我正在构建允许在CMS中编辑 Map 框标记的功能 . 单击 Map 标记时,该功能应打开并填充表单,然后允许拖动 Map 标记 . 保存表单后,将通过ajax提交内容,然后使用featureLayer.loadURL(“my_geojson_endpoint”)重新加载 Map .
我在下面的代码中添加了注释,以概述我是如何得到错误的 .
N.B. 我在geojson中定义了一个属性db_id来标识每个点,因为在应用过滤器时,_leaflet_id会发生变化 . 我也在代码中包含了jquery .
码:
// loop through each marker, adding a click handler
$.each(points._layers, function (item) {
var point = points._layers[item];
attachClickHandler(point);
});
function attachClickHandler(point) {
// open the edit state for the marker on click
$(point._icon).on("click", function () {
openEditState(point);
})
}
function openEditState (point) {
disableEditOthers(point);
displayContent(point);
point.dragging.enable(); // this line causes the error
$(point._icon).off("click");
}
function disableEditOthers (point) {
// hide the other markers from the map (using db_id as mentioned above)
points.setFilter(function (f) {
return f.db_id === point.feature.db_id;
})
// this functions as a callback to display the popup
// since applying the filter on click, does not show the popup
setTimeout(function () {
for (key in points._layers) {
points._layers[key].openPopup();
}
}, 0)
}
在 Map 创建步骤中,我已经能够在每个标记上调用这个dragging.enable()方法,并为所有标记提供“可拖动性”,但从可用性的角度来看,这是不可取的 . 我希望用户清除交换进出编辑状态 .
我在github上发现了this问题,通过this的解决方案解决了 . 然而,在将我的mapbox.js版本交换到独立版并包含最新版本的传单(0.7.3)之后,仍然出现了相同的错误 .
我在对象的错误属性上调用函数吗?在错误未显示draggable属性定义了enable()函数的行之前转出“point”变量 .
任何帮助深表感谢 .
1 回答
好的,作为一个小的解决方法,但仍然没有解决原始错误 .
因为我已经过滤掉了其他点,所以在所有点上拖动都会解决这个问题 .
如果你能修复我的原始修复(避免循环),我很乐意接受它 .