Openlayers 通过拖动移动矢量要素
如果我在一个图层上有一个多边形、直线、文本和点,我希望能够选择一个特征,右键单击选择“移动”,然后能够将该特征拖动到地图上的另一个位置,并在我释放该特征时进行 用鼠标键将新位置保存到我的数据库中 在我所在的地方,我可以 选择要移动的特征 右键单击并选择用于调用代码的“移动”操作 这将添加“平移”和“选择ol对象”。这不会选择我传递给的功能 翻译虽然…我仍然需要点击功能,然后我可以拖动它。即使我 只添加了一个翻译功能,我可以点击并拖动其中的任何功能(这是我没有想到的) 这样做将允许 一旦进入选择要拖动的要素的模式,除了重新加载地图之外,没有其他出路了…I 不知道如何,也没有在文档中看到如何捕获“拖动完成” 我的代码Openlayers 通过拖动移动矢量要素,openlayers,openlayers-3,openlayers-5,Openlayers,Openlayers 3,Openlayers 5,如果我在一个图层上有一个多边形、直线、文本和点,我希望能够选择一个特征,右键单击选择“移动”,然后能够将该特征拖动到地图上的另一个位置,并在我释放该特征时进行 用鼠标键将新位置保存到我的数据库中 在我所在的地方,我可以 选择要移动的特征 右键单击并选择用于调用代码的“移动”操作 这将添加“平移”和“选择ol对象”。这不会选择我传递给的功能 翻译虽然…我仍然需要点击功能,然后我可以拖动它。即使我 只添加了一个翻译功能,我可以点击并拖动其中的任何功能(这是我没有想到的) 这样做将允许 一旦进入选择要
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
})
})