@defra/interactive-map 0.0.47-alpha → 0.0.48-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.
@@ -25,7 +25,14 @@ const buildTileBoundaryState = (layer, map) => {
25
25
  const getClipContext = (state, coord) => {
26
26
  if (!state) { return null }
27
27
  const { tileGrid, viewProj, sourceProj, zoom } = state
28
- const toSource = (c) => c ? projTransform(c, viewProj, sourceProj) : null
28
+ // Same-code projections need no reprojection skipping the call also avoids depending
29
+ // on ol/proj's registry having a transform for the pair, which can be missing when the
30
+ // draw plugin and the map provider ship as separate bundles each with their own ol/proj4.
31
+ const codeOf = (projection) => (typeof projection === 'string' ? projection : projection.getCode())
32
+ const toSource = (coordinate) => {
33
+ if (!coordinate) { return null }
34
+ return codeOf(sourceProj) === codeOf(viewProj) ? coordinate : projTransform(coordinate, viewProj, sourceProj)
35
+ }
29
36
  const anchor = toSource(coord)
30
37
  const tileCoord = tileGrid.getTileCoordForCoordAndZ(anchor, zoom)
31
38
  const extent = tileGrid.getTileCoordExtent(tileCoord)
@@ -1,6 +1,7 @@
1
1
  import VectorLayer from 'ol/layer/Vector.js'
2
2
  import VectorTileLayer from 'ol/layer/VectorTile.js'
3
3
  import VectorSource from 'ol/source/Vector.js'
4
+ import { Projection, addProjection, addCoordinateTransforms } from 'ol/proj.js'
4
5
  import { createSnapEngine } from './snapEngine.js'
5
6
  import { polygonFeature } from '../__helpers__/harness.js'
6
7
 
@@ -177,6 +178,22 @@ describe('vector-tile layers', () => {
177
178
  map.layers.unshift(new VectorLayer({})) // a non-tile layer sits in the stack
178
179
  expect(engine.query([600, 2005], 12)).toEqual({ type: 'edge', coord: [600, 2000] })
179
180
  })
181
+
182
+ test('reprojects the query coordinate when the tile source has a genuinely different projection', () => {
183
+ // Real ol/proj Projection objects (not the bare code strings the other tests use), with
184
+ // different codes and an identity transform between them, so toSource actually calls
185
+ // transform() instead of short-circuiting, while leaving the mocked tileGrid's numbers valid.
186
+ const viewProj = new Projection({ code: 'x-test-view', units: 'm' })
187
+ const sourceProj = new Projection({ code: 'x-test-source', units: 'm' })
188
+ addProjection(viewProj)
189
+ addProjection(sourceProj)
190
+ addCoordinateTransforms(viewProj, sourceProj, (c) => c, (c) => c)
191
+
192
+ const { engine, map } = setupVT({ features: [renderFeature('LineString', [500, 2000, 1500, 2000])] })
193
+ map.getView = () => ({ getResolution: () => 1, getProjection: () => viewProj })
194
+ map.layers[0].getSource().getProjection = () => sourceProj
195
+ expect(engine.query([600, 2005], 12)).toEqual({ type: 'edge', coord: [600, 2000] })
196
+ })
180
197
  })
181
198
 
182
199
  describe('invisible shared fill boundaries', () => {