[OpenLayers-Users] Markers on Google move around N/S

Christopher Schmidt crschmidt at metacarta.com
Tue Sep 2 11:45:43 EDT 2008


On Tue, Sep 02, 2008 at 09:32:43AM -0600, Matt Williamson wrote:
> Hello List,
> 
> Having a strange behavior with the following page:
> 
> http://s89238293.onlinehome.us/w/index.php?title=Special:EditData/BirdCountGoogle/Google_form_test
> 
> ... click on the "Show map" link, and you'll get an OpenLayers map  
> with a Google base layer. What's happening is, whenever the map is  
> panned or zoomed, the marker icon moves around North or South from  
> where it's supposed to be. Stranger, the pop-up remains in the correct  
> place!! I'm not using "sphericalMercator" on purpose, because it made  
> a mess of setting extents, etc. 

> It seems this should work, especially  
> since the pop-up knows how to stay put...and markers loaded with the  
> older Layer.Text mechanism (e.g. here: http://s89238293.onlinehome.us/ 
> w/ , bottom of the page) don't have this issue. 

> What gives?? Please  tell me there's something simple I can do to fix
> this.

You're not using Spherical Mercator. That's the way the cookie crumbles.

Specifically, the reason for this difference in behavior is becasue
markers and popups are single entities: having them place themselves by
doing a request to the base layer is not too expensive. 

However, vectors can be thousands of points: and when rendering many
points, this additional work (which, with Google, actually equates to an
additional *15 level deep* call stack, due to the way the GMaps API
works) slows down drawing of vectors by as much as 50%. 

Rather than maintaining two sets of code -- one that does ask the Base 
Layer, one that doesn't -- we went with the path of providing a way to
make a GMaps layer behave the way every other base layer in OpenLayers
works, where you actually know where a given pixel is. 

OpenLayers offers the ability to reproject extents from Spherical
Mercator to LonLat and reverse:

  var bounds = new OpenLayers.Bounds(-180,-90,180,90).transform(
    new OpenLayers.Projection("EPSG:4326"), 
    new OpenLayers.Projection("EPSG:900913")
  );  

This is also true of LonLat objects and geometries.

I would highly recommend going this route; my expectation is that in 3.0
(~6-12 months from now is my personal guess on the first release of 3.0,
though I don't really decide, just a guess at this point) that we will
remove 'markers' as they currently exist and replace them entirely with
vectors. (Some of the spherical mercator things will probably get easier
at the same time -- but not all.)

If you're using projected data, treat it as if it's projected. Google's
LonLat view of the world doesn't represent the data you're interacting
with. Get to the roots! 

(This is an expansion of
http://faq.openlayers.org/vector-related-questions/why-dont-my-vector-features-work-over-google-yahoo-virtual-earth-etc/
)

Regards,
-- 
Christopher Schmidt
MetaCarta



More information about the Users mailing list