From 80b4473180034ad43ceb7612aff20815ba251855 Mon Sep 17 00:00:00 2001 From: Olivier Guyot Date: Mon, 28 Oct 2019 10:27:26 +0100 Subject: [PATCH] Simplify the heatmap example Use a weight function instead of manually edditing the features. --- examples/heatmap-earthquakes.js | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/examples/heatmap-earthquakes.js b/examples/heatmap-earthquakes.js index 05d28aeb31..93256ab1a8 100644 --- a/examples/heatmap-earthquakes.js +++ b/examples/heatmap-earthquakes.js @@ -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 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 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({