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

View File

@@ -16,16 +16,15 @@ const vector = new HeatmapLayer({
})
}),
blur: parseInt(blur.value, 10),
radius: parseInt(radius.value, 10)
});
vector.getSource().on('addfeature', function(event) {
// 2012_Earthquakes_Mag5.kml stores the magnitude of each earthquake in a
// standards-violating <magnitude> tag in each Placemark. We extract it from
// the Placemark's name instead.
const name = event.feature.get('name');
const magnitude = parseFloat(name.substr(2));
event.feature.set('weight', magnitude - 5);
radius: parseInt(radius.value, 10),
weight: function(feature) {
// 2012_Earthquakes_Mag5.kml stores the magnitude of each earthquake in a
// standards-violating <magnitude> tag in each Placemark. We extract it from
// the Placemark's name instead.
const name = feature.get('name');
const magnitude = parseFloat(name.substr(2));
return magnitude - 5;
}
});
const raster = new TileLayer({
@@ -34,7 +33,7 @@ const raster = new TileLayer({
})
});
const map = new Map({
new Map({
layers: [raster, vector],
target: 'map',
view: new View({