From f0c83e5540396fd11437ad8e4c449c77fd57b92b Mon Sep 17 00:00:00 2001 From: Dan Leech Date: Fri, 11 Sep 2026 15:56:39 +0100 Subject: [PATCH] snapEngine missing test coverage added --- .../adapters/openlayers/snap/snapEngine.test.js | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/plugins/draw/src/adapters/openlayers/snap/snapEngine.test.js b/plugins/draw/src/adapters/openlayers/snap/snapEngine.test.js index ba6a52ca..98358b12 100644 --- a/plugins/draw/src/adapters/openlayers/snap/snapEngine.test.js +++ b/plugins/draw/src/adapters/openlayers/snap/snapEngine.test.js @@ -1,6 +1,7 @@ import VectorLayer from 'ol/layer/Vector.js' import VectorTileLayer from 'ol/layer/VectorTile.js' import VectorSource from 'ol/source/Vector.js' +import { Projection, addProjection, addCoordinateTransforms } from 'ol/proj.js' import { createSnapEngine } from './snapEngine.js' import { polygonFeature } from '../__helpers__/harness.js' @@ -177,6 +178,22 @@ describe('vector-tile layers', () => { map.layers.unshift(new VectorLayer({})) // a non-tile layer sits in the stack expect(engine.query([600, 2005], 12)).toEqual({ type: 'edge', coord: [600, 2000] }) }) + + test('reprojects the query coordinate when the tile source has a genuinely different projection', () => { + // Real ol/proj Projection objects (not the bare code strings the other tests use), with + // different codes and an identity transform between them, so toSource actually calls + // transform() instead of short-circuiting, while leaving the mocked tileGrid's numbers valid. + const viewProj = new Projection({ code: 'x-test-view', units: 'm' }) + const sourceProj = new Projection({ code: 'x-test-source', units: 'm' }) + addProjection(viewProj) + addProjection(sourceProj) + addCoordinateTransforms(viewProj, sourceProj, (c) => c, (c) => c) + + const { engine, map } = setupVT({ features: [renderFeature('LineString', [500, 2000, 1500, 2000])] }) + map.getView = () => ({ getResolution: () => 1, getProjection: () => viewProj }) + map.layers[0].getSource().getProjection = () => sourceProj + expect(engine.query([600, 2005], 12)).toEqual({ type: 'edge', coord: [600, 2000] }) + }) }) describe('invisible shared fill boundaries', () => {