gpt4 book ai didi

geometry - 拖动/移动多个选定功能-OpenLayers

转载 作者:行者123 更新时间:2023-12-04 13:44:18 28 4
gpt4 key购买 nike

我知道我可以轻松地允许用户在OpenLayers中选择多个功能/几何图形,但是随后我希望使用户能够轻松地同时拖动/移动所有选定的功能。

使用ModifyFeature控件一次只能移动一个要素...是否可以轻松扩展此控件(或其他可行方法)以在该层上移动所有选定要素?

最佳答案

好的,跳过ModifyFeature控件,仅挂接到SelectFeature控件即可跟踪所选要素,然后使用DragControl同时操作所选点。

控件实例化的示例:

var drag = new OpenLayers.Control.DragFeature(vectors, {
onStart: startDrag,
onDrag: doDrag,
onComplete: endDrag
});
var select = new OpenLayers.Control.SelectFeature(vectors, {
box: true,
multiple: true,
onSelect: addSelected,
onUnselect: clearSelected
});

事件处理功能的示例:
/* Keep track of the selected features */
function addSelected(feature) {
selectedFeatures.push(feature);
}

/* Clear the list of selected features */
function clearSelected(feature) {
selectedFeatures = [];
}

/* Feature starting to move */
function startDrag(feature, pixel) {
lastPixel = pixel;
}

/* Feature moving */
function doDrag(feature, pixel) {
for (f in selectedFeatures) {
if (feature != selectedFeatures[f]) {
var res = map.getResolution();
selectedFeatures[f].geometry.move(res * (pixel.x - lastPixel.x), res * (lastPixel.y - pixel.y));
vectors.drawFeature(selectedFeatures[f]);
}
}
lastPixel = pixel;
}

/* Featrue stopped moving */
function endDrag(feature, pixel) {
for (f in selectedFeatures) {
f.state = OpenLayers.State.UPDATE;
}
}

关于geometry - 拖动/移动多个选定功能-OpenLayers,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4389221/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com