Simplify the heatmap example

Use a weight function instead of manually edditing the features.
This commit is contained in:
Olivier Guyot
2019-10-28 10:27:26 +01:00
parent cd3b222467
commit 80b4473180
+10 -11
View File
@@ -16,16 +16,15 @@ const vector = new HeatmapLayer({
}) })
}), }),
blur: parseInt(blur.value, 10), blur: parseInt(blur.value, 10),
radius: parseInt(radius.value, 10) radius: parseInt(radius.value, 10),
}); weight: function(feature) {
// 2012_Earthquakes_Mag5.kml stores the magnitude of each earthquake in a
vector.getSource().on('addfeature', function(event) { // standards-violating <magnitude> tag in each Placemark. We extract it from
// 2012_Earthquakes_Mag5.kml stores the magnitude of each earthquake in a // the Placemark's name instead.
// standards-violating <magnitude> tag in each Placemark. We extract it from const name = feature.get('name');
// the Placemark's name instead. const magnitude = parseFloat(name.substr(2));
const name = event.feature.get('name'); return magnitude - 5;
const magnitude = parseFloat(name.substr(2)); }
event.feature.set('weight', magnitude - 5);
}); });
const raster = new TileLayer({ const raster = new TileLayer({
@@ -34,7 +33,7 @@ const raster = new TileLayer({
}) })
}); });
const map = new Map({ new Map({
layers: [raster, vector], layers: [raster, vector],
target: 'map', target: 'map',
view: new View({ view: new View({