[OpenLayers-Users] zoomToScale

Christopher Schmidt crschmidt at metacarta.com
Wed Feb 7 11:02:52 EST 2007


On Wed, Feb 07, 2007 at 04:51:35PM +0100, olivier.terral wrote:
> Hi everybody,
> 
>    I try to integrate OL in Mapbuilder but I've a problem with the 
> ZoomToScale(scale) method.
> when I specify a scale , OL recompute this scale.
> 
>    Is it possible to zoom  at a specified scale with openlayers?


Currently, when you define your map, you make a fixed list of scales.

However, you can change this list on the layer. It's possibly not the
most sane solution, but what you can do is this:

m = new OpenLayers.Map("map");
l = new OpenLayers.Layer.WMS(etc.)
m.addLayer(l);

then to pick a scale:

l.resolutions = [OpenLayers.Util.getResolutionFromScale(20000)];
m.zoomTo(1);
m.zoomTo(0);

The m.zoomTo(1); will not do anything visually, but it will change the
internal zoom level the map is using. The m.zoomTo(0); will then redraw
the map with the correct resolution.

This behavior is possibly something that would change in the future, but
hopefully it will only change if there is a more well supported way of
zooming to a particular scale/resolution.

If you wish to add support for simplifying this mechanism, I'd love a
patch.

Regards,
-- 
Christopher Schmidt
MetaCarta



More information about the Users mailing list