1 2// Inspired by Roger Codina and 3// http://gis.stackexchange.com/questions/87199/how-does-one-reset-map-fitbounds-zoomtofeature-to-the-original-zoom 4 5(function ($) { 6 7 $(document).bind('leaflet.map', function(event, map_and_features, lMap) { 8 var mapSettings = map_and_features.settings; 9 // Use a flag on the map object to prevent controls being added multiple 10 // times. This can happen in AJAX contexts. 11 if (lMap && mapSettings) { 12 if (mapSettings.zoomIndicator) { 13 lMap.addControl(L.control.zoomIndicator(mapSettings.zoomIndicator)); 14 } 15 if (mapSettings.resetControl) { 16 lMap.addControl(L.control.reset(mapSettings.resetControl)); 17 } 18 if (mapSettings.clusterControl) { 19 lMap.addControl(L.control.clusterToggle(mapSettings.clusterControl)); 20 } 21 if (mapSettings.scaleControl) { 22 lMap.addControl(L.control.scale(mapSettings.scaleControl)); 23 } 24 if (mapSettings.miniMap) { 25 for (var key in lMap._layers) { 26 var layer = lMap._layers[key]; 27 if (layer instanceof L.TileLayer) { 28 // Copy the (first) main map layer for use in a mini-map inset. 29 var tileLayer = (layer._type === 'quad') 30 // See leaflet_more_maps/leaflet_more_maps.js 31 ? L.tileLayerQuad(layer._url, layer.options) 32 : L.tileLayer(layer._url, layer.options); 33 lMap.addControl(L.control.minimap(tileLayer, mapSettings.miniMap)); 34 break; 35 } 36 } 37 } 38 } 39 }); 40})(jQuery); 41 42L.Control.ZoomIndicator = L.Control.extend({ 43 44 options: { 45 position: 'topleft', 46 prefix: 'z' 47 }, 48 49 onAdd: function(map) { 50 this.indicator = L.DomUtil.create('div', 'leaflet-control-zoom-indicator leaflet-bar'); 51 this.indicator.setAttribute('title', Drupal.t('Zoom level')); 52 this.indicator.innerHTML = this.options.prefix + map.getZoom(); 53 map.on('zoomend', this.update, this); 54 return this.indicator; 55 }, 56 57 update: function(event) { 58 this.indicator.innerHTML = event.target.getZoom(); 59 } 60}); 61L.control.zoomIndicator = function(options) { 62 return new L.Control.ZoomIndicator(options); 63}; 64 65L.Control.Reset = L.Control.extend({ 66 67 options: { 68 position: 'topleft', 69 label: 'R' 70 }, 71 72 onAdd: function(map) { 73 this._map._initialBounds = map.getBounds(); 74 75 var button = L.DomUtil.create('a', 'leaflet-control-reset leaflet-bar'); 76 if (this.options.label.length <= 2) { 77 button.innerHTML = this.options.label; 78 } 79 else { 80 // Assume label is a font-icon specification, e.g. 'fa fa-repeat'. 81 L.DomUtil.addClass(button, this.options.label); 82 } 83 button.setAttribute('title', Drupal.t('Reset')); 84 85 // Must pass "this" in as context, or onClick() will not know us. 86 L.DomEvent 87 .on(button, 'click', this.onClick, this) 88 .on(button, 'dblclick', L.DomEvent.stopPropagation) 89 .on(button, 'dblclick', function(event) { 90 alert(Drupal.t('A single click is sufficient!')); 91 }); 92 93 return button; 94 }, 95 96 onClick: function(event) { 97 this._map.fitBounds(this._map._initialBounds); 98 } 99}); 100L.control.reset = function(options) { 101 return new L.Control.Reset(options); 102}; 103 104L.Control.ClusterToggle = L.Control.extend({ 105 106 options: { 107 position: 'topright' 108 }, 109 110 onAdd: function(map) { 111 var leafletSettings = Drupal.settings.leaflet; 112 for (var m = 0; m < leafletSettings.length; m++) { 113 // Get here once per map, i.e. once per containing div. 114 if (L.DomUtil.get(leafletSettings[m].mapId) === map._container) { 115 this._masterSettings = leafletSettings[m].map.settings; 116 break; 117 } 118 } 119 var button = L.DomUtil.create('a', 'leaflet-control-cluster leaflet-bar'); 120 button.setAttribute('title', Drupal.t('Toggle clustering')); 121 122 // Must pass "this" in as context, or onClick() will not know us. 123 L.DomEvent 124 .on(button, 'click', this.onClick, this) 125 .on(button, 'dblclick', L.DomEvent.stopPropagation) 126 .on(button, 'dblclick', function(event) { 127 alert(Drupal.t('A single click is sufficient!')); 128 }); 129 130 return button; 131 }, 132 133 onClick: function(event) { 134 // This normally only loops once, as there's only one _topClusterLevel 135 for (var leaflet_id in this._map._layers) { 136 if (this._map._layers[leaflet_id]._topClusterLevel) { 137 var clusterGroup = this._map._layers[leaflet_id]; 138 clusterGroup._map = null; 139 if (clusterGroup.options.disableClusteringAtZoom < 0) { 140 // Restore the old disableClusteringAtZoom setting. 141 clusterGroup.options.disableClusteringAtZoom = this._masterSettings ? this._masterSettings.disableClusteringAtZoom : null; 142 } 143 else { 144 // Easiest way to stop clustering safely is this way: 145 clusterGroup.options.disableClusteringAtZoom = -1; 146 } 147 clusterGroup.clearLayers(); 148 // In order for the clusterGroup to be reinitialised with the new 149 // option value(s) set above, clusterGroup._needsClustering needs to
150 // hold all markers to be added, before onAdd(map) can be called. 151 clusterGroup._needsClustering = clusterGroup._topClusterLevel.getAllChildMarkers(); 152 clusterGroup.onAdd(this._map); 153 } 154 } 155 } 156}); 157L.control.clusterToggle = function(options) { 158 return new L.Control.ClusterToggle(options); 159}; 160 161if (L.Control.MiniMap) { 162 L.extend(L.Control.MiniMap.prototype, { 163 hideText: Drupal.t('Hide this inset'), 164 showText: Drupal.t('Show map inset') 165 }); 166}
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.