I'm trying to build a heatmap using leaflet.js and leaflet.heat from data I have in JSON format. So far, I've been able to fetch and parse my JSON file using jQuery's getJSON, but I'm stuck at the part where I loop through the file and return the arrays leaflet.heat needs to build the heatmap layer on top of leaflet.
According to leaflet.heat's documentation, all I need to pass to the library is an array constructed like so:
[latitude, longitude, intensity]
My JSON looks like this:
[{"Lat":"39.51","Long":"-76.164","Intensity":"0.0017980221756068300"},
{"Lat":"39.463","Long":"-76.12","Intensity":"0.0332634102487264000"},
...more data...]
Here is my code:
$.getJSON( 'data.json',
function(data){
var heat = L.heatLayer(data, {radius: 25}).addTo(map);
});
});
When I run this, I get the following error:
TypeError: null is not an object (evaluating 't.lat')
I assume this is resulting from passing a JSON object when the library requires an array without keys. I've looked at this similar SO question, but when I log the output to the console with this code,
var arr = $.map(data, function(el) { return el });
console.log(arr);
...it's still output as an object with keys. Not sure what I'm doing wrong.