|
93 | 93 | popupMinWidth = this.map.popupMinWidth;
|
94 | 94 | }
|
95 | 95 |
|
| 96 | + // Defensive coding: mapControls gets set in leaflet_build_map(), but |
| 97 | + // might be missing in edge cases. |
| 98 | + let controls = (this.mapControls) ? this.mapControls : {}; |
| 99 | + let settings = {}; |
| 100 | + if (controls.ControlFullscreen) { |
| 101 | + settings.fullscreenControl = true; |
| 102 | + } |
96 | 103 | // load a settings object with all of our map settings
|
97 |
| - var settings = { |
98 |
| - 'fullscreenControl': true, |
99 |
| - }; |
100 | 104 | for (let setting in this.map.settings) {
|
101 | 105 | settings[setting] = this.map.settings[setting];
|
102 | 106 | }
|
103 |
| - settings.zoomControl = false; // replaced by L.Control.Zoomslider |
| 107 | + if (controls.ControlZoomslider) { |
| 108 | + settings.zoomControl = false; // replaced by L.Control.Zoomslider |
| 109 | + } |
104 | 110 |
|
105 | 111 | // Workaround for Safari bug.
|
106 | 112 | // @see https://github.com/backdrop-contrib/leaflet/issues/17
|
|
171 | 177 | }
|
172 | 178 |
|
173 | 179 | // add scale control //+
|
174 |
| - lMap.addControl(new L.control.scale({imperial: false})); |
| 180 | + if (controls.ControlScale) { |
| 181 | + // @todo Evaluate options for dynamic options (imperial). |
| 182 | + let scaleControl = new L.control.scale({imperial: false}); |
| 183 | + lMap.scaleControl = scaleControl; |
| 184 | + lMap.addControl(scaleControl); |
| 185 | + } |
175 | 186 |
|
176 | 187 | // add Zoomslider control //+
|
177 |
| - lMap.addControl(new L.Control.Zoomslider()); |
| 188 | + if (controls.ControlZoomslider) { |
| 189 | + let zoomsliderControl = new L.Control.Zoomslider(); |
| 190 | + lMap.zoomsliderControl = zoomsliderControl; |
| 191 | + lMap.addControl(zoomsliderControl); |
| 192 | + } |
178 | 193 |
|
179 | 194 | // Small box with lat/lon coordinates of mouse click event on map.
|
180 |
| - var c = new L.Control.Coordinates({ |
181 |
| - promptText: Backdrop.t('Press Ctrl+C to copy coordinates'), |
182 |
| - precision: 5 |
183 |
| - }); |
184 |
| - c.addTo(lMap); |
185 |
| - lMap.on('click', function(e) { |
186 |
| - c.setCoordinates(e); |
187 |
| - // Hide the coordinates box again after 4 seconds. |
188 |
| - if (typeof this.hideTimer !== 'undefined') { |
189 |
| - clearTimeout(this.hideTimer); |
190 |
| - } |
191 |
| - this.hideTimer = window.setTimeout(function() { |
192 |
| - c._container.classList.add('hidden'); |
193 |
| - }, 4000); |
194 |
| - }); |
| 195 | + if (controls.ControlCoordinates) { |
| 196 | + let c = new L.Control.Coordinates({ |
| 197 | + promptText: Backdrop.t('Press Ctrl+C to copy coordinates'), |
| 198 | + precision: 5 |
| 199 | + }); |
| 200 | + lMap.coordinatesControl = c; |
| 201 | + c.addTo(lMap); |
| 202 | + lMap.on('click', function(e) { |
| 203 | + c.setCoordinates(e); |
| 204 | + // Hide the coordinates box again after 4 seconds. |
| 205 | + if (typeof this.hideTimer !== 'undefined') { |
| 206 | + clearTimeout(this.hideTimer); |
| 207 | + } |
| 208 | + this.hideTimer = window.setTimeout(function() { |
| 209 | + c._container.classList.add('hidden'); |
| 210 | + }, 4000); |
| 211 | + }); |
| 212 | + } |
195 | 213 |
|
196 | 214 | let zoom = this.map.settings.zoom ? this.map.settings.zoom : this.map.settings.zoomDefault;
|
197 | 215 | // Init ViewCenter plugin with some defaults.
|
|
202 | 220 | vcLatLng: [0, 0],
|
203 | 221 | vcZoom: zoom
|
204 | 222 | });
|
205 |
| - lMap.addControl(viewCenter); |
| 223 | + // @todo viewCenter is in use further down. Might need restructuring. |
| 224 | + if (controls.ControlViewCenter) { |
| 225 | + lMap.viewCenterControl = viewCenter; |
| 226 | + lMap.addControl(viewCenter); |
| 227 | + } |
206 | 228 |
|
207 | 229 | // center the map
|
208 | 230 | if (this.map.center && (this.map.center.force || this.features.length === 0)) {
|
|
0 commit comments