Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

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
share|improve this question
add comment

2 Answers 2

up vote 5 down vote accepted

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...

share|improve this answer
add comment

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

You want moveend and zoomend.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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