Hi.

I have a map with two layers in different projections (OSM & EPSG:4236)

When I change the layer through the layer switcher control, the map changes
but it doesn't stay centered in the same point and zoom level.

This is the function I wrote to reset the center of the map.


function onchangelayer(e) {
    if (e.layer.name != previousLayer.name && e.layer.projection.getCode()
!= previousLayer.projection.getCode()) {
        var newCenter = map.getCenter().transform(previousLayer.projection,
e.layer.projection);                                            
        map.setCenter(newCenter);
    }
    previousLayer= map.baseLayer;
}

Sometimes, after the layer change, the new layer is not shown or can't be
panned.

I have two questions:
 - Which is the correct way to preserve the map center after a layer change?
 - How to keep the zoom level as close as possible to the previous zoom
level?

Regards,
Rodrigo.
-- 
View this message in context: 
http://osgeo-org.1803224.n2.nabble.com/Keep-zoom-location-between-layer-changes-tp5696461p5696461.html
Sent from the OpenLayers Users mailing list archive at Nabble.com.
_______________________________________________
Users mailing list
[email protected]
http://lists.osgeo.org/mailman/listinfo/openlayers-users

Reply via email to