Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Heatmap based on values instead density #1

Open
ktugan opened this issue Aug 6, 2017 · 2 comments
Open

Heatmap based on values instead density #1

ktugan opened this issue Aug 6, 2017 · 2 comments

Comments

@ktugan
Copy link

ktugan commented Aug 6, 2017

I love the library and would like to make a feature request to build a heatmap from values. Here a superior argument from somebody else (from mapbox/mapbox-gl-js#4756):

by default, heatmaps render according to point density (so two points in the same spot are twice as intense as one). But there are cases where we want a different behavior — imagine an air pollution map that shows measurements from spots around the country. Multiple measure points clustered close together shouldn't cause the area to appear many times more polluted compared to an area with the same pollution but only one measure spot.[...]

I can imagine it would work like this:

    var heatmap = new HexgridHeatmap(map, "hexgrid-heatmap", "waterway-label");
    heatmap.setType('value'); // or 'density' which is default
    heatmap.setWeightProperty('airPollutionLevel'); // a property in each Feature of the FeatureCollection
    heatmap.setReduceFunction('mean'); // 'median' or even a function which accepts values

    //normal init from before
    heatmap.setIntensity(6);
    heatmap.setSpread(0.15); //
    heatmap.setCellDensity(0.5); // small value == bigger hexagons
    heatmap.setData(berlinData);
    heatmap.update();

I assume clustering logic would need little or no changing, but instead of counting all objects are iterated through, the value from the property extracted and the reduce function called.

@ktugan
Copy link
Author

ktugan commented Aug 7, 2017

I implemented my own version of a value based heatmap in a fork without any regards for best practices (since I am not familiar with the javascript ecosystem).

here the diff: ktugan@7cfa0ec

@kronick
Copy link
Owner

kronick commented Aug 31, 2017

@ktugan Thanks for taking a crack at adding in this functionality. Your code style is good, but you get rid of the gaussian kernel calculation that makes this work as a heatmap: ktugan@7cfa0ec#diff-feb43b13521636d30c38958cccf95c91L166

This creates artifacts like those seen here:
image

If you add in this kernel with your property value code, make a PR to this repo and I will work it in.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants