3

Is it possible to delete a vector layer when a user pans or zooms a map? I saw in the documentation that there is a function called onMapResize. Can this also be used to detect a pan change?

I want to delete a point if the map is panned or zoomed and tried using it in the following way (which does not work):

map.OpenLayers.vectorLayer.onMapResize(console.log('map was moved'))
//use removeAllFeatures() to remove vector points
7

Vadim is right. you can do it with registering map moveend and zoomend events.

map.events.register("moveend", map, function(){
     var lyr = map.getLayersByName('vectorLayer')[0];
     map.removeLayer(lyr);
});

map.events.register("zoomend", map, function(){
     var lyr = map.getLayersByName('vectorLayer')[0];
     map.removeLayer(lyr);
});

i hope it helps you...

5

See the map events. http://dev.openlayers.org/docs/files/OpenLayers/Map-js.html#OpenLayers.Map.events

You want moveend and zoomend.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.