Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Zoom level changes when check and then uncheck layers #764

Closed
yhy0217 opened this issue Feb 20, 2023 · 2 comments
Closed

Zoom level changes when check and then uncheck layers #764

yhy0217 opened this issue Feb 20, 2023 · 2 comments

Comments

@yhy0217
Copy link
Contributor

yhy0217 commented Feb 20, 2023

https://maps4html.org/experiments/custom-projections/BNG/

when turn the OS Roads tile map in BNG custom projection layer on and then off, the zoom level changes from 0 to 5 automatically;

Similarly, the BNG Shrink/Swell WMS layer becomes disabled after turning it on then off (as the zoom level changes and gets out of its max zoom bound, I believe).

image

@yhy0217 yhy0217 self-assigned this Feb 20, 2023
@yhy0217
Copy link
Contributor Author

yhy0217 commented Feb 23, 2023

Found the zoom level change is one of leaflet's features.
There is a function called _updateZoomLevels() in leaflet-src.js, which gets called to updates the current zoom level when we make any changes on layers (ex. removing/adding a layer):
image
This function is intended to read min and max zoom limits of all layers and update the current zoom level to fit the layer that is displayed on the map.
For example, say that there is two layers, one (Toporama) has a max zoom limit 5, one (Static MapML with tiles) has min zoom limit 6, and the current map zoom level is 3:

<layer- label="Toporama" checked>
  <map-meta name="zoom" content="max=5"></map-meta>
  <map-extent units="CBMTILE">
    <map-input name="z" type="zoom" value="19" min="0" max="5" ></map-input>
    <map-input name="w" type="width" ></map-input>
    <map-input name="h" type="height" ></map-input>
    <map-input name="xmin" type="location" units="pcrs" position="top-left" axis="easting" min="-6207743.103886206"
      max="3952277.216154434" ></map-input>
    <map-input name="ymin" type="location" units="pcrs" position="bottom-left" axis="northing" min="-3362085.3441706896"
      max="3952277.216154434" ></map-input>
    <map-input name="xmax" type="location" units="pcrs" position="top-right" axis="easting" min="-6207743.103886206"
      max="3952277.216154434" ></map-input>
    <map-input name="ymax" type="location" units="pcrs" position="top-left" axis="northing" min="-3362085.3441706896"
      max="3952277.216154434" ></map-input>
    <map-link rel="image"
              tref="http://wms.ess-ws.nrcan.gc.ca/wms/toporama_en?SERVICE=WMS&amp;REQUEST=GetMap&amp;FORMAT=image/jpeg&amp;TRANSPARENT=FALSE&amp;STYLES=&amp;VERSION=1.3.0&amp;LAYERS=WMS-Toporama&amp;WIDTH={w}&amp;HEIGHT={h}&amp;CRS=EPSG:3978&amp;BBOX={xmin},{ymin},{xmax},{ymax}&amp;m4h=t" ></map-link>
  </map-extent>
</layer->
<layer- label="Static MapML with tiles" checked>
  <map-meta name="zoom" content="min=6"></map-meta>
  <map-meta name="projection" content="CBMTILE"></map-meta>
  <map-link rel="license"
    href="https://www.nrcan.gc.ca/earth-sciences/geography/topographic-information/free-data-geogratis/licence/17285"
    title="Canada Base Map © Natural Resources Canada"></map-link>
  <map-tile zoom="0" row="3" col="3" src="data/cbmt/0/c3_r3.png"></map-tile>
</layer->

When turn off Toporama, the _updateZoomLayers will get called and set zoom level of map to 6, in order to show the Static MapML with tiles layer.
image

It works great when the two layers have similar extent bounds, because when the zoom level gets changed, the layer that is disabled previously (Static MapML with tiles in this case) can become visible.
However, if the two layers have very different extent bounds, like the OS Roads tile map in BNG custom projection layer and the Surficial Geology layer in https://maps4html.org/experiments/custom-projections/BNG/, it behaves weirdly. When removed the OS layer at zoom level = 0, Leaflet intends to set zoom level to 5, which is the min zoom limit of the Surficial Geology layer, but it is still invisible because the current extent does not fall into its extent bounds. As a result, there is nothing shown on the map, but the zoom level gets changed, and since the current zoom level does not reach the min/max zoom limit of the OS layer, so leaflet will not reset the zoom level when add the OS layer back. This causes the "automatic zoom" behavior.

@yhy0217 yhy0217 removed their assignment Feb 24, 2023
@yhy0217
Copy link
Contributor Author

yhy0217 commented Nov 8, 2023

Resolved in #887

@yhy0217 yhy0217 closed this as completed Nov 8, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant