|
|
@@ -34,6 +34,22 @@ export function getGisWmtsLayer() {
|
|
34
|
34
|
return (import.meta.env.VITE_GIS_WMTS_LAYER || '').trim()
|
|
35
|
35
|
}
|
|
36
|
36
|
|
|
|
37
|
+/** 高 zoom 时切换的 WMTS 图层,如 baqing_wp2 */
|
|
|
38
|
+export function getGisWmtsLayer2() {
|
|
|
39
|
+ return (import.meta.env.VITE_GIS_WMTS_LAYER2 || '').trim()
|
|
|
40
|
+}
|
|
|
41
|
+
|
|
|
42
|
+/** zoom 大于该值时叠加显示 VITE_GIS_WMTS_LAYER2(wp 始终保留在底层) */
|
|
|
43
|
+export function getGisWmtsLayerSwitchZoom() {
|
|
|
44
|
+ const z = Number(import.meta.env.VITE_GIS_WMTS_LAYER_SWITCH_ZOOM)
|
|
|
45
|
+ return Number.isFinite(z) ? z : 16
|
|
|
46
|
+}
|
|
|
47
|
+
|
|
|
48
|
+export const GIS_WMTS_LAYER_IDS = {
|
|
|
49
|
+ primary: 'gis-wmts-layer',
|
|
|
50
|
+ secondary: 'gis-wmts-layer-2'
|
|
|
51
|
+}
|
|
|
52
|
+
|
|
37
|
53
|
/** 瓦片边长(256 或 512);512 时向 WMTS 追加 WIDTH/HEIGHT 请求高清瓦片 */
|
|
38
|
54
|
export function getGisTileSize() {
|
|
39
|
55
|
const n = Number(import.meta.env.VITE_GIS_TILE_SIZE)
|
|
|
@@ -54,16 +70,15 @@ function getGisWmtsZoomOffset() {
|
|
54
|
70
|
return Number.isFinite(n) ? n : 0
|
|
55
|
71
|
}
|
|
56
|
72
|
|
|
57
|
|
-function buildWmtsTileUrl() {
|
|
|
73
|
+function buildWmtsTileUrlForLayer(layerName) {
|
|
58
|
74
|
const base = getGisBaseUrl()
|
|
59
|
|
- const layer = getGisWmtsLayer()
|
|
60
|
75
|
const key = getGisAccessToken()
|
|
61
|
76
|
const tileSize = getGisTileSize()
|
|
62
|
77
|
const matrix = getGisWmtsTileMatrixTemplate()
|
|
63
|
78
|
const matrixSet = encodeURIComponent(getGisWmtsTileMatrixSet())
|
|
64
|
79
|
let url =
|
|
65
|
80
|
`${base}/agis/maps/v1/wmts` +
|
|
66
|
|
- `?LAYER=${encodeURIComponent(layer)}` +
|
|
|
81
|
+ `?LAYER=${encodeURIComponent(layerName)}` +
|
|
67
|
82
|
'&SERVICE=WMTS&REQUEST=GetTile' +
|
|
68
|
83
|
`&TileMatrix=${matrix}` +
|
|
69
|
84
|
'&TileCol={x}&TileRow={y}' +
|
|
|
@@ -76,6 +91,34 @@ function buildWmtsTileUrl() {
|
|
76
|
91
|
return url
|
|
77
|
92
|
}
|
|
78
|
93
|
|
|
|
94
|
+function buildWmtsRasterSource(layerName) {
|
|
|
95
|
+ return {
|
|
|
96
|
+ type: 'raster',
|
|
|
97
|
+ tiles: [buildWmtsTileUrlForLayer(layerName)],
|
|
|
98
|
+ tileSize: getGisTileSize(),
|
|
|
99
|
+ scheme: 'xyz',
|
|
|
100
|
+ minzoom: getGisMinZoom(),
|
|
|
101
|
+ maxzoom: getGisTileMaxZoom()
|
|
|
102
|
+ }
|
|
|
103
|
+}
|
|
|
104
|
+
|
|
|
105
|
+function buildWmtsRasterLayer(id, sourceId, visible = true) {
|
|
|
106
|
+ return {
|
|
|
107
|
+ id,
|
|
|
108
|
+ type: 'raster',
|
|
|
109
|
+ source: sourceId,
|
|
|
110
|
+ layout: {
|
|
|
111
|
+ visibility: visible ? 'visible' : 'none'
|
|
|
112
|
+ },
|
|
|
113
|
+ minzoom: getGisMinZoom(),
|
|
|
114
|
+ maxzoom: 24,
|
|
|
115
|
+ paint: {
|
|
|
116
|
+ 'raster-fade-duration': 300,
|
|
|
117
|
+ 'raster-resampling': 'linear'
|
|
|
118
|
+ }
|
|
|
119
|
+ }
|
|
|
120
|
+}
|
|
|
121
|
+
|
|
79
|
122
|
/**
|
|
80
|
123
|
* 瓦片请求改写:仅处理 zoom 偏移。
|
|
81
|
124
|
* TileMatrix 上限由 style 里 source.maxzoom 控制,勿在此改写 col/row,否则易与引擎缓存键不一致导致 canceled。
|
|
|
@@ -97,49 +140,64 @@ export function createGisTransformRequest() {
|
|
97
|
140
|
}
|
|
98
|
141
|
}
|
|
99
|
142
|
|
|
100
|
|
-/** 由 WMTS GetTile 模板生成 Mapbox Style(raster 源) */
|
|
|
143
|
+/** 由 WMTS GetTile 模板生成 Mapbox Style(raster 源;可选双图层) */
|
|
101
|
144
|
export function buildWmtsMapStyle() {
|
|
102
|
145
|
const base = getGisBaseUrl()
|
|
103
|
146
|
const layer = getGisWmtsLayer()
|
|
|
147
|
+ const layer2 = getGisWmtsLayer2()
|
|
104
|
148
|
const key = getGisAccessToken()
|
|
105
|
149
|
if (!base || !layer || !key) {
|
|
106
|
150
|
return null
|
|
107
|
151
|
}
|
|
108
|
|
- const tileSize = getGisTileSize()
|
|
109
|
|
- const tileUrl = buildWmtsTileUrl()
|
|
110
|
|
- return {
|
|
111
|
|
- version: 8,
|
|
112
|
|
- sources: {
|
|
113
|
|
- 'gis-wmts': {
|
|
114
|
|
- type: 'raster',
|
|
115
|
|
- tiles: [tileUrl],
|
|
116
|
|
- tileSize,
|
|
117
|
|
- scheme: 'xyz',
|
|
118
|
|
- minzoom: getGisMinZoom(),
|
|
119
|
|
- maxzoom: getGisTileMaxZoom()
|
|
|
152
|
+
|
|
|
153
|
+ const sources = {
|
|
|
154
|
+ 'gis-wmts': buildWmtsRasterSource(layer)
|
|
|
155
|
+ }
|
|
|
156
|
+ const layers = [
|
|
|
157
|
+ {
|
|
|
158
|
+ id: 'gis-bg',
|
|
|
159
|
+ type: 'background',
|
|
|
160
|
+ paint: {
|
|
|
161
|
+ 'background-color': '#1a3a32'
|
|
120
|
162
|
}
|
|
121
|
163
|
},
|
|
122
|
|
- layers: [
|
|
123
|
|
- {
|
|
124
|
|
- id: 'gis-bg',
|
|
125
|
|
- type: 'background',
|
|
126
|
|
- paint: {
|
|
127
|
|
- 'background-color': '#1a3a32'
|
|
128
|
|
- }
|
|
129
|
|
- },
|
|
130
|
|
- {
|
|
131
|
|
- id: 'gis-wmts-layer',
|
|
132
|
|
- type: 'raster',
|
|
133
|
|
- source: 'gis-wmts',
|
|
134
|
|
- minzoom: getGisMinZoom(),
|
|
135
|
|
- // 勿与 VITE_GIS_MAX_ZOOM 绑死:zoom 略大于 max 时(easeTo 过冲)图层会被引擎整层隐藏
|
|
136
|
|
- maxzoom: 24,
|
|
137
|
|
- paint: {
|
|
138
|
|
- 'raster-fade-duration': 300,
|
|
139
|
|
- 'raster-resampling': 'linear'
|
|
140
|
|
- }
|
|
141
|
|
- }
|
|
142
|
|
- ]
|
|
|
164
|
+ buildWmtsRasterLayer(GIS_WMTS_LAYER_IDS.primary, 'gis-wmts', true)
|
|
|
165
|
+ ]
|
|
|
166
|
+
|
|
|
167
|
+ if (layer2) {
|
|
|
168
|
+ sources['gis-wmts-2'] = buildWmtsRasterSource(layer2)
|
|
|
169
|
+ layers.push(buildWmtsRasterLayer(GIS_WMTS_LAYER_IDS.secondary, 'gis-wmts-2', false))
|
|
|
170
|
+ }
|
|
|
171
|
+
|
|
|
172
|
+ return {
|
|
|
173
|
+ version: 8,
|
|
|
174
|
+ sources,
|
|
|
175
|
+ layers
|
|
|
176
|
+ }
|
|
|
177
|
+}
|
|
|
178
|
+
|
|
|
179
|
+/** 根据 zoom 控制 wp2 叠加层显隐:wp 始终在底层,zoom > 16 时 wp2 叠在上方 */
|
|
|
180
|
+export function syncWmtsLayerVisibility(map) {
|
|
|
181
|
+ if (!map || typeof map.getZoom !== 'function') {
|
|
|
182
|
+ return
|
|
|
183
|
+ }
|
|
|
184
|
+ const layer2 = getGisWmtsLayer2()
|
|
|
185
|
+ if (!layer2 || typeof map.getLayer !== 'function') {
|
|
|
186
|
+ return
|
|
|
187
|
+ }
|
|
|
188
|
+ if (!map.getLayer(GIS_WMTS_LAYER_IDS.secondary)) {
|
|
|
189
|
+ return
|
|
|
190
|
+ }
|
|
|
191
|
+
|
|
|
192
|
+ const z = map.getZoom()
|
|
|
193
|
+ const showOverlay = Number.isFinite(z) && z > getGisWmtsLayerSwitchZoom()
|
|
|
194
|
+
|
|
|
195
|
+ if (typeof map.setLayoutProperty === 'function') {
|
|
|
196
|
+ map.setLayoutProperty(
|
|
|
197
|
+ GIS_WMTS_LAYER_IDS.secondary,
|
|
|
198
|
+ 'visibility',
|
|
|
199
|
+ showOverlay ? 'visible' : 'none'
|
|
|
200
|
+ )
|
|
143
|
201
|
}
|
|
144
|
202
|
}
|
|
145
|
203
|
|