diff --git a/modules/core/map/js/farmOS.map.behaviors.popup.js b/modules/core/map/js/farmOS.map.behaviors.popup.js index 44efeab6..d7b20c3d 100644 --- a/modules/core/map/js/farmOS.map.behaviors.popup.js +++ b/modules/core/map/js/farmOS.map.behaviors.popup.js @@ -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 `${name}`; + } + // 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 !== '') {