@defra/interactive-map 0.0.46-fmp-2 → 0.0.47-alpha
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/docs/api/map-style-config.md +22 -1
- package/package.json +1 -1
- package/providers/beta/openlayers/dist/esm/im-openlayers-provider.js +1 -1
- package/providers/beta/openlayers/dist/umd/im-openlayers-provider.js +1 -1
- package/providers/beta/openlayers/src/utils/tileLayers.js +12 -7
- package/providers/beta/openlayers/src/utils/tileLayers.test.js +26 -0
- package/src/types.js +9 -0
|
@@ -15,7 +15,7 @@ import { TILE_GRID_RESOLUTIONS, TILE_GRID_ORIGIN, TILE_SIZE } from '../defaults.
|
|
|
15
15
|
recordStyleLayer(true)
|
|
16
16
|
|
|
17
17
|
const CRS = 'EPSG:27700'
|
|
18
|
-
const SUPPORTED_MAP_STYLE_TYPES = ['vector', 'raster', 'wms', 'ogc-vt']
|
|
18
|
+
const SUPPORTED_MAP_STYLE_TYPES = new Set(['vector', 'raster', 'wms', 'ogc-vt'])
|
|
19
19
|
|
|
20
20
|
export function fetchWithTransform (url, resourceType, transformRequest) {
|
|
21
21
|
const result = transformRequest ? (transformRequest(url, resourceType) || {}) : {}
|
|
@@ -32,11 +32,12 @@ const createTileLoadFunction = (transformRequest) => (tile, src) => {
|
|
|
32
32
|
.catch(() => tile.setState(TileState.ERROR))
|
|
33
33
|
}
|
|
34
34
|
|
|
35
|
-
function createTileGrid () {
|
|
35
|
+
function createTileGrid (extent) {
|
|
36
36
|
return new TileGrid({
|
|
37
37
|
resolutions: TILE_GRID_RESOLUTIONS,
|
|
38
38
|
origin: TILE_GRID_ORIGIN,
|
|
39
|
-
tileSize: TILE_SIZE
|
|
39
|
+
tileSize: TILE_SIZE,
|
|
40
|
+
...(extent && { extent })
|
|
40
41
|
})
|
|
41
42
|
}
|
|
42
43
|
|
|
@@ -52,8 +53,12 @@ export function createWMSTileSource (url, params, transformRequest) {
|
|
|
52
53
|
})
|
|
53
54
|
}
|
|
54
55
|
|
|
55
|
-
|
|
56
|
-
|
|
56
|
+
// `extent` has no discovery protocol to fetch it from for a bare XYZ template — unlike the
|
|
57
|
+
// other map style types, only the consumer configuring this particular tile service can supply
|
|
58
|
+
// it, via `mapStyle.extent` ([minX, minY, maxX, maxY] in EPSG:27700). Omitted → no extent, same
|
|
59
|
+
// as before: OL requests tiles for the whole tile grid regardless of real coverage.
|
|
60
|
+
export function createTileSource (url, transformRequest, extent) {
|
|
61
|
+
const tileGrid = createTileGrid(extent)
|
|
57
62
|
|
|
58
63
|
const tileUrlFunction = ([z, x, y]) => url
|
|
59
64
|
.replace('{z}', z)
|
|
@@ -69,7 +74,7 @@ export function createTileSource (url, transformRequest) {
|
|
|
69
74
|
}
|
|
70
75
|
|
|
71
76
|
export async function createMapStyleLayer (mapStyle, transformRequest) {
|
|
72
|
-
if (mapStyle.type && !SUPPORTED_MAP_STYLE_TYPES.
|
|
77
|
+
if (mapStyle.type && !SUPPORTED_MAP_STYLE_TYPES.has(mapStyle.type)) {
|
|
73
78
|
throw new Error(`Unsupported map style type: '${mapStyle.type}'`)
|
|
74
79
|
}
|
|
75
80
|
|
|
@@ -79,7 +84,7 @@ export async function createMapStyleLayer (mapStyle, transformRequest) {
|
|
|
79
84
|
}
|
|
80
85
|
|
|
81
86
|
if (mapStyle.type === 'raster') {
|
|
82
|
-
const source = createTileSource(mapStyle.url, transformRequest)
|
|
87
|
+
const source = createTileSource(mapStyle.url, transformRequest, mapStyle.extent)
|
|
83
88
|
return { layer: new TileLayer({ source }), source }
|
|
84
89
|
}
|
|
85
90
|
|
|
@@ -127,6 +127,26 @@ describe('createTileSource', () => {
|
|
|
127
127
|
const { tileLoadFunction } = XYZ.mock.calls[0][0]
|
|
128
128
|
expect(typeof tileLoadFunction).toBe('function')
|
|
129
129
|
})
|
|
130
|
+
|
|
131
|
+
it('does not set a TileGrid extent when none is given, so tiles across the whole grid can be requested', () => {
|
|
132
|
+
createTileSource('https://tiles.example.com/{z}/{x}/{y}', null)
|
|
133
|
+
expect(TileGrid).toHaveBeenCalledWith({
|
|
134
|
+
resolutions: TILE_GRID_RESOLUTIONS,
|
|
135
|
+
origin: TILE_GRID_ORIGIN,
|
|
136
|
+
tileSize: TILE_SIZE
|
|
137
|
+
})
|
|
138
|
+
})
|
|
139
|
+
|
|
140
|
+
it('passes a given extent through to the TileGrid, so out-of-coverage tiles are never requested', () => {
|
|
141
|
+
const extent = [0, 0, 700000, 1300000]
|
|
142
|
+
createTileSource('https://tiles.example.com/{z}/{x}/{y}', null, extent)
|
|
143
|
+
expect(TileGrid).toHaveBeenCalledWith({
|
|
144
|
+
resolutions: TILE_GRID_RESOLUTIONS,
|
|
145
|
+
origin: TILE_GRID_ORIGIN,
|
|
146
|
+
tileSize: TILE_SIZE,
|
|
147
|
+
extent
|
|
148
|
+
})
|
|
149
|
+
})
|
|
130
150
|
})
|
|
131
151
|
|
|
132
152
|
describe('createWMSTileSource', () => {
|
|
@@ -244,6 +264,12 @@ describe('createMapStyleLayer', () => {
|
|
|
244
264
|
expect(result).toEqual({ layer: mockTileLayerInstance, source: mockSourceInstance })
|
|
245
265
|
})
|
|
246
266
|
|
|
267
|
+
it('passes mapStyle.extent through to the raster TileGrid', async () => {
|
|
268
|
+
const extent = [-233752.41, -4325.11, 609472.1, 1278448.84]
|
|
269
|
+
await createMapStyleLayer({ url: 'https://tiles.example.com/{z}/{x}/{y}', type: 'raster', extent }, null)
|
|
270
|
+
expect(TileGrid).toHaveBeenCalledWith(expect.objectContaining({ extent }))
|
|
271
|
+
})
|
|
272
|
+
|
|
247
273
|
it('creates an OGC vector tile layer and source when mapStyle.type is ogc-vt', async () => {
|
|
248
274
|
global.fetch = makeOGCFetchMock()
|
|
249
275
|
const result = await createMapStyleLayer({ url: 'https://example.com/ogc-styles', type: 'ogc-vt' }, null)
|
package/src/types.js
CHANGED
|
@@ -462,6 +462,15 @@
|
|
|
462
462
|
* @property {Object} [params]
|
|
463
463
|
* WMS request parameters. Passed directly to the OpenLayers `TileWMS` source when `type` is `'wms'`.
|
|
464
464
|
* Most WMS GetMap requests should include `LAYERS`. Example: `{ LAYERS: 'MyLayer', FORMAT: 'image/jpeg' }`.
|
|
465
|
+
*
|
|
466
|
+
* @property {[number, number, number, number]} [extent]
|
|
467
|
+
* Bounding box [minX, minY, maxX, maxY] in EPSG:27700, the units the OpenLayers provider's
|
|
468
|
+
* tile grid is built in. When set, no tiles outside this area are requested — a plain XYZ tile
|
|
469
|
+
* URL template has no capabilities document to determine real coverage from, so the consumer
|
|
470
|
+
* configuring the style must supply it directly. **Currently only supported by the OpenLayers
|
|
471
|
+
* provider's `'raster'` type.** Omit to request tiles across the whole tile grid regardless of
|
|
472
|
+
* real coverage. Panning/zooming outside the extent is unaffected;
|
|
473
|
+
* only tile requests are limited.
|
|
465
474
|
*/
|
|
466
475
|
|
|
467
476
|
/**
|