I have an OpenLayers map.

On to this I have loaded a GeoJSON file.

When I pan the map the GeoJSON data moves relative to the basemap.

Surely this isn't right! Can anyone shed some light no why this is happening?

  • 4
    please add a link to your code, it's very hard to debug from just a description of the problem – Ian Turton Mar 22 '11 at 16:12
  • to add to what @iant said - you can use jsfiddle.net or jsbin.com to post some bare bones code to test. – Vadim Mar 22 '11 at 16:43
  • Surley you want your georeferenced data to move relative to the other spatial data? – geographika Mar 22 '11 at 17:06
  • We are waiting for the code, but it appears normal to me that the geojson data move when panning the basemap ... – simo Mar 22 '11 at 17:08
  • 1
    questioner is complaining the data moves relative to the base map - it's probably a projection issue – Ian Turton Mar 23 '11 at 15:31

This happened to me once and the layer was not on the same projection as the basemap.

But without example code, this is like a stab in the dark.

| improve this answer | |
  • I'm having trouble reproducing the problem now - which is good - but I am having a slightly different problem. Now the overlays are aligned correctly (over Britain) when using osgeo.org basemap but are off the coast of Africa (0,0 in EPSG:4326 projection) when using Google or Microsoft. I'm almost certain it is a projection issue. I'll mark this as the correct answer - I can't reproduce the original problem so I can't test any other answers. Thanks all the same! – Mr_Chimp Mar 31 '11 at 12:01

The most likely cause of this is not setting a baselayer's sphericalMercator property to true - by default this is false, so it needs to be set explicitly.

var myBaseLayer = new OpenLayers.Layer.Google("Google",
              {'sphericalMercator': true

APIProperty: sphericalMecator Whether the tile extents should be set to the defaults for spherical mercator. Useful for things like OpenStreetMap. Default is false, except for the OSM subclass.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.