1010 */
1111
1212import { MapLibreLayer } from ' @geoblocks/ol-maplibre-layer'
13- import axios from ' axios '
13+ import { Source } from ' ol/source '
1414import { computed , inject , toRefs , watch } from ' vue'
1515
1616import GeoAdminVectorLayer from ' @/api/layers/GeoAdminVectorLayer.class'
17- import { VECTOR_TILES_IMAGERY_STYLE_ID } from ' @/config/vectortiles.config'
1817import useAddLayerToMap from ' @/modules/map/components/openlayers/utils/useAddLayerToMap.composable'
19- import log from ' @/utils/logging'
2018
2119const props = defineProps ({
2220 vectorLayerConfig: {
@@ -35,65 +33,27 @@ const props = defineProps({
3533const { vectorLayerConfig , parentLayerOpacity , zIndex } = toRefs (props)
3634
3735// extracting useful info from what we've linked so far
38- const layerId = computed (() => vectorLayerConfig .value .id )
36+ const layerId = computed (() => vectorLayerConfig .value .vectorStyleId )
3937const opacity = computed (() => parentLayerOpacity .value ?? vectorLayerConfig .value .opacity )
4038const styleUrl = computed (
4139 () => ` ${ vectorLayerConfig .value .baseUrl } styles/${ layerId .value } /style.json`
4240)
4341
4442const layer = new MapLibreLayer ({
45- id: layerId .value ,
4643 opacity: opacity .value ,
44+ mapLibreOptions: {
45+ style: styleUrl .value ,
46+ },
47+ source: new Source ({
48+ attribution: [vectorLayerConfig .value .attribution ],
49+ }),
4750})
48- setMapLibreStyle (styleUrl .value )
4951
5052const olMap = inject (' olMap' )
5153useAddLayerToMap (layer, olMap, zIndex)
5254
5355watch (opacity, (newOpacity ) => layer .setOpacity (newOpacity))
54- watch (styleUrl, (newStyleUrl ) => setMapLibreStyle (newStyleUrl))
55- function setMapLibreStyle (styleUrl ) {
56- if (! layer? .maplibreMap ) {
57- log .error (' MapLibre instance is not attached to the layer' )
58- return
59- }
60- // most of this methods will be edited while doing https://jira.swisstopo.ch/browse/BGDIINF_SB-2741
61- if (layerId .value === VECTOR_TILES_IMAGERY_STYLE_ID ) {
62- // special case here, as the imagery is only over Switzerland (for now)
63- // we inject a fair-use WMTS that covers the globe under our aerial images
64- axios
65- .get (styleUrl)
66- .then ((response ) => {
67- const vectorStyle = response .data
68- // settings SwissImage to use the tiled WMS instead
69- // otherwise it covers the whole world with white tiles (when no data is present)
70- vectorStyle .sources .swissimage_wmts .tiles = [
71- ' https://wms.geo.admin.ch/?SERVICE=WMS&VERSION=1.3.0&REQUEST=GetMap&FORMAT=image%2Fpng&TRANSPARENT=true&LAYERS=ch.swisstopo.swissimage&LANG=en&WIDTH=256&HEIGHT=256&CRS=EPSG%3A3857&STYLES=&BBOX={bbox-epsg-3857}' ,
72- ]
73- // setting up Sentinel2 WMTS to cover the globe outside of Switzerland
74- vectorStyle .sources [' sentinel2_wmts' ] = {
75- minzoom: 0 ,
76- maxzoom: 22 ,
77- tileSize: 256 ,
78- type: ' raster' ,
79- tiles: [
80- ' https://tiles.maps.eox.at/wmts?layer=s2cloudless-2020_3857&style=default&tilematrixset=g&Service=WMTS&Request=GetTile&Version=1.0.0&Format=image%2Fjpeg&TileMatrix={z}&TileCol={x}&TileRow={y}' ,
81- ],
82- }
83- vectorStyle .layers .splice (1 , 0 , {
84- id: ' sentinel2' ,
85- source: ' sentinel2_wmts' ,
86- type: ' raster' ,
87- })
88- layer .maplibreMap .setStyle (vectorStyle)
89- })
90- .catch ((err ) => {
91- log .error (' Error while fetching MapLibre style' , styleUrl, err)
92- })
93- } else {
94- layer .maplibreMap .setStyle (styleUrl)
95- }
96- }
56+ watch (styleUrl, (newStyleUrl ) => layer .mapLibreMap ? .setStyle (newStyleUrl))
9757< / script>
9858
9959< template>
0 commit comments