[OpenLayers-Users] Overlays with google maps

Christopher Schmidt crschmidt at metacarta.com
Mon Feb 19 13:39:06 EST 2007


Forwarding message from off-list discussion.

This is important for anyone who treats the map ratio as being the same
vertically and horizontally, and is trying to do the same thing with
Google.

----- Forwarded message from Les Szklanny <lszklanny at where2getit.com> -----

Date: Mon, 19 Feb 2007 11:07:22 -0600
Subject: Re: [Fwd: Re: [OpenLayers-Users] Overlays with google maps]

Christopher Schmidt wrote:
>On Mon, Feb 19, 2007 at 07:56:22AM -0600, Les Szklanny wrote:
>  
>>Christopher, hi!
>>
>>I'm responding to your question:
>>
>>"Can you give an example chunk of code for how you're currently determining
>>the bounds for the image that you request from your route generation
>>tool? are you using map.getExtent()?"
>>
>>Here's the function that generates a query string for the GET route image 
>>request:
>>
>>	/**
>>	 * @method
>>	 * @return String
>>	 */
>>	_getImageQS: function() {
>>		var bounds = this.map.getExtent();
>>		var res = this.map.getResolution();
>>		var qs =	'top=' 		+ (-bounds.top/res) +
>>					'&left=' 	+ bounds.left/res +
>>					'&right=' 	+ bounds.right/res +
>>					'&bottom=' 	+ 
>>					(-bounds.bottom/res) +
>>					'&ratio=' 	+ res;	
>>		return qs;		
>>	}
>>    

That won't work with Google. The horizontal resolution is not the same
as the vertical resolution: because the units are in decimal degrees,
but the projection is in meters, there is a non-linear change in
geographic distance for every vertical pixel.

I can't tell you what your application server-side needs to do, but
somewhere along the line you need to support a different ratio for width
and height. You can then divide 
  
  (bounds.top - bounds.bottom) / map.getSize()[1]

to get that vertical ratio. (I'd suggest doing something simiar for the
horizontal direction: getResolution picks one of those two values, but
I'm not sure which.) 

Alternatively, simply change your code to accept a geographic bounds,
plus a width and height, and render that way. However, I'm assuming
that you're not using the tried-and-true method that WMS uses for a
reason, so that probably won't work for you for some reason I don't
understand.

Regards,
-- 
Christopher Schmidt
MetaCarta



More information about the Users mailing list