Render the feature name as a link in popups if a url is provided.

This commit is contained in:
paul121 2021-05-19 16:45:47 -07:00 committed by Michael Stenta
parent 1cb8e99928
commit 0a94bbb6d9
1 changed files with 16 additions and 3 deletions

View File

@ -2,6 +2,18 @@
farmOS.map.behaviors.popup = {
attach: function (instance) {
// Helper function to build the feature name as a link.
const featureName = function (feature) {
// Bail if either the name or url aren't defined.
const name = feature.get('name');
const url = feature.get('url');
if (name === undefined || url === undefined) {
return name;
}
// Build a link with the url and name.
return `<a href="${url}">${name}</a>`;
}
// Create a popup and add it to the instance for future reference.
instance.popup = instance.addPopup(function (event) {
var content = '';
@ -14,8 +26,9 @@
if (features !== undefined) {
var names = [];
features.forEach(function (item) {
if (item.get('name') !== undefined) {
names.push(item.get('name'));
const name = featureName(item);
if (name !== undefined) {
names.push(name);
}
});
if (names.length !== 0) {
@ -24,7 +37,7 @@
feature.set('name', names.length + ' item(s):');
}
var name = feature.get('name') || '';
var name = featureName(feature) || '';
var description = feature.get('description') || '';
var measurement = instance.measureGeometry(feature.getGeometry(), instance.units);
if (name !== '' || measurement !== '' || description !== '') {