OpenLayers要素拖拽

    //拖拽要素
    function  dragFeature  (_map,_dragEndCallback) {
        let selFeature = null;
        _map.on("pointerdrag", function (evt) {
            selFeature = _map.getFeaturesAtPixel(evt.pixel, function (feature) {
                return feature;
            });
        });
        let translate = new ol.interaction.Translate({//拖拽移动interaction
            features: selFeature//拖拽的为选择的要素
        });
        _map.encmap.addInteraction(translate);
        translate.on('translateend', function (f) {
            if(_dragEndCallback){
                let obj = {};
                obj.features=f.features;
                obj.coordinate=f.coordinate;
                _dragEndCallback(obj);//拖拽完成事件,可以获取拖拽后的要素
            }
            _map.removeInteraction(translate);
        });
    };
posted @ 2020-01-15 10:12  昜木辰deブログ  阅读(1959)  评论(0编辑  收藏  举报