1

I have this GeoJSON (can be downloaded here). The data is distributed through a grid, thus the points are distributed regularly.

distribution of points

However, each point has a different "weight" via the prop count assigned to it. The vast majority has count 1. The max value of count is 90. I want to display a heatmap with Mapbox, but it looks everywhere the same.

Screenshot of heatmap

I would expect some areas to be darker in color and others not. But like this, it all looks the same... These are my heatmap settings (note: its React code, which is why - have been converted to CamelCase)

<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <title>Create a heatmap layer</title>
    <meta name="viewport" content="initial-scale=1,maximum-scale=1,user-scalable=no">
    <link href="https://api.mapbox.com/mapbox-gl-js/v3.5.1/mapbox-gl.css" rel="stylesheet">
    <script src="https://api.mapbox.com/mapbox-gl-js/v3.5.1/mapbox-gl.js"></script>
    <style>
        body { margin: 0; padding: 0; }
         #map { position: absolute; top: 0; bottom: 0; width: 100%; }
    </style>
</head>

<body>
    <div id="map"></div>
    <script>
        mapboxgl.accessToken = '...';
            const map = new mapboxgl.Map({
                container: 'map',
                center: [52, 13],
                zoom: 4
            });
         
            map.on('load', () => {
                map.addSource('movementData', {
                    'type': 'geojson',
                    'data': 'the/data/I/provided/for/download'
                });
         
                map.addLayer(
                    {
                        'id': 'movement-heat',
                        'type': 'heatmap',
                        'source': 'movementData',
                        'maxzoom': 15,
                        'paint': {
                            "heatmap-color": [
                                "interpolate",
                                [
                                  "linear"
                                ],
                                [
                                  "heatmap-density"
                                ],
                                0,
                                "rgba(33,102,172,0)",
                                0.2,
                                "#005F80",
                                0.4,
                                "rgb(209,229,240)",
                                0.6,
                                "rgb(253,219,199)",
                                0.8,
                                "rgb(239,138,98)",
                                1,
                                "rgb(178,24,43)"
                              ],
                              "heatmap-intensity": [
                                "interpolate",
                                [
                                  "linear"
                                ],
                                [
                                  "zoom"
                                ],
                                2,
                                1,
                                15,
                                4
                              ],
                              "heatmap-opacity": 0.7,
                              "heatmap-radius": [
                                "interpolate",
                                [
                                  "linear"
                                ],
                                [
                                  "zoom"
                                ],
                                2,
                                36,
                                15,
                                1
                              ],
                              "heatmap-weight": [
                                "interpolate",
                                [
                                  "linear"
                                ],
                                [
                                  "get",
                                  "value"
                                ],
                                1,
                                0,
                                90,
                                1
                              ]
                        }
                    },
                );
            });
    </script>
</body>
</html>

Why are there no "denser" and "no-denser" areas being colored?

2
  • Coding question on GIS SE site should include relevant existing code of what has been tried so far, otherwise it's most likely to be closed as not compliant with the site policy. Please edit your question and add relevant existing code.
    – TomazicM
    Commented Jul 25 at 17:49
  • @TomazicM The relevant bit is here. The data as well as the styling I picked. Of course I could wrap that in a lot of code like done here docs.mapbox.com/mapbox-gl-js/example/heatmap-layer, but the main part is the data which I provided and the styling. But if thats what you want :)
    – four-eyes
    Commented Jul 26 at 5:21

1 Answer 1

2

Problem is in your heatmap-weight specification:

"heatmap-weight": [
  "interpolate",
  [
    "linear"
  ],
  [
    "get",
    "value"
  ],
  1, 0,
  90, 1
]

Instead of using actual value count from GeoJSON properties you left placeholder value value.

You have to specify heatmap-weight like this:

"heatmap-weight": [
  "interpolate",
  [
    "linear"
  ],
  [
    "get",
    "count"
  ],
  1, 0,
  90, 1
]

This is how heat map looks like then:

enter image description here

1
  • Oh dear.... Thank you so much!
    – four-eyes
    Commented Jul 27 at 8:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.