Changing cursor on drag in openlayers 3

烈酒焚心 提交于 2019-12-11 05:03:58

问题


What are the proper way of changing the cursor when user is dragging the map. Below example is not that good as it only triggers when pointerdrag starts the drag and then change it back after no events for 125ms. Is there any other way?

    var timer = null;
    this.map().on("pointerdrag",() => {
        this.map().getViewport().style.cursor = "-webkit-grabbing";
        clearTimeout(timer);
        timer = setTimeout(() => this.map().getViewport().style.cursor = "-webkit-grab", 125); 
    });

回答1:


What about listening to pointerup to reset the cursor?

map.getViewport().style.cursor = "-webkit-grab";
map.on('pointerdrag', function(evt) {
    map.getViewport().style.cursor = "-webkit-grabbing";
});

map.on('pointerup', function(evt) {
    map.getViewport().style.cursor = "-webkit-grab";
});

http://jsfiddle.net/9vwgdcyr/



来源:https://stackoverflow.com/questions/30020424/changing-cursor-on-drag-in-openlayers-3

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!