3
0
Fork 0
mirror of https://github.com/farmOS/farmOS.git synced 2024-02-23 11:37:38 +01:00

Revert "Add a setting to configure if the map popup behavior is enabled."

This reverts commit 19f8851543.
This commit is contained in:
Michael Stenta 2021-04-08 15:13:00 -04:00
parent c7ddaab912
commit 930df73049
4 changed files with 28 additions and 49 deletions

View file

@ -8,7 +8,4 @@ id: geofield_widget
label: Geofield widget
description: 'Renders a geofield widget using farmOS-map.'
behaviors: { }
options:
behaviors:
popup:
enabled: false
options: { }

View file

@ -2,44 +2,37 @@
farmOS.map.behaviors.popup = {
attach: function (instance) {
// Add a popup if enabled on the instance. Popups are enabled by default.
const enabled = drupalSettings.farm_map[instance.target]?.behaviors?.popup?.enabled ?? true;
if (enabled) {
// Create a popup and add it to the instance for future reference.
instance.popup = instance.addPopup(function (event) {
var content = '';
var feature = instance.map.forEachFeatureAtPixel(event.pixel, function(feature, layer) { return feature; });
if (feature) {
// Create a popup and add it to the instance for future reference.
instance.popup = instance.addPopup(function (event) {
var content = '';
var feature = instance.map.forEachFeatureAtPixel(event.pixel, function (feature, layer) {
return feature;
});
if (feature) {
// If the feature is a cluster, then create a list of names and add it
// to the overall feature's description.
var features = feature.get('features');
if (features !== undefined) {
var names = [];
features.forEach(function (item) {
if (item.get('name') !== undefined) {
names.push(item.get('name'));
}
});
if (names.length !== 0) {
feature.set('description', '<ul><li>' + names.join('</li><li>') + '</li></ul>');
// If the feature is a cluster, then create a list of names and add it
// to the overall feature's description.
var features = feature.get('features');
if (features !== undefined) {
var names = [];
features.forEach(function (item) {
if (item.get('name') !== undefined) {
names.push(item.get('name'));
}
feature.set('name', names.length + ' item(s):');
}
var name = feature.get('name') || '';
var description = feature.get('description') || '';
var measurement = instance.measureGeometry(feature.getGeometry(), instance.units);
if (name !== '' || measurement !== '' || description !== '') {
content = '<h4 class="ol-popup-name">' + name + '</h4><div class="ol-popup-measurement"><small>' + measurement + '</small></div><div class="ol-popup-description">' + description + '</div>';
});
if (names.length !== 0) {
feature.set('description', '<ul><li>' + names.join('</li><li>') + '</li></ul>');
}
feature.set('name', names.length + ' item(s):');
}
return content;
});
}
var name = feature.get('name') || '';
var description = feature.get('description') || '';
var measurement = instance.measureGeometry(feature.getGeometry(), instance.units);
if (name !== '' || measurement !== '' || description !== '') {
content = '<h4 class="ol-popup-name">' + name + '</h4><div class="ol-popup-measurement"><small>' + measurement + '</small></div><div class="ol-popup-description">' + description + '</div>';
}
}
return content;
});
}
};
}());

View file

@ -47,16 +47,6 @@ class MapRenderEventSubscriber implements EventSubscriberInterface {
if (in_array($event->getMapType()->id(), ['geofield_widget'])) {
$event->addBehavior('wkt');
$event->addBehavior('geofield');
// Disable popups for the geofield_widget map.
// @todo Allow this to be set on the map type config entity.
// This should be a proper instance specific setting.
// In the map type config, it should be possible to add behavior specific
// settings in the top-level "behaviors" list (right now it just accepts
// behavior IDs). Each behavior could provide schema for its valid
// setting options.
$settings[$event->getMapTargetId()]['behaviors']['popup']['enabled'] = FALSE;
$event->addSettings($settings);
}
}

View file

@ -3,5 +3,4 @@ behavior_asset_type_layers:
js/farmOS.map.behaviors.asset_type_layers.js: { }
dependencies:
- farm_map/farm_map
# NOTICE: This included the popup behavior anytime the asset_type_layers behavior is loaded.
- farm_map/behavior_popup