Javascript OpenLayers before zoom event listener

前端 未结 5 1941
醉酒成梦
醉酒成梦 2021-02-09 03:46

I am trying to set up OpenLayers to not display the vector layer just before a zoom starts and make it reappear after a zoom ends. I have the zoom ends part already established

5条回答
  •  遇见更好的自我
    2021-02-09 03:48

    Here is a easy to add the 'BeforeZoom' event to the OpenLayers . Just add the code below to where you created your map object.

    map.zoomToProxy = map.zoomTo;
    map.zoomTo =  function (zoom,xy){
        //Your Before Zoom Actions
    
        //If you want zoom to go through call
        map.zoomToProxy(zoom,xy); 
        //else do nothing and map wont zoom
    };
    

    How this works:

    For any kind of zooming activity, OpenLayers API ultimately calls the function called zoomTo. So before overriding it, we copy that function to a new function called 'zoomToProxy'. The we override it and add our conditional zoom logic. If we want the zoom to happen we just call new proxy function :)

提交回复
热议问题