How to display Heatmap on leaflet map

2019-02-19 20:35发布

问题:

I want to display on my leaflet map a heatmap.

I used heatmap.js from https://github.com/pa7/heatmap.js but it end up just displaying

Uncaught TypeError: Cannot assign to read only property 'data' of object '#'

So eventually i end up going for https://github.com/ursudio/leaflet-webgl-heatmap.

// i noticed that when i debug that

setData method from heatmapLayer has this as arguments

TypeError: 'caller', 'callee', and 'arguments' properties may not be accessed on strict mode functions or the arguments objects for calls to them at Function.invokeGetter (:2:14)

Below is my code

 // I initialize heatmap

 // first function where i define and create map and the heatmap 
 var heatmapLayer = new L.webGLHeatmap({
   size: 25, // diameter-in-pixels
   units: 'px',
    opacity: 0.5,
    alphaRange: 0.4 
});

  var myRenderer = L.canvas({ padding: 0.5 });
     var markers = L.markerClusterGroup( { 
        chunkedLoading: true,
        renderer: myRenderer,
        iconCreateFunction: function  (cluster) {
        var childCount = cluster.getChildCount();

        var c = ' marker-cluster-';
        if (childCount < 10) {
            c += 'small';
        } 
        else if (childCount < 100) {
            c += 'medium';
        } 
            else {
                c += 'large';
            }

            return new L.DivIcon({ html: '<div><span>' + childCount + '</span></div>', 
               className: 'marker-cluster' + c, iconSize: new L.Point(40, 40) 
});
}
         });


 var overlays   = {
                 "Fancy Markers": markers,
         "Fancy Heatmap": heatmapLayer
          };

    L.control.layers(baseLayer, overlays).addTo(map);
    component.set("v.map", map); 
    component.set('v.markers',markers);
    component.set('v.heatLayer',heatmapLayer);

second function

var heatmapLayer = component.get('v.heatLayer');
var locationsAccounts = new Array(accounts.length);    

 for (var i=0, len = accounts.length; i<len; i++) {
          locationsAccounts[i]=[account.ShippingLatitude, 
account.ShippingLongitude,1];

}

  heatmapLayer.setData(locationsAccounts);