我在Leaflet上有一个Map,它根据我对DC.JS图表的过滤显示标记。
当我不使用getbounds
函数时,我的数据正在过滤。我添加了一个功能来放大所选的功能,现在地图过滤不起作用。
我该如何解决?
// Called when dc.js is filtered (typically from user click interaction)
var onFilt = function(chart, filter) {
updateMap(locations.top(Infinity));
};
// Updates the displayed map markers to reflect the crossfilter dimension passed in
var updateMap = function(locs) {
//clear the existing markers from the map
var minlat = 200, minlon = 200, maxlat = -200, maxlon = -200;
locs.forEach( function(d, i) {
if (d.latitude!=null && d.latitude!=undefined) {
// add a Leaflet marker for the lat lng and insert the application's stated purpose in popup\
// find corners
if (minlat > d.latitude) minlat = d.latitude;
if (minlon > d.longitude) minlon = d.longitude;
if (maxlat < d.latitude) maxlat = d.latitude;
if (maxlon < d.longitude) maxlon = d.longitude;
L.marker([d.latitude, d.longitude]);
}
});
c1 = L.latLng(minlat, minlon);
c2 = L.latLng(maxlat, maxlon);
// fit bounds
map.fitBounds(L.latLngBounds(c1, c2));
// correct zoom to fit markers
setTimeout(function() {
map.setZoom(map.getZoom() - 1);
}, 500);
};
function filtr() {
updateMap(filter);
};
markersLayer.clearLayers();
clusterLayer.clearLayers();
也尝试过:
function filtr() {
updateMap(locations.top(Infinity));
};
您可以在这里找到我的示例:http://htmlpreview.github.io/?https://github.com/renauld94/dashboard/blob/master/index