Search code examples
http-status-code-404openlayerslayer

When a tile is 404, openlayers zoom in the previous tile image instead of hide it


I am using OpenLayers with OSM and Geoportail. I display OSM at the bottom and Geoportail on top.

In France I have no problem but in others country Geoportail has no tiles for big zoom. In this case Geoportail return 404, openLayers keep the previous tile/image and zoom inside :/

I wish to hide the Geoportail tile when the tile doesn't exist, this way I will see the OSM tile.

Any idea how to do it ?

My code to add the both layers :

layers: [
        new OlTile({
            'title': 'OSM',
            source: new OlOSM()
        }),
        new OlTile({
            source : new WMTS({
                          url: 'https://wxs.ign.fr/pratique/geoportail/wmts',
                          layer: 'ORTHOIMAGERY.ORTHOPHOTOS',
                          matrixSet: 'PM',
                          format: 'image/jpeg',
                          projection: 'EPSG:3857',
                          tileGrid: new WMTSTileGrid({
                              origin: [-20037508, 20037508],
                              resolutions: resolutions,
                              matrixIds: matrixIds,
                            }),
                          style: 'normal'
                        })
        })
],

Thank you


Solution

  • As Mike say it in his comment : using "useInterimTilesOnError: false" solve the problem.