[OpenLayers-Users] Google layer,vector graphic, and the dateline

Heidt, Christopher M. CHRISTOPHER.M.HEIDT at saic.com
Wed Jan 7 15:49:48 EST 2009


I use the control below to allow my users to draw a "bounding box" on a
map that uses the Google layers.
The problem arises when they draw a shape that crosses the dateline, as
it creates a shape longitudly inverse to what they wanted.
Any suggestions as to the best way to handle this?


[javascript]

//bbox
_bboxDrawControl = new OpenLayers.Control({
    draw: function () {
        this.box = new OpenLayers.Handler.Box( _bboxDrawControl,{
			done: this.notice
		},{});
		this.box.boxDivClassName = 'Control_DrawBox';
    },
    notice: function (bounds){
		this.box.deactivate();
		var newbounds = new OpenLayers.Bounds();
		newbounds.extend(_map.getLonLatFromPixel(new
OpenLayers.Pixel(bounds.left, bounds.bottom)));
		newbounds.extend(_map.getLonLatFromPixel(new
OpenLayers.Pixel(bounds.right, bounds.top)));
		
		var bbox = new
OpenLayers.Feature.Vector(newbounds.toGeometry());
		bbox.id = 'SW_customBoundingBox';
		_bboxLayer.addFeatures(bbox);
		_map.zoomToExtent(newbounds);
    }
});
_map.addControl(_bboxDrawControl);

[end javascript]


I could snip the shape off entirely at the dateline, but id like to
avoid that.

I could cut it in half and create two shapes, but while producing a more
accurate result it would render on different sides of the map,
and if its not coherent its not very user friendly.

A third option would be to force the draw control to be unable to cross
the date line,
but I don't have any idea how to accomplish that.

Ultimately id like one shape(or look like one) that truly represents the
shape drawn.



More information about the Users mailing list