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

Matt Williamson MatthewDW at gmail.com
Tue Sep 2 12:46:57 EDT 2008


Thanks Chris.

*Sigh*

That's what I was afraid of. The problem is, that this is part of a  
system that lets users define their own maps and what layers go in  
them...so to do what you're suggesting, I think I have to build an  
infrastructure into the whole system for the users to define  
projections on layers...which I figured I'd have to do at some point,  
but wanted to skip for this release. Plus that means that my users  
have to concern themselves with what projection their base map  
is...and probably I must prevent them from mixing base layers of  
different projections in the same map....until now, the users haven't  
had to worry about this, for the most part.

Hmm...I guess I could use OpenLayers.Map.getProjectionObject to do  
some of this automatically? E.g. I'm thinking perhaps I could do  
something like the following:

OpenLayers.Map.prototype.zoomToGeographicExtent = function(geobounds){
     bounds = geobounds.transform(
         new OpenLayers.Projection("EPSG:4326"),
         this.getProjectionObject()
     );
     this.zoomToExtent(geobounds);
}

...or something like this? Is there a problem with an approach like  
this?

Thanks,

-Matt



On Sep 2, 2008, at 9:45 AM, Christopher Schmidt wrote:

> 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