origo
origo copied to clipboard
Mapbox style vectortile layer extra requests on map initial load
If using an mvt type vectortile layer the tileURL
layer prop can be used to construct the get tile call for the layer. This is overriden by the mandatory tile url of the source property in the mapbox style file on map load, but not before a number of tiles are loaded it seems.
To Reproduce
- Enable the mapbox style extension by uncommenting the line in src/extensions.js
- Have a map with the following props (from PR #929 )
"projectionCode": "EPSG:3857",
"projectionExtent": [-20037508.342789,-20037508.342789,20037508.342789,20037508.342789
],
"proj4Defs": [
{
"code": "EPSG:3006",
"projection": "+proj=utm +zone=33 +ellps=GRS80 +towgs84=0,0,0,0,0,0,0 +units=m +no_defs"
}
],
"extent": [-20037508.342789,-20037508.342789,20037508.342789,20037508.342789
],
"center": [
1800243, 8091548
],
"zoom": 17,
"maxResolution": 156543.03390625,
"constrainResolution": true,
"resolutions": [
156543.03390625,
78271.516953125,
39135.7584765625,
19567.87923828125,
9783.939619140625,
4891.9698095703125,
2445.9849047851562,
1222.9924523925781,
611.4962261962891,
305.74811309814453,
152.87405654907226,
76.43702827453613,
38.218514137268066,
19.109257068634033,
9.554628534317017,
4.777314267158508,
2.388657133579254,
1.194328566789627
],
"source": {
"lmvt": {
"url": "https://mapslab.lantmateriet.se/vt-open/wmts/1.0.0/",
"tileGrid": {
"tileSize": [256,256],
"alignBottomLeft": false,
"extent": [-20037508.342789,-20037508.342789,20037508.342789,20037508.342789],
"origin": [-20037508.342789,20037508.342789],
"resolutions": [
156543.03390625,
78271.516953125,
39135.7584765625,
19567.87923828125,
9783.939619140625,
4891.9698095703125,
2445.9849047851562,
1222.9924523925781,
611.4962261962891,
305.74811309814453,
152.87405654907226,
76.43702827453613,
38.218514137268066,
19.109257068634033,
9.554628534317017,
4.777314267158508,
2.388657133579254,
1.194328566789627
]
}
}
},
"layers": [
{
"name": "se10",
"format": "mvt",
"layerURL": "se10/default/3857/{z}/{y}/{x}.mvt",
"title": "Vector tiles",
"group": "background",
"source": "lmvt",
"style": "lmvt",
"type": "VECTORTILE",
"visible": true,
"queryable": false
}
],
"styles": {
"lmvt": [
[
{
"custom": {
"file": "https://raw.githubusercontent.com/Lantmateriet/Example-vector-tiles-wmts/master/style/se10.json",
"source": "vt-source",
"type": "mapbox"
}
}
]
],
- Try loading the map and observe the result in terms of amount of requests and possible errors.
- Change the layerURL into something faulty and try loading the map again - there will be a number of errors but the map will load
- Change the layerURL back into its correct form and edit src/extensions/olms.js like so:
applyStyle(layer, glStyle, {
updateSource: false
});
There ought to be slightly fewer requests and still a viable map.
Expected behavior The mapbox style vector tile layer speced according to our documentation and no extra requests when initing the map
Additional context
My thought is that the documentation can be updated for mapbox style layers and that we advice one of two strategies, either update the call to applyStyle like above and have a correct tileURL
prop in the layer def, or ignore tileURL
(as well as gridSet
and layerName
that are currently described as mandatory without a tileURL
) and merely use the tile url mentioned in the mapbox style file. (As I understand it it is mandatory : https://docs.mapbox.com/mapbox-gl-js/style-spec/sources/ )
This issue relates somewhat to #1801 in that if the second option is preferred then Origo needs to wait for the style file to load before trying to show the layer in the map