openLayer设置禁止拖拽地图

import DragPan from 'ol/interaction/DragPan'//先在项目中引用此包

getPan() {
    let pan = null
    this.map.getInteractions().forEach(element => {
        if (element instanceof DragPan) {
            pan = element
        }
    })
    return pan
},

let pan = this.getPan()
pan.setActive(false)//false禁止拖拽,true允许拖拽

 

你可能感兴趣的:(web前端)