【发布时间】:2014-12-13 12:46:54
【问题描述】:
问题: 要点是,谁能提供一个使用 dc.js + google maps 的玩具示例,当我在 dc.js 图表上刷时,地图的标记会根据图表中选择/刷过的内容进行更新?
到目前为止我所拥有的:pages.github。完整的回购是here。我还发现了这个很酷的snack dashboard 示例,但这使用了传单。我尽量避免传单。
我正在尝试将 dc.js(交叉过滤器)绑定到 Google 地图。我已经看到了这个 video 并且我能够调整这个例子。
但是,当我尝试调整它以使用 dc.js 时,我无法将交叉过滤器绑定回 Google 地图。 (我仍然可以将地图绑定到 crossfilter/dc.js,但不能反过来)。也就是说,在地图上滚动时,图表会调整,但是当我刷图表时,我似乎无法触发我的updateMarkers() 函数。
function init() {
initMap();
initCrossFilter();
// bind map bounds to lat/lng ndx dimensions
latDim = ndx.dimension(function(p) { return p.lat; });
lngDim = ndx.dimension(function(p) { return p.lng; });
google.maps.event.addListener(map, 'bounds_changed', function() {
var bounds = this.getBounds();
var northEast = bounds.getNorthEast();
var southWest = bounds.getSouthWest();
// NOTE: need to be careful with the dateline here
lngDim.filterRange([southWest.lng(), northEast.lng()]);
latDim.filterRange([southWest.lat(), northEast.lat()]);
// NOTE: may want to debounce here, perhaps on requestAnimationFrame
dc.renderAll();
});
// dimension and group for looking up currently selected markers
idDim = ndx.dimension(function(p, i) { return i; });
idGroup = idDim.group(function(id) { return id; });
renderAll();
}
function updateMarkers() {
var pointIds = idGroup.all();
for (var i = 0; i < pointIds.length; i++) {
var pointId = pointIds[i];
markers[pointId.key].setVisible(pointId.value > 0);
}
}
function renderAll() {
updateMarkers();
dc.renderAll();
}
【问题讨论】:
-
好主意。你能制作一个 jsfiddle 或类似的东西,让我们看看你到目前为止有什么吗?请注意,还有 dc.leaflet.js 正在开发中。
-
我发布了我所拥有的内容:pages.github。完整的回购是here。我还发现了这个很酷的snack dashboard 示例,但这使用了传单。如果可能的话,我试图避免传单。
标签: javascript google-maps d3.js dc.js crossfilter