Add a locations map behavior and refactor dashboard map logic to use it.
This commit is contained in:
parent
433747d0ff
commit
1b2ce0b075
|
@ -60,11 +60,9 @@ class MapRenderEventSubscriber implements EventSubscriberInterface {
|
|||
*/
|
||||
public function onMapRender(MapRenderEvent $event) {
|
||||
|
||||
// Get the map ID.
|
||||
$map_id = $event->getmapType()->id();
|
||||
|
||||
// Add land type layers to dashboard map.
|
||||
if ($map_id == 'dashboard') {
|
||||
// If the "locations" behavior is added to the map, add layers for each
|
||||
// land type.
|
||||
if (in_array('locations', $event->getMapBehaviors())) {
|
||||
$layers = [];
|
||||
|
||||
// Define the parent group.
|
||||
|
|
|
@ -60,11 +60,9 @@ class MapRenderEventSubscriber implements EventSubscriberInterface {
|
|||
*/
|
||||
public function onMapRender(MapRenderEvent $event) {
|
||||
|
||||
// Get the map ID.
|
||||
$map_id = $event->getmapType()->id();
|
||||
|
||||
// Add structure type layers to dashboard map.
|
||||
if ($map_id == 'dashboard') {
|
||||
// If the "locations" behavior is added to the map, add layers for each
|
||||
// structure type.
|
||||
if (in_array('locations', $event->getMapBehaviors())) {
|
||||
$layers = [];
|
||||
|
||||
// Define the parent group.
|
||||
|
|
|
@ -0,0 +1,11 @@
|
|||
langcode: en
|
||||
status: true
|
||||
dependencies:
|
||||
enforced:
|
||||
module:
|
||||
- farm_ui_map
|
||||
id: locations
|
||||
label: Location asset layers
|
||||
description: 'Displays location asset geometries in layers by asset type.'
|
||||
library: ''
|
||||
settings: { }
|
|
@ -7,5 +7,6 @@ dependencies:
|
|||
id: dashboard
|
||||
label: Dashboard
|
||||
description: 'The farmOS dashboard map.'
|
||||
behaviors: { }
|
||||
behaviors:
|
||||
- locations
|
||||
options: { }
|
||||
|
|
|
@ -0,0 +1,39 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Post update functions for farm_ui_map module.
|
||||
*/
|
||||
|
||||
use Drupal\farm_map\Entity\MapBehavior;
|
||||
use Drupal\farm_map\Entity\MapType;
|
||||
|
||||
/**
|
||||
* Create farmOS-map locations behavior, add it to dashboard map.
|
||||
*/
|
||||
function farm_ui_map_post_update_locations_behavior(&$sandbox = NULL) {
|
||||
|
||||
// Create locations behavior.
|
||||
$behavior = MapBehavior::create([
|
||||
'id' => 'locations',
|
||||
'label' => 'Location asset layers',
|
||||
'description' => 'Displays location asset geometries in layers by asset type.',
|
||||
'library' => '',
|
||||
'settings' => [],
|
||||
'dependencies' => [
|
||||
'enforced' => [
|
||||
'module' => [
|
||||
'farm_ui_map',
|
||||
],
|
||||
],
|
||||
],
|
||||
]);
|
||||
$behavior->save();
|
||||
|
||||
// Add the locations behavior to the dashboard map type.
|
||||
$dashboard = MapType::load('dashboard');
|
||||
$behaviors = $dashboard->getMapBehaviors();
|
||||
$behaviors[] = 'locations';
|
||||
$dashboard->set('behaviors', $behaviors);
|
||||
$dashboard->save();
|
||||
}
|
|
@ -61,11 +61,8 @@ class MapRenderEventSubscriber implements EventSubscriberInterface {
|
|||
*/
|
||||
public function onMapRender(MapRenderEvent $event) {
|
||||
|
||||
// Get the map ID.
|
||||
$map_id = $event->getmapType()->id();
|
||||
|
||||
// Add behaviors/settings to default and geofield maps.
|
||||
if (in_array($map_id, ['default', 'geofield'])) {
|
||||
if (in_array($event->getmapType()->id(), ['default', 'geofield'])) {
|
||||
|
||||
// Add "All locations" layers.
|
||||
$event->addBehavior('asset_type_layers');
|
||||
|
@ -86,8 +83,9 @@ class MapRenderEventSubscriber implements EventSubscriberInterface {
|
|||
}
|
||||
}
|
||||
|
||||
// Add asset layers to dashboard map.
|
||||
elseif ($map_id == 'dashboard') {
|
||||
// If the "locations" behavior is added to the map, add layers for each
|
||||
// location asset type.
|
||||
if (in_array('locations', $event->getMapBehaviors())) {
|
||||
|
||||
$layers = [];
|
||||
|
||||
|
|
Loading…
Reference in New Issue