尝试在地图框/传单中启用标记拖动时,无法读取 null 的属性“_leaflet_mousedown5”
Cannot read property '_leaflet_mousedown5' of null when attempting to enable marker dragging in Mapbox/Leaflet
我正在构建允许从CMS中编辑地图框标记的功能。单击地图标记时,该功能应打开并填充表单,然后允许拖动地图标记。保存表单后,将通过 ajax 提交内容,然后使用 featureLayer.loadURL("my_geojson_endpoint") 重新加载地图。
我在下面的代码中添加了注释,以概述我是如何到达错误的。
注:注:我在 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)
}
在地图创建步骤中,我已经能够在每个标记上调用这个 dragging.enable() 方法,并为所有这些标记提供"可拖动性",但从可用性的角度来看,这是不可取的。我希望用户清除交换进入和退出编辑状态。
我在 github 上发现了这个问题,通过解决方案解决了这个问题。但是,将我的mapbox.js版本换成独立版本并包括最新版本的传单(0.7.3)后,仍然发生了相同的错误。
我是否在对象的错误属性上调用该函数? 在错误的行之前转储"point"变量并不表明可拖动属性定义了enable()函数。
任何帮助都非常感谢。
好的,作为一个轻微的解决方法,但仍然没有解决原始错误。
$.each(points._layers, function (item) {
points._layers[item].dragging.enable()
})
因为我已经过滤掉了其他点,所以启用所有点的拖动可以解决这个问题。
如果您可以提供对我原始修复程序的修复程序(避免循环),我很乐意接受它。
相关文章:
- 字符串在将其传递给另一个活动Android JavaScript时读取Null
- 未捕获的类型错误:无法读取属性'addEventListener'的null chrome扩展名
- 未捕获的类型错误:无法读取属性'状态'在react中为null
- Javascript Float32数组抛出无法读取属性'0'即使数组定义良好,也为null
- 我该如何解决这个问题?“未捕获的类型错误:无法读取 null 的属性'appendChild'”
- VM5111:1249未捕获类型错误:无法读取属性'x'为null
- 无法读取属性'addEventListener'菜单上为null的
- Catch无法读取null的属性
- select2:无法读取null的属性查询
- 获得'无法读取null的属性样式'
- TinyMCE->无法读取属性'setAttribute'为null
- 未捕获的类型错误:无法读取 null 的属性“removeChild”(使用 Instagram 的 JSONP 响应)
- 未捕获的类型错误:无法读取 null 的属性“toLowerCase”
- JAVASCRIPT - 未捕获的类型错误:无法读取 null 的属性“值”
- Google Map API BackBoneJS 无法读取 null 的属性 'offsetWidth'
- 未捕获的类型错误:无法读取 null 的属性“选项” - 某些代码有效
- javascript无法读取属性'style'为null
- 无法读取属性''为null
- Vaadin组合框无法读取属性'addEventListener'为null
- 无法从 NULL 读取属性“患者”