dc-js / dc.leaflet.js

DC charts using Leaflet maps
Apache License 2.0
52 stars 24 forks source link

when data has exact same lat long, marker cluster displays it only once #35

Closed rrameshkumar76 closed 7 years ago

rrameshkumar76 commented 7 years ago

I am currently facing a issue when data has the exact same lat long it is counted only once to marker cluster. I tried it by adding data to demo1.tsv in examples also. We have scenarios of multiple data points for exact same lat long.

Thanks.

gordonwoodhull commented 7 years ago

By default, the markerChart uses latlongs as its keys - the locationAccessor uses the keyAccessor. If you set up your group with latlong keys, then it will aggregate all values with the same latlong into one group, so there will only be one marker for the map to display.

I think if you group by a unique key instead, and then set up the locationAccessor to return the latlong, you should get the desired effect.

So if the rows have fields id (a unique id) and geo (the latlong), you could set up your dimension and chart like this:

var dimension = xf.dimension(function(d) { return d.id; }); // instead of d.geo
// ...
markerChart.locationAccessor(function(d)  { return d.geo; });

I think you may also need to specify the reduction in order to pass geo through from data to group. Here is a question and answer on SO which explains this better: http://stackoverflow.com/questions/41828806/dc-js-leaflet-marker-popup-showing-fields-from-input-data

You're basically not reducing the data, just setting up a crossfilter group to put each row in its own bin.

Please let me know if this works.

rrameshkumar76 commented 7 years ago

Thanks a lot, The above solution works as expected.

gordonwoodhull commented 7 years ago

Awesome, glad I could help!