[OpenLayers-Dev] 'changelayer' event + map zoom

Andreas Hocevar ahocevar at opengeo.org
Thu Jan 12 11:27:30 EST 2012


How would your map know which extent you want to zoom to? Your code
would only work if your base layer changes, and the base layer was
configured with a different maxExtent than the previous one.

To do what you want, you need to do something like

map.zoomToExtent(evt.layer.maxExtent);

which only works if you have configured your layers with a maxExtent.

On Thu, Jan 12, 2012 at 4:10 PM, Grzegorz Kurzejamski
<grzegorz.kurzejamski at lingaro.com> wrote:
> Hi,
>
> I've been wondering, how is that, that after firing that piece of code:
>
> map.events.register('changelayer', null, function(evt)
> {
>  if(evt.layer.visibility==true)
>  {
>   map.zoomToMaxExtent()
>  }
> }
> );
>
> ...zoom doesn't affect the view.
> I've got few layers in my map, with standard layer switcher. Those are
> completely different graphs, so when I change layer, I want to zoom it to
> maximum extent. When I put some alert(); just after zoom function i can see,
> that when the alert is fired - layer is already changed and certainly zoomed
> to "MaxExtent" . After alert closure, layer pans to bounding box before
> layer switching.
>
> After few hours of net digging, I decided to post here.
> Hope someone can help :).
>
> --
> View this message in context: http://osgeo-org.1803224.n2.nabble.com/changelayer-event-map-zoom-tp7180553p7180553.html
> Sent from the OpenLayers Dev mailing list archive at Nabble.com.
> _______________________________________________
> Dev mailing list
> Dev at lists.osgeo.org
> http://lists.osgeo.org/mailman/listinfo/openlayers-dev



-- 
Andreas Hocevar
OpenGeo - http://opengeo.org/
Expert service straight from the developers.


More information about the Dev mailing list