PageSourceSearch

https://fedasil.be/modules/contrib/geolocation/modules/geolocation…/geolocation-common-map-leaflet.js?tlbtey

js fedasil.be collected 2026-10-02 03:59:42 UTC 3,879 bytes, 101 lines download raw bytes

1/**
2 * @file
3 * Common Map Leaflet.
4 */
5
6(function ($, Drupal) {
7
8  'use strict';
9
10  /**
11   * Dynamic map handling aka "AirBnB mode".
12   *
13   * @type {Drupal~behavior}
14   *
15   * @prop {Drupal~behaviorAttach} attach
16   *   Attaches common map style functionality to relevant elements.
17   */
18  Drupal.behaviors.geolocationCommonMapLeaflet = {
19    /**
20     * @param {GeolocationSettings} drupalSettings.geolocation
21     */
22    attach: function (context, drupalSettings) {
23      $.each(
24        drupalSettings.geolocation.commonMap,
25
26        /**
27         * @param {String} mapId - ID of current map
28         * @param {CommonMapSettings} commonMapSettings - settings for current map
29         */
30        function (mapId, commonMapSettings) {
31          if (
32            typeof commonMapSettings.dynamic_map !== 'undefined'
33            && commonMapSettings.dynamic_map.enable
34          ) {
35            var map = Drupal.geolocation.getMapById(mapId);
36
37            if (!map) {
38              return;
39            }
40
41            if (map.container.hasClass('geolocation-common-map-leaflet-processed')) {
42              return;
43            }
44            map.container.addClass('geolocation-common-map-leaflet-processed');
45
46            /**
47             * Update the view depending on dynamic map settings and capability.
48             *
49             * One of several states might occur now. Possible state depends on whether:
50             * - view using AJAX is enabled
51             * - map view is the containing (page) view or an attachment
52             * - the exposed form is present and contains the boundary filter
53             * - map settings are consistent
54             *
55             * Given these factors, map boundary changes can be handled in one of three ways:
56             * - trigger the views AJAX "RefreshView" command
57             * - trigger the exposed form causing a regular POST reload
58             * - fully reload the website
59             *
60             * These possibilities are ordered by UX preference.
61             */
62            if (
63              map.container.length
64              && map.type === 'leaflet'
65            ) {
66              map.addPopulatedCallback(function (map) {
67                var geolocationMapIdleTimer;
68                map.leafletMap.on('moveend zoomend', /** @param {LeafletMouseEvent} e */function (e) {
69                  clearTimeout(geolocationMapIdleTimer);
70
71                  geolocationMapIdleTimer = setTimeout(
72                    function () {
73                      var ajaxSettings = Drupal.geolocation.commonMap.dynamicMapViewsAjaxSettings(commonMapSettings);
74
75                      // Add bounds.
76                      var currentBounds = map.leafletMap.getBounds();
77                      var bound_parameters = {};
78                      bound_parameters[commonMapSettings['dynamic_map']['parameter_identifier'] + '[lat_north_east]'] = currentBounds.getNorthEast().lat;
79                      bound_parameters[commonMapSettings['dynamic_map']['parameter_identifier'] + '[lng_north_east]'] = currentBounds.getNorthEast().lng;
80                      bound_parameters[commonMapSettings['dynamic_map']['parameter_identifier'] + '[lat_south_west]'] = currentBounds.getSouthWest
80().lat;
81                      bound_parameters[commonMapSettings['dynamic_map']['parameter_identifier'] + '[lng_south_west]'] = currentBounds.getSouthWest().lng;
82
83                      ajaxSettings.submit = $.extend(
84                        ajaxSettings.submit,
85                        bound_parameters
86                      );
87
88                      Drupal.ajax(ajaxSettings).execute();
89                    },
90                    commonMapSettings.dynamic_map.views_refresh_delay
91                  );
92                });
93              });
94            }
95          }
96        });
97    },
98    detach: function (context, drupalSettings) {}
99  };
100
101})(jQuery, Drupal);

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.