From 01c1acf0b35d00c72ea152e70c0c05f035b3dc5c Mon Sep 17 00:00:00 2001 From: Yohan Boniface Date: Thu, 19 Mar 2020 07:37:54 +0100 Subject: [PATCH] Allow variables in tooltips fix #737 --- umap/static/umap/js/umap.features.js | 3 +++ umap/static/umap/test/Feature.js | 11 +++++++++++ 2 files changed, 14 insertions(+) diff --git a/umap/static/umap/js/umap.features.js b/umap/static/umap/js/umap.features.js index 7a6911c8..e7fb7e73 100644 --- a/umap/static/umap/js/umap.features.js +++ b/umap/static/umap/js/umap.features.js @@ -157,6 +157,9 @@ L.U.FeatureMixin = { getDisplayName: function (fallback) { if (fallback === undefined) fallback = this.datalayer.options.name; var key = this.getOption('labelKey') || 'name'; + // Variables mode. + if (key.indexOf("{") != -1) return L.Util.greedyTemplate(key, this.extendedProperties()); + // Simple mode. return this.properties[key] || this.properties.title || fallback; }, diff --git a/umap/static/umap/test/Feature.js b/umap/static/umap/test/Feature.js index fce7ff3e..ee908e4f 100644 --- a/umap/static/umap/test/Feature.js +++ b/umap/static/umap/test/Feature.js @@ -179,6 +179,17 @@ describe('L.U.FeatureMixin', function () { }); + describe('#tooltip', function () { + + it('should have a tooltip when active and allow variables', function () { + this.map.options.showLabel = true; + this.map.options.labelKey = "Foo {name}"; + this.datalayer.redraw(); + assert.equal(qs('.leaflet-tooltip-pane .leaflet-tooltip').textContent, "Foo name poly"); + }); + + }); + describe('#properties()', function () { it('should rename property', function () {