am2222 / mapbox-pmtiles

A custom source to add PmTiles support to mapbox gl js. Supports both raster and vector pmtiles
https://am2222.github.io/mapbox-pmtiles/
12 stars 1 forks source link

Crash if Zoom level specified incorrectly #8

Closed Mtehabsim closed 6 months ago

Mtehabsim commented 7 months ago

Hello Thank you for a great tool, i noticed if I set the max zoom level on the layer wrong or i dont specify it, the page stop loading the map and crash

for example on a source which support zoom from 0 to 14 this would work just fine:

map.addLayer({
                        id: "places",
                        source: "pmTileSourceName",
                        "source-layer": "71933498ed974050a59161d5b7693c37",
                        type: "line",
                        maxzoom: 14,
                    });

while this or setting any number higher than 14 would crash:

 map.addLayer({
                        id: "places",
                        source: "pmTileSourceName",
                        "source-layer": "71933498ed974050a59161d5b7693c37",
                        type: "line"
                    });

Screenshot 2024-03-31 at 11 20 49

am2222 commented 7 months ago

@Mtehabsim I will have a look at it but due to the nature of tbe mbtile I think we need to specify the zoom. I have to write a safer control for it.

Mtehabsim commented 7 months ago

@am2222 The main pain is that overzooming cause to crash too for example if I add a source with maxzoom 20 and a layer with maxzoom 22, it should not send a request to get the 21 zoom from the pmtiles, but instead overzoom the 20 zoom tile it has, so it shouldn't be related to the pmtiles itself but mapbox GL internally.

https://docs.mapbox.com/help/glossary/overzoom/

Please correct me if I got it wrong.

am2222 commented 7 months ago

@Mtehabsim I will have a look at it but due to the nature of tbe pmtiles I think we need to specify the zoom. I have to write a safer checks for it.

I think the main issue here is that for some reason your pmtiles does not have zoom information in the header.

Can you share your pmtile's headers?

Mtehabsim commented 7 months ago

@am2222 Here is the pmtiles file, which was generated using tippecanoe https://sagerdrones-my.sharepoint.com/:u:/g/personal/m_tehabsim_sagerdrone_com/Eai61PLsKGVMhQMPf1dxMWwBD0gxn59b5QlBnHtOGxZytA?e=SsVnoA

am2222 commented 7 months ago

Thanks @Mtehabsim I am looking into it

am2222 commented 7 months ago

@Mtehabsim so for a temporary solution you can always set the min and max zoom of the data at the source level to avoid requesting the tiles for overzoom from the the source. mapbox should be able to handle the overzoom at the layer level

const header = await PmTilesSource.getHeader(url);
const bounds: [number, number, number, number] = [
    header.minLon,
    header.minLat,
    header.maxLon,
    header.maxLat,
  ];

  map.addSource('sourceName', {
    type: PmTilesSource.SOURCE_TYPE,
    url: url,
    minzoom: header.minZoom,
    maxzoom: header.maxZoom,
    bounds: bounds,
  })