Javascript OpenLayers before zoom event listener

前端 未结 5 2055
醉酒成梦
醉酒成梦 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:49

    I had the same problem that OP had, and I tried to solve it with drnextgis's solution. But unfortunately it didn't completely work:: the zoomChanged property in OpenLayers.Map.moveTo evaluates to true not only when the zoom level has changed, but also when the map has been resized.

    My map was 100% of the user's browser window, so if they resized the window, the event would be triggered. This was undesirable for me, as I only wanted to trigger the event if the zoom level had actually changed. My solution was to create an new event, called "zoomstart", which I inserted at the top of OpenLayers.Map.moveTo. Here's the code:

    var getZoom = this.getZoom();
    if ( !!getZoom && !!zoom && this.isValidZoomLevel(zoom) && getZoom != zoom )
        this.events.triggerEvent("zoomstart", zoom);
    

    This code will pass the new zoom level to an event listener that is registered to zoomstart, and in my case I determine the map's restrictedExtent and do other stuff based upon the new zoom level.

    Peace be with ye.

提交回复
热议问题