Skip to content
Snippets Groups Projects
Commit fc070679 authored by sleitner's avatar sleitner
Browse files

Initial commit

parents
Branches
Tags 1.0.0-alpha1
No related merge requests found
CONTENTS OF THIS FILE
---------------------
* Introduction
* Requirements
* Installation
* Configuration
* Troubleshooting
* FAQ
* Maintainers
INTRODUCTION
------------
The Geolocation Leaflet Center Node module allows to hide fields, if the cookie
category is not accepted.
* For a full description of the module visit:
https://www.drupal.org/project/geolocation_leafletcenternode
* To submit bug reports and feature suggestions, or to track changes visit:
https://www.drupal.org/project/issues/geolocation_leafletcenternode
REQUIREMENTS
------------
This module requires the Geolocation module.
INSTALLATION
------------
Install the Geolocation Leaflet Center Node module as you would normally
install a contributed Drupal module. Visit https://www.drupal.org/node/1897420
for further information.
CONFIGURATION
-------------
1. Navigate to Administration > Extend and enable the Geolocation Leaflet
Center Node module.
2. Change center settings in view settings.
TROUBLESHOOTING
---------------
FAQ
---
MAINTAINERS
-----------
* sleitner - https://www.drupal.org/u/sleitner
{
"name": "drupal/geolocation_leafletcenternode",
"description": "Center on current node location in view",
"type": "drupal-module",
"homepage": "https://drupal.org/project/geolocation_leafletcenternode",
"authors": [
{
"name": "Stefan Leitner (sleitner)",
"homepage": "https://www.drupal.org/u/sleitner",
"role": "Maintainer"
}
],
"support": {
"issues": "https://drupal.org/project/issues/geolocation_leafletcenternode",
"source": "https://cgit.drupalcode.org/geolocation_leafletcenternode"
},
"require": {
"drupal/geolocation": "~3.7"
}
}
plugin.plugin_configuration.geolocation.map_feature.geolocation_leafletcenternode:
type: geolocation.map_feature_settings
label: 'Center Node'
mapping:
settings:
type: mapping
label: 'Settings'
mapping:
min_zoom:
type: integer
label: 'Zoom level'
core_version_requirement: ^8.7.7 || ^9
type: module
name: Geolocation Leaflet Center Node
description: 'Center on current node location in view'
package: Geolocation
dependencies:
- geolocation:geolocation
- drupal:views
#
#
# API
#
#
map_feature.leaflet_center_node:
js:
js/MapFeature/center_node.js: {}
/**
* @file
* Center map by Node.
*/
(function ($, Drupal) {
'use strict';
/**
* Center map by Node.
*
* @type {Drupal~behavior}
*
* @prop {Drupal~behaviorAttach} attach
* Attaches common map style functionality to relevant elements.
*/
Drupal.behaviors.geolocationCenterNode = {
attach: function (context, drupalSettings) {
Drupal.geolocation.executeFeatureOnAllMaps(
'leaflet_center_node',
/**
* @param {GeolocationLeafletMap} map - Current map.
* @param {MarkerIconSettings} featureSettings - Settings for current feature.
*/
function (map, featureSettings) {
var path = window.location.pathname;
$.each(map.mapMarkers, function (index, marker) {
if (marker.locationWrapper.data('nid') == path) {
map.setCenterByCoordinates(marker.getLatLng() );
if (featureSettings.min_zoom != '') {
map.setZoom(featureSettings.min_zoom);
}
}
});
return false;
},
drupalSettings
);
},
detach: function (context, drupalSettings) {}
};
})(jQuery, Drupal);
<?php
namespace Drupal\geolocation_leafletcenternode\Plugin\geolocation\MapFeature;
use Drupal\geolocation\MapFeatureBase;
use Drupal\Core\Render\BubbleableMetadata;
use Drupal\Core\Template\Attribute;
/**
* Provides Feature.
*
* @MapFeature(
* id = "leaflet_center_node",
* name = @Translation("Center Node"),
* description = @Translation("Center on current node location. Field Content:View node, URL as text required"),
* type = "leaflet",
* )
*/
class LeafletCenterNode extends MapFeatureBase {
/**
* {@inheritdoc}
*/
public static function getDefaultSettings() {
return [
'min_zoom' => FALSE,
'reset_zoom' => FALSE,
];
}
/**
* {@inheritdoc}
*/
public function getSettingsForm(array $settings, array $parents) {
$form['min_zoom'] = [
'#type' => 'number',
'#min' => 0,
'#step' => 1,
'#title' => $this->t('Zoom level'),
'#default_value' => $settings['min_zoom'],
];
return $form;
}
/**
* {@inheritdoc}
*/
public function alterMap(array $render_array, array $feature_settings, array $context = []) {
if (empty($render_array['#children']['locations'])) {
return $render_array;
}
if (!empty($context['view'])) {
/** @var \Drupal\views\ViewExecutable $view */
$view = $context['view'];
}
foreach ($render_array['#children']['locations'] as &$location) {
$node_id = Drupal::token()->replace('{{ view_node }}', $context);
if (empty($view)) {
continue;
}
if (empty($location['#attributes'])) {
$location['#attributes'] = [];
}
elseif (!is_array($location['#attributes'])) {
$location['#attributes'] = new Attribute($location['#attributes']);
$location['#attributes'] = $location['#attributes']->toArray();
}
if (isset($location['#attributes']['data-views-row-index'])) {
$node_id = $view->getStyle()->tokenizeValue($node_id, (int) $location['#attributes']['data-views-row-index']);
$location['#attributes']['data-nid'] = trim($node_id);
}
}
$render_array = parent::alterMap($render_array, $feature_settings, $context);
$render_array['#attached'] = BubbleableMetadata::mergeAttachments(
empty($render_array['#attached']) ? [] : $render_array['#attached'],
[
'library' => [
'geolocation_leafletcenternode/map_feature.' . $this->getPluginId(),
],
'drupalSettings' => [
'geolocation' => [
'maps' => [
$render_array['#id'] => [
$this->getPluginId() => [
'enable' => TRUE,
'min_zoom' => $feature_settings['min_zoom'],
],
],
],
],
],
]
);
return $render_array;
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment