[OpenLayers-Users] Vector layer on top of SphericalMercator layer

Christopher Schmidt crschmidt at metacarta.com
Wed May 7 10:12:21 EDT 2008


On Wed, May 07, 2008 at 04:08:40PM +0200, jrom wrote:
> Hi,
> 
> I am trying to reproject lat/lon vector ontop of commercial api using
> OpenLayers.
> I've spent quite a lot of time on a strange behaviour. My vector does
> not appear on the map when i switch on sphericalMercator to true...
> 
> The problem is that the point does not appear at all on the map.
> However, when i switch sphericalMercator to false, it appears (but not
> on the right place at large scale due to projection difference)
> 
> I really don't understand what i am doing wrong. I've check the
> projected coordinates and they are correct...
> 
> Did someone experience such an issue ?

The layer is being turned off because it is 'out of range'. The reason
for this is that you have not defined the spherical mercator projection
propertpies on the map: this means that the overlay is pulling the
defaults from the map (which are in lon/lat) and therefore has a
resolutions range of 1.40625 -> some very small number, while your
spherical mercator layer has a range of 150000ish -> 100ish, and the end
result is that your layer is never on.

Copy the options from the map creation in the spherical-mercator.html
example, and add them to your map constructor, and your layer should
appear. 

-- Chris

> Regards
> 
> ps: Here is the code
> 
>  <html>
>  <head>
>   <title>OpenLayers Example</title>
>     <script src='http://dev.virtualearth.net/mapcontrol/v3/mapcontrol.js'></script>
>     <script src="http://openlayers.org/api/OpenLayers.js"></script>
>     </head>
>     <body>
>       <div style="width:100%; height:100%" id="map"></div>
>       <script defer='defer' type='text/javascript'>
>            var map = new OpenLayers.Map("map", {
>                    projection: new OpenLayers.Projection("EPSG:900913"),
>                    displayProjection: new OpenLayers.Projection("EPSG:4326")
>             });
>             map.addControl(new OpenLayers.Control.Permalink());
>             map.addControl(new OpenLayers.Control.MousePosition());
>             var layer = new OpenLayers.Layer.Google("Google",
>                 { sphericalMercator: true });
>             map.addLayer(layer);
>             map.zoomToMaxExtent();
> 
>             var wkt = new OpenLayers.Format.WKT();
>             var features = wkt.read("POINT(-71, 42)");
>             var myVector = new OpenLayers.Layer.Vector("GML",
>  {projection: new OpenLayers.Projection("EPSG:900913")});
>             myVector.addFeatures(features);
>             map.addLayer(myVector);
>             map.zoomToExtent(myVector.getExtent());
>       </script>
>     </body>
>  </html>
> 
>  For your information i'm using firefox 2.0.0.14 (inux and windows) and
>  Safari (Leopard). Same problems on each platforms
> 
>  --
>  jrom.
>  http://www.ombresetlumieres.com
> 
> 
> 
> -- 
> jrom.
> http://www.ombresetlumieres.com
> _______________________________________________
> Users mailing list
> Users at openlayers.org
> http://openlayers.org/mailman/listinfo/users

-- 
Christopher Schmidt
MetaCarta



More information about the Users mailing list