From 563839b9a6d3f67fcabaf048b234c97edad53a88 Mon Sep 17 00:00:00 2001 From: Yohan Boniface Date: Sat, 7 Jul 2018 15:12:30 +0200 Subject: [PATCH] Add rank in feature.extendedProperties() and use it for icon symbol cf #527 --- umap/static/umap/js/umap.features.js | 18 ++++++++++++++++++ umap/static/umap/js/umap.icon.js | 2 +- umap/static/umap/js/umap.popup.js | 11 +---------- 3 files changed, 20 insertions(+), 11 deletions(-) diff --git a/umap/static/umap/js/umap.features.js b/umap/static/umap/js/umap.features.js index e35c23b4..bed57df0 100644 --- a/umap/static/umap/js/umap.features.js +++ b/umap/static/umap/js/umap.features.js @@ -436,6 +436,24 @@ L.U.FeatureMixin = { layer.isDirty = true; layer.edit(); return layer; + }, + + extendedProperties: function () { + // Include context properties + properties = this.map.getGeoContext(); + center = this.getCenter(); + properties.lat = center.lat; + properties.lon = center.lng; + properties.lng = center.lng; + properties.rank = this.getRank() + 1; + if (typeof this.getMeasure !== 'undefined') { + properties.measure = this.getMeasure(); + } + return L.extend(properties, this.properties); + }, + + getRank: function () { + return this.datalayer._index.indexOf(L.stamp(this)); } }; diff --git a/umap/static/umap/js/umap.icon.js b/umap/static/umap/js/umap.icon.js index 68170ea3..5d822214 100644 --- a/umap/static/umap/js/umap.icon.js +++ b/umap/static/umap/js/umap.icon.js @@ -30,7 +30,7 @@ L.U.Icon = L.DivIcon.extend({ }, formatUrl: function (url, feature) { - return L.Util.greedyTemplate(url || '', feature ? feature.properties : {}); + return L.Util.greedyTemplate(url || '', feature ? feature.extendedProperties() : {}); } }); diff --git a/umap/static/umap/js/umap.popup.js b/umap/static/umap/js/umap.popup.js index 99491bd7..23855e5f 100644 --- a/umap/static/umap/js/umap.popup.js +++ b/umap/static/umap/js/umap.popup.js @@ -23,16 +23,7 @@ L.U.Popup = L.Popup.extend({ container = L.DomUtil.create('div', ''), content, properties, center; if (this.options.parseTemplate) { - // Include context properties - properties = this.feature.map.getGeoContext(); - center = this.feature.getCenter(); - properties.lat = center.lat; - properties.lon = center.lng; - properties.lng = center.lng; - if (typeof this.feature.getMeasure !== 'undefined') { - properties.measure = this.feature.getMeasure(); - } - properties = L.extend(properties, this.feature.properties); + properties = this.feature.extendedProperties(); // Resolve properties inside description properties.description = L.Util.greedyTemplate(this.feature.properties.description || '', properties); content = L.Util.greedyTemplate(template, properties);