Merge pull request #767 from umap-project/tooltip-var
Allow variables in tooltips
This commit is contained in:
commit
fda5bc4283
2 changed files with 14 additions and 0 deletions
|
@ -157,6 +157,9 @@ L.U.FeatureMixin = {
|
||||||
getDisplayName: function (fallback) {
|
getDisplayName: function (fallback) {
|
||||||
if (fallback === undefined) fallback = this.datalayer.options.name;
|
if (fallback === undefined) fallback = this.datalayer.options.name;
|
||||||
var key = this.getOption('labelKey') || '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;
|
return this.properties[key] || this.properties.title || fallback;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
|
@ -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 () {
|
describe('#properties()', function () {
|
||||||
|
|
||||||
it('should rename property', function () {
|
it('should rename property', function () {
|
||||||
|
|
Loading…
Reference in a new issue