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