openlayers 5.3 + Vue 2.5
效果:
持续按下鼠标右键再拖动鼠标可以实现变换视图的角度
(openlayers的样式被我改了一下,看上去有点像ArcGIS API for JS 4.x的样式)
关键点
- Vue里面如何阻止浏览器的默认右键事件
- 如何阻止openlayers自带的鼠标点击拖动地图事件
1.Vue里面如何阻止浏览器的默认右键事件
这里有一个坑,下面的代码是无效的,不能阻止浏览器的默认右键事件
html:
<div id="map"
class="w-100"
@mousedown.prevent.right.prevent="changeRotation('down',$event)"
@mousemove="changeRotation('move',$event)"
@mouseup.prevent.right.prevent="changeRotation('up',$event)"></div>
JavaScript: