Skip to content

Instantly share code, notes, and snippets.

@ewg118
Created July 1, 2015 20:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ewg118/38d3a8d94ba0c771753f to your computer and use it in GitHub Desktop.
Save ewg118/38d3a8d94ba0c771753f to your computer and use it in GitHub Desktop.
Leaflet heatmap, getJSON vs hard-coded
// don't forget to include leaflet-heatmap.js
var heatmapArray = $.getJSON('../apis/heatmap?uri=http://nomisma.org/id/' + id);
var testData = {
"max": 4, "data":[ {
"lat": 45.31859, "lng": 11.27843, "count": 1
},
{
"lat": 45.03537, "lng": 11.22923, "count": 1
},
"lat": 40.4223, "lng": 15.00731, "count": 1
},
{
"lat": 44.23819, "lng": 12.15277, "count": 1
},
{
"lat": 42.83333, "lng": 12.83333, "count": 1
}]
};
var baseLayer = L.tileLayer(
'http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
attribution: '...',
maxZoom: 18
});
var cfg = {
// radius should be small ONLY if scaleRadius is true (or small radius is intended)
// if scaleRadius is false it will be the constant radius used in pixels
"radius": 1,
"maxOpacity": .8,
// scales the radius based on map zoom
"scaleRadius": true,
// if set to false the heatmap uses the global maximum for colorization
// if activated: uses the data maximum within the current map boundaries
// (there will always be a red spot with useLocalExtremas true)
"useLocalExtrema": true,
// which field name in your data represents the latitude - default "lat"
latField: 'lat',
// which field name in your data represents the longitude - default "lng"
lngField: 'lng',
// which field name in your data represents the data value - default "value"
valueField: 'count'
};
var heatmapLayer = new HeatmapOverlay(cfg);
var map = new L.Map('mapcontainer', {
center: new L.LatLng(41.9, 12.5),
zoom: 4,
layers:[baseLayer, heatmapLayer]
});
heatmapLayer.setData(testData);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment