我试图通过websockets实时绘制一个映射可视化文件,并在其中获取新的点。最初在地图上绘制这些标记似乎很简单,但我不确定在Mapbox上更新图层的正确方式是什么。更新Leaflet/Mapbox中的图层
截至目前,每当我得到一个新的点,我删除旧的层,创建一个新的,然后将其添加到地图上。这种方法存在的问题是速度慢,而且对于大量的点(> 5000)它开始滞后。
// remove layer
if (this.pointsLayer != null) {
map.removeLayer(this.pointsLayer);
}
// build geoJSON
var geoJSON = { "type": "FeatureCollection", "features": [] };
geoJSON["features"] = tweets.map(function(tweet) {
return this.getGeoPoint(tweet);
}.bind(this));
// add geoJSON to layer
this.pointsLayer = L.mapbox.featureLayer(geoJSON, {
pointToLayer: function(feature, latlon) {
return L.circleMarker(latlon, {
fillColor: '#AA5042',
fillOpacity: 0.7,
radius: 3,
stroke: false
});
}
}).addTo(map);
有没有更好的方法?
您的目标是随着时间的推移不断地添加地图,还是要删除旧点? –