Translate移动要素
Interaction for translating (moving) features.
用于移动要素的交互;用于移动要素的交互;
官方示例:https://openlayers.org/en/latest/examples/translate-features.html
移动对象可以是要素features也可以是图层layers,但两者不能同时存在;
hitTolerance属性是用于设置触发范围
主要代码:
// 创建移动交互对象
var translate = new ol.interaction.Translate({
features: new ol.Collection([featureIcon1]),
//layers: [layerChinaSimple],
//hitTolerance: 100 // 触发范围:在要素100像素的半径圆内都可以触发
})
// 地图添加交互行为
map.addInteraction(translate);
// 交互对象的触发事件
translate.on('translatestart',function(e){
$("#message1").text("开始移动!");
});
translate.on('translating',function(e){
$("#message1").text("正在移动!");
});
translate.on('translateend',function(e){
$("#message1").text("结束移动!");
});