Leaflet 传单+;超星系团:L.marker';自动驾驶仪坏了

Leaflet 传单+;超星系团:L.marker';自动驾驶仪坏了,leaflet,mapbox,Leaflet,Mapbox,我正在使用mapbox超星系团库对大量的点数据进行聚类,并在一个闪亮的应用程序中用传单进行绘图。在maxZoom显示点,如果位置错误,用户可以拖动点。Mapbox超级星团使用静态kdbush空间索引,因此每次移动L.marker时,都会重新加载群集(在我的情况下,这不是问题,因为超级星团速度非常快) 但是,只能在可见贴图边界内拖动与超星系团一起使用的L.marker。这是有意义的,因为L.marker只为可见地图边界动态生成。如果使用选项定义了L.marker{draggable:true,au

我正在使用mapbox超星系团库对大量的点数据进行聚类,并在一个闪亮的应用程序中用传单进行绘图。在
maxZoom
显示点,如果位置错误,用户可以拖动点。Mapbox超级星团使用静态kdbush空间索引,因此每次移动
L.marker
时,都会重新加载群集(在我的情况下,这不是问题,因为超级星团速度非常快)

但是,只能在可见贴图边界内拖动与超星系团一起使用的
L.marker
。这是有意义的,因为
L.marker
只为可见地图边界动态生成。如果使用选项定义了
L.marker
{draggable:true,autoPan:true}如果将
L.marker
拖到可见地图范围之外,则会发生错误:

Uncaught TypeError: t is null
  leaflet 1.3.3/dist/leaflet.js:5
  leaflet 1.3.3/dist/leaflet.js:5
  at https://unpkg.com/leaflet@1.3.3/dist/leaflet.js:5
  _adjustPan https://unpkg.com/leaflet@1.3.3/dist/leaflet.js:5
  _adjustPan self-hosted:891
  _adjustPan self-hosted:844
或者在我的闪亮应用程序中,我遇到以下错误:

Uncaught TypeError: Cannot set property '_leaflet_pos' of null
at Object.Lt [as setPosition] (eval at <anonymous> (jquery.min.js:2), <anonymous>:5:9959)
at e._adjustPan (eval at <anonymous> (jquery.min.js:2), <anonymous>:5:71149)
但这似乎以某种方式阻止了拖动事件

我的问题是:有没有一种方法可以让超星系团使用的
L.marker
自动扫描

我在下面设置了一个最小的可复制示例。本例用超星系团绘制单点(
var标记
)和三点(
var标记
)。单个点可以拖动到可见地图范围之外,而簇点不能

var-map=L.map('map').setView([51.505,-1.09],9);
L.tileLayer('http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png').addTo(map);
var标记=新的L.标记([51.505,-1.09]{
真的,
自动扫描:对
}).bindpoppop('autopan working').addTo(map);
//空层组,将动态接收群集数据。
var markers=L.geoJson(空{
pointToLayer:createClusterIcon,
onEachFeature:onEachFeature
}).addTo(地图);
var clusterData={
“类型”:“FeatureCollection”,
“特点”:[
{
“类型”:“功能”,
“财产”:{
“id”:0
},
“几何学”:{
“类型”:“点”,
“坐标”:[-1.0,51.5]
}
},
{
“类型”:“功能”,
“财产”:{
“id”:1
},
“几何学”:{
“类型”:“点”,
“坐标”:[-1.1,51.6]
}
},
{
“类型”:“功能”,
“财产”:{
“id”:2
},
“几何学”:{
“类型”:“点”,
“坐标”:[-0.9,51.4]
}
}
]
}
功能特性(f,层){
//添加拖动事件
层上('拖动',功能(e){
//log('marker dragstart event');
//var position=e.target.getLatLng();
//panTo地图(新L.latLng(position.lat,position.lng));
});
层上('dragend',函数(e){
//console.log('marker dragend event');
var changedPos=e.target.getLatLng();
//console.log('new location'+changedPos);
//再次加载群集
clusterData.features[f.properties.id].geometry.coordinates[1]=changedPos.lat;
clusterData.features[f.properties.id].geometry.coordinates[0]=changedPos.lng;
加载(clusterData.features);
更新();
});
}
//在用户平移/缩放后更新显示的簇。
地图上('moveend',更新);
函数更新(){
如果(!就绪)返回;
var bounds=map.getBounds();
var bbox=[bounds.getWest(),bounds.getSouth(),bounds.getEast(),bounds.getNorth()];
var zoom=map.getZoom();
var clusters=index.getClusters(bbox,zoom);
//console.log('clusters'+clusters);
markers.clearLayers();
标记。添加数据(集群);
}
//缩放以展开用户单击的群集。
标记。打开('单击',功能(e){
//console.log('check data'+e.layer.feature.properties.cluster\u id);
var clusterId=e.layer.feature.properties.cluster\u id;
var中心=e.latlng;
var扩展放大;
if(群集){
expansionZoom=index.getClusterExpansionZoom(clusterId);
map.flyTo(居中,展开缩放);
} 
});
var ready=false;
//加载数据
常数指数=新的超星系团({
半径:150,
最大缩放:10
});
加载(clusterData.features);
就绪=正确;
更新();
函数createClusterIcon(特性,板条){
如果(!feature.properties.cluster){
返回L.marker(latlng,{draggable:true,autoPan:true});//添加autoPan:true
}
变量计数=feature.properties.point\u计数;
变量大小=
计数<100?“小”:
计数<1000?“中”:“大”;
var icon=L.divIcon({
html:“”+feature.properties.point\u count\u缩写+“”,
className:“标记簇标记簇-”+大小,
iconSize:L.点(40,40)
});
返回L.标记(板条{
图标:图标
});
}
#地图{
位置:绝对位置;
排名:0;
左:0;
右:0;
底部:0;
}

layer.on('drag',function(e){
//console.log('marker dragstart event');
var position=e.target.getLatLng();
map.panTo(new L.latLng(position.lat,position.lng));
});