From 5d350a7cc987dd5ba370f0fd5482e671df6f2c56 Mon Sep 17 00:00:00 2001 From: Yohan Boniface Date: Sat, 10 Jun 2023 21:17:28 +0200 Subject: [PATCH] Control property used in choropleth --- umap/static/umap/js/umap.layer.js | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/umap/static/umap/js/umap.layer.js b/umap/static/umap/js/umap.layer.js index 16a3d75b..418dccfd 100644 --- a/umap/static/umap/js/umap.layer.js +++ b/umap/static/umap/js/umap.layer.js @@ -123,9 +123,14 @@ L.U.Layer.Choropleth = L.FeatureGroup.extend({ ) }, + _getValue: function (feature) { + const key = this.datalayer.options.choropleth.property || 'value' + return feature.properties[key] + }, + computeLimits: function () { const values = [] - this.datalayer.eachLayer((layer) => values.push(layer.properties.density)) + this.datalayer.eachLayer((layer) => values.push(this._getValue(layer))) this.options.limits = chroma.limits( values, this.datalayer.options.choropleth.mode || 'q', @@ -139,7 +144,7 @@ L.U.Layer.Choropleth = L.FeatureGroup.extend({ getColor: function (feature) { if (!feature) return // FIXME shold not happen - const featureValue = feature.properties.density + const featureValue = this._getValue(feature) // Find the bucket/step/limit that this value is less than and give it that color for (let i = 0; i < this.options.limits.length; i++) { if (featureValue <= this.options.limits[i]) { @@ -169,6 +174,14 @@ L.U.Layer.Choropleth = L.FeatureGroup.extend({ getEditableOptions: function () { return [ + [ + 'options.choropleth.property', + { + handler: 'BlurInput', + placeholder: L._('Choropleth property value'), + helpText: L._('Choropleth property value'), + }, + ], [ 'options.choropleth.steps', {