As pointed by @yhy0217 When removing a map-extent from a single layer in a map, the other map-extents should be used to calculate the projection of the layer.
We devised an early method (similar to determineLayerProjection, which should be merged to this method) for layer.js to help with this, which is called from map-extent disconnected Callback and can also be called from the layer disconnectedcallback:
// update the layer projection based on it's children, used if map-meta is appended or map-extents are removed
validateLayerProjection() {
let meta = this.shadowRoot
? this.shadowRoot.querySelector('map-meta[name=projection][content]')
: this.querySelector('map-meta[name=projection][content]');
// if map-meta for project exists use it primarily
if (meta) {
let metaProjection = M._metaContentToObject(
meta.getAttribute('content')
).content;
if (
metaProjection.toUpperCase() !==
this._layer._properties.projection.toUpperCase()
) {
this._layer._properties.projection = metaProjection.toUpperCase();
}
} else {
// otherwise use map-extents to check if projection can be updated
let extents = this.shadowRoot
? this.shadowRoot.querySelectorAll('map-extent')
: this.querySelectorAll('map-extent');
let match = true;
for (let i = 0; i < extents.length; i++) {
if (extents[i].units.toUpperCase() !== extents[0].units.toUpperCase()) {
match = false;
break;
}
}
// if all map-extents have same projection, update layer projection
if (match) {
this._layer._properties.projection = extents[0].units;
} else {
// change projection to map-projection, similar to what is done in initialization
// in determineLayerProjection
this._layer._properties.projection = this._layer.options.mapprojection;
}
}
// check if only layer for mapml-viewer and to update the map projection if needed
if (
this._layer._properties.projection !==
this._layer.options.mapprojection &&
this.parentElement.layers.length === 1
) {
this.parentElement.projection = this._layer._properties.projection;
}
}
Steps to reproduce, paste the following to https://maps4html.org/web-map-doc/demo/sandbox/ and remove the OSMTILE map-extent, expected outcome should be that the map changes projection to CBMTILE to display the CBMTILE map-extent as it is the only layer in the map:
As pointed by @yhy0217 When removing a map-extent from a single layer in a map, the other map-extents should be used to calculate the projection of the layer.
Relevant to https://github.com/Maps4HTML/Web-Map-Custom-Element/pull/911
We devised an early method (similar to determineLayerProjection, which should be merged to this method) for layer.js to help with this, which is called from map-extent disconnected Callback and can also be called from the layer disconnectedcallback:
Steps to reproduce, paste the following to https://maps4html.org/web-map-doc/demo/sandbox/ and remove the OSMTILE
map-extent
, expected outcome should be that the map changes projection to CBMTILE to display the CBMTILE map-extent as it is the only layer in the map: