| 399 | break; |
| 400 | case 'projection': |
| 401 | const reconnectLayers = () => { |
| 402 | // save map location and zoom |
| 403 | let lat = this.lat; |
| 404 | let lon = this.lon; |
| 405 | let zoom = this.zoom; |
| 406 | // saving the lat, lon and zoom is necessary because Leaflet seems |
| 407 | // to try to compensate for the change in the scales for each zoom |
| 408 | // level in the crs by changing the zoom level of the map when |
| 409 | // you set the map crs. So, we save the current view for use below |
| 410 | // when all the layers' reconnections have settled. |
| 411 | // leaflet doesn't like this: https://github.com/Leaflet/Leaflet/issues/2553 |
| 412 | this._map.options.crs = M[newValue]; |
| 413 | this._map.options.projection = newValue; |
| 414 | let layersReady = []; |
| 415 | this._map.announceMovement.disable(); |
| 416 | for (let layer of this.querySelectorAll('map-layer,layer-')) { |
| 417 | layer.removeAttribute('disabled'); |
| 418 | let reAttach = this.removeChild(layer); |
| 419 | this.appendChild(reAttach); |
| 420 | layersReady.push(reAttach.whenReady()); |
| 421 | } |
| 422 | return Promise.allSettled(layersReady).then(() => { |
| 423 | // For single-layer case (e.g. link traversal), synchronously set |
| 424 | // zoom constraints so that layer.zoomTo() uses correct bounds |
| 425 | const layers = this.querySelectorAll('map-layer,layer-'); |
| 426 | if (layers.length === 1) { |
| 427 | const layer = layers[0]; |
| 428 | if (layer.extent) { |
| 429 | this._map.setMinZoom(layer.extent.zoom.minZoom); |
| 430 | this._map.setMaxZoom(layer.extent.zoom.maxZoom); |
| 431 | } |
| 432 | } |
| 433 | // use the saved map location to ensure it is correct after |
| 434 | // changing the map CRS. Specifically affects projection |
| 435 | // upgrades, e.g. https://maps4html.org/experiments/custom-projections/BNG/ |
| 436 | // see leaflet bug: https://github.com/Leaflet/Leaflet/issues/2553 |
| 437 | this.zoomTo(lat, lon, zoom); |
| 438 | if (M.options.announceMovement) this._map.announceMovement.enable(); |
| 439 | // required to delay until map-extent.disabled is correctly set |
| 440 | // which happens as a result of map-layer._validateDisabled() |
| 441 | // which happens so much we have to delay until they calls are |
| 442 | // completed |
| 443 | setTimeout(() => { |
| 444 | this.dispatchEvent(new CustomEvent('map-projectionchange')); |
| 445 | }, 0); |
| 446 | }); |
| 447 | }; |
| 448 | if ( |
| 449 | newValue && |
| 450 | this._map && |