问题描述
如果图层上有多边形、线、文本和点,我希望能够选择 1 个要素,请右键单击以选择“移动”,然后能够将该要素拖动到地图上的另一个位置,然后当我释放 鼠标按钮将新位置保存到我的数据库中。
我在哪里,我可以...
选择要移动的要素
右键单击并选择用于调用代码的“移动”操作 添加 Translate 和 Select ol 对象。这不会选择我传递给的功能 翻译虽然...我仍然需要单击该功能,然后我可以拖动它。即使我 仅向 Translate 添加了 1 个功能,我可以单击并拖动任何功能(这是我没想到的) 这样做将允许。
一旦进入选择要拖动的要素模式,除了重新加载地图之外别无他法...我 不知道如何也没有在文档中看到如何捕捉“拖动完成”
我的代码
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.
}
更新: 我找到了 'translateend'
translate.on('translateend',evt => {
evt.features.forEach(feat => {
// process every feature
})
})
...但这不仅仅是在最后触发,它在点击和向上点击时触发?我很困惑为什么要这样做,以及这个功能的脊状框架是什么?...我可能是错的,但有限的文档和示例让我很难理解翻译的功能。
非常感谢任何帮助
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)