问题描述
我尝试使用Ghybs solution for adding polygon进行聚类,但是另外还用于折线。
L.polyline.addInitHook(function () {
// @ts-ignore
this._latlng = this._bounds.getCenter();
});
L.polyline.include({
getLatLng: function () {
return this._bounds.getCenter();
},setLatLng: function () {} // Dummy method.
});
L.polygon.addInitHook(function () {
// @ts-ignore
this._latlng = this._bounds.getCenter();
});
// Provide getLatLng and setLatLng methods for Leaflet.markercluster to be able to cluster polygons.
L.polygon.include({
getLatLng: function () {
return this._latlng;
},setLatLng: function () {} // Dummy method.
});
我遇到的问题是,我正在使用传单-geoman编辑(本质上是更新位置)对象。这将导致折线在更改时不存在纬度。
出现此错误:Uncaught TypeError: Cannot read property 'lat' of undefined
添加折线代码后,多边形也会发生这种情况。删除折线代码后,多边形可以正常工作。
总结:我需要对多边形和折线进行聚类,导致折线引起问题,我不明白为什么。
此外,折线实际上会在初始地图加载时聚类。仅在对折线执行更改时才会发生此问题。 (但是如果删除折线代码,则多边形不会发生这种情况)
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)