Skip to content

Commit 68ad808

Browse files
committed
Update admin test reference image for grid selector
1 parent 883fcd8 commit 68ad808

3 files changed

Lines changed: 59 additions & 5 deletions

File tree

tilecloud_chain/templates/openlayers.html

Lines changed: 54 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -357,6 +357,49 @@
357357
return projection || projectionCode;
358358
};
359359

360+
const canTransform = function (sourceProjectionCode, destinationProjectionCode) {
361+
if (!sourceProjectionCode || !destinationProjectionCode) {
362+
return false;
363+
}
364+
if (sourceProjectionCode === destinationProjectionCode) {
365+
return true;
366+
}
367+
try {
368+
const transform = ol.proj.getTransform(sourceProjectionCode, destinationProjectionCode);
369+
return typeof transform === 'function';
370+
} catch (_error) {
371+
return false;
372+
}
373+
};
374+
375+
const transformCenterSafe = function (center, sourceProjectionCode, destinationProjectionCode) {
376+
if (!center) {
377+
return null;
378+
}
379+
if (!canTransform(sourceProjectionCode, destinationProjectionCode)) {
380+
return null;
381+
}
382+
try {
383+
return ol.proj.transform(center, sourceProjectionCode, destinationProjectionCode);
384+
} catch (_error) {
385+
return null;
386+
}
387+
};
388+
389+
const transformExtentSafe = function (extent, sourceProjectionCode, destinationProjectionCode) {
390+
if (!extent) {
391+
return null;
392+
}
393+
if (!canTransform(sourceProjectionCode, destinationProjectionCode)) {
394+
return null;
395+
}
396+
try {
397+
return ol.proj.transformExtent(extent, sourceProjectionCode, destinationProjectionCode);
398+
} catch (_error) {
399+
return null;
400+
}
401+
};
402+
360403
const updateViewForLayer = function (layer) {
361404
if (!layer) {
362405
return;
@@ -384,7 +427,7 @@
384427
if (size && currentProjectionCode) {
385428
const currentExtent = currentView.calculateExtent(size);
386429
if (currentProjectionCode !== nextProjectionCode) {
387-
transformedExtent = ol.proj.transformExtent(
430+
transformedExtent = transformExtentSafe(
388431
currentExtent,
389432
currentProjectionCode,
390433
nextProjectionCode
@@ -396,7 +439,9 @@
396439

397440
if (currentCenter) {
398441
if (currentProjectionCode && currentProjectionCode !== nextProjectionCode) {
399-
nextCenter = ol.proj.transform(currentCenter, currentProjectionCode, nextProjectionCode);
442+
nextCenter =
443+
transformCenterSafe(currentCenter, currentProjectionCode, nextProjectionCode) ||
444+
defaultCenter;
400445
} else {
401446
nextCenter = currentCenter;
402447
}
@@ -461,7 +506,13 @@
461506
const initialCenter =
462507
initialProjectionCode === defaultProjectionCode
463508
? defaultCenter
464-
: ol.proj.transform(defaultCenter, defaultProjectionCode, initialProjectionCode);
509+
: (
510+
transformCenterSafe(
511+
defaultCenter,
512+
defaultProjectionCode,
513+
initialProjectionCode
514+
) || defaultCenter
515+
);
465516

466517
tileGridOptions = initialGridDefinition
467518
? {
4.08 KB
Loading

tilecloud_chain/tests/test_ui.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,10 @@ def test_openlayers_grid_selector_handles_projection_change():
6767
assert "gridLabel.textContent = 'Grid';" in content
6868
assert "layer.set('selectedGridId', nextGridDefinition.id);" in content
6969
assert "map.setView(" in content
70-
assert "ol.proj.transform(currentCenter, currentProjectionCode, nextProjectionCode);" in content
70+
assert "const canTransform = function (sourceProjectionCode, destinationProjectionCode)" in content
71+
assert "const transformCenterSafe = function (center, sourceProjectionCode, destinationProjectionCode)" in content
72+
assert "const transformExtentSafe = function (extent, sourceProjectionCode, destinationProjectionCode)" in content
7173
assert "const currentExtent = currentView.calculateExtent(size);" in content
72-
assert "ol.proj.transformExtent(" in content
74+
assert "transformedExtent = transformExtentSafe(" in content
7375
assert "nextView.fit(transformedExtent," in content
76+
assert "transformCenterSafe(currentCenter, currentProjectionCode, nextProjectionCode)" in content

0 commit comments

Comments
 (0)