[OpenLayers-Users] Google map, antimeridian and bounding box
Eric Lemoine
eric.c2c at gmail.com
Fri Jan 25 17:58:12 EST 2008
On Jan 23, 2008 1:23 PM, Guillaume Lom <progmls at googlemail.com> wrote:
> Hello,
>
> I am trying to display some markers on a Google map layers, along with
> bounding boxes.
>
> All is well except in on particular case:
>
> If I want to display a bounding box around Antartica, for instance, it
> does not expand around all longitudes, but only around the
> antimeridian, which means that I have a litte rectangle in the middle
> of the sea instead of having a big one covering the whole antartica.
>
> Is there a way to go around this while using google map? I could not find any...
>
> Here are the relevant javascript bits:
>
> var glayer = new OpenLayers.Layer.Google("Google Normal", { 'type':
> G_NORMAL_MAP});
> var params;
> params.maxExtent=new OpenLayers.Bounds(-180,-90,180,90);
> var _map = new OpenLayers.Map('map', params)
> _map.addLayers([glayer]);
> var boxes = new OpenLayers.Layer.Boxes("portalsBoxes");
> _map.addLayer(boxes);
> var bbounds = new OpenLayers.Bounds(-180, -90, 180, -61.4);
> boxes.addMarker(new OpenLayers.Marker.Box(bbounds), 'red', 1);
You can try the following (absolutely untested!!) :
var _map = new OpenLayers.Map('map');
var glayer = new OpenLayers.Layer.Google("Google Normal", {
'type':G_NORMAL_MAP
'sphericalMercator': true
});
var boxes = new OpenLayers.Layer.Boxes("portalsBoxes");
_map.addLayers([glayer, boxes]);
var bbounds = new OpenLayers.Bounds(-180, -90, 180, -61.4);
bbounds.transform(new OpenLayers.Projection("EPSG:4326),
new OpenLayers.Projection("EPSG:900913"));
boxes.addMarker(new OpenLayers.Marker.Box(bbounds), 'red', 1);
Explanation: google doesn't use the EPSG:4326 projection, it uses
EPSG:900913. So you need to reproject your EPSG:4326 data to be able
to display it on top of the google layer.
Hope this helps,
--
Eric
More information about the Users
mailing list