【发布时间】:2021-03-31 16:31:51
【问题描述】:
如果我在图层上有多边形、线、文本和点,我希望能够选择 1 个要素,右键单击选择“移动”,然后能够将该要素拖动到地图上的另一个位置,然后当我释放 鼠标按钮将新位置保存到我的数据库中。
我在哪里,我可以...
选择要移动的特征
右键单击并选择用于调用代码的“移动”操作 添加 Translate 和 Select ol 对象。这不会选择我传递给的功能 翻译虽然...我仍然需要单击该功能,然后我才能拖动它。即使我 仅向翻译添加了 1 个功能我可以单击并拖动任何功能(我没想到 这样做可以。
一旦在选择要拖动的要素模式下,除了重新加载地图之外别无他法...I 不知道如何,也没有在文档中看到如何捕捉“拖动完成”
我的代码
moveObject(){
//first get the selected object
const selectedObject = new Array<number>();
const selectedFeatures: Array<olFeature> = myFeatureLayer.getSource().getFeatures();
selectedFeatures.forEach((feature: olFeature) => {
selectedObject.push(feature.getId());
});
//get the feature
let selectedFeatures = this.myFeatureService.getFeature(selectedObject);
let select = new Select();
let translate = new Translate({
features: selectedFeatures, (this should restrict the move to just the feature passed in,but it
doesn't)
});
MapValues.map.addInteraction(translate);
MapValues.map.addInteraction(select);
//Here I want to automatically select the feature given and put it into "Move" mode.
// Here once move is done I want to catch "Dropping" the feature and add to the data base and
remove the Interactions.
}
更新: 我找到了“翻译结束”
translate.on('translateend', evt => {
evt.features.forEach(feat => {
// process every feature
})
})
...但这不只是在最后触发,它会随着 clickdown 和 upclick 触发?我很困惑为什么要这样做,以及这个功能看起来像是一个脊梁框架?...我可能是错的,但有限的文档和示例使我们很难理解翻译的功能。
非常感谢任何帮助
【问题讨论】:
标签: openlayers openlayers-3 openlayers-5