Openlayers 4.0中如何实现平移、缩放事件回调
在Openlyaers 4.0中,可以通过以下方式对地图map对象的几个特定事件绑定自定义函数。 来自官网的例子:http://openlayers.org/en/latest/examples/moveend.html
function onMoveEnd(evt) {
const map = evt.map;
const extent = map.getView().calculateExtent(map.getSize());
const bottomLeft = toLonLat(getBottomLeft(extent));
const topRight = toLonLat(getTopRight(extent));
display('left', wrapLon(bottomLeft[0]));
display('bottom', bottomLeft[1]);
display('right', wrapLon(topRight[0]));
display('top', topRight[1]);
// TODO: your code...
}
map.on('moveend', onMoveEnd);
支持的事件是:
click (module:ol/MapBrowserEvent~MapBrowserEvent) - A click with no dragging. A double click will fire two of this.
dblclick (module:ol/MapBrowserEvent~MapBrowserEvent) - A true double click, with no dragging.
moveend (module:ol/MapEvent~MapEvent) - Triggered after the map is moved.
movestart (module:ol/MapEvent~MapEvent) - Triggered when the map starts moving.
pointerdrag (module:ol/MapBrowserEvent~MapBrowserEvent) - Triggered when a pointer is dragged.
pointermove (module:ol/MapBrowserEvent~MapBrowserEvent) - Triggered when a pointer is moved. Note that on touch devices this is triggered when the map is panned, so is not the same as mousemove.
postcompose (module:ol/render/Event~RenderEvent)
postrender (module:ol/MapEvent~MapEvent) - Triggered after a map frame is rendered.
precompose (module:ol/render/Event~RenderEvent)
propertychange (module:ol/Object~ObjectEvent) - Triggered when a property is changed.
singleclick (module:ol/MapBrowserEvent~MapBrowserEvent) - A true single click with no dragging and no double click. Note that this event is delayed by 250 ms to ensure that it is not a double click.