Skip to content

Commit 5056fae

Browse files
authored
Merge pull request #813 from SlideRuleEarth/carlos-dev4
There is an offset sometimes when viewing polys from the request page…
2 parents 57da49f + 8c552b1 commit 5056fae

File tree

2 files changed

+23
-4
lines changed

2 files changed

+23
-4
lines changed

web-client/src/components/SrMap.vue

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -490,13 +490,16 @@ drawPolygon.on('drawend', function (event) {
490490
//console.log("Original polyCoords:", rings);
491491
492492
const projName = useMapStore().getSrViewObj().projectionName
493+
const mapViewProjection = mapRef.value?.map.getView().getProjection().getCode()
493494
let thisProj = getProjection(projName)
495+
494496
let flatLonLatPairs
495497
if (thisProj?.getUnits() !== 'degrees') {
496-
//Convert each ring's coordinates to lon/lat using toLonLat
498+
//Convert each ring's coordinates to lon/lat using toLonLat with EXPLICIT projection
497499
const convertedRings: Coordinate[][] = rings.map((ring: Coordinate[]) =>
498-
ring.map((coord) => toLonLat(coord) as Coordinate)
500+
ring.map((coord) => toLonLat(coord, mapViewProjection) as Coordinate)
499501
)
502+
500503
//console.log("Converted polyCoords:", convertedRings);
501504
mapStore.polyCoords = convertedRings
502505
flatLonLatPairs = convertedRings.flatMap((ring) => ring)
@@ -508,6 +511,7 @@ drawPolygon.on('drawend', function (event) {
508511
lon: coord[0],
509512
lat: coord[1]
510513
}))
514+
511515
if (isClockwise(srLonLatCoordinates)) {
512516
//console.log('poly is clockwise, reversing');
513517
reqParamsStore.setPoly(srLonLatCoordinates.reverse())
@@ -826,6 +830,11 @@ onMounted(async () => {
826830
})
827831
//console.log("SrMap onMounted registering proj4:",proj4);
828832
register(proj4 as any)
833+
834+
// Clear the global drawVectorSource when component mounts to prevent stale features
835+
// from previous navigation sessions from appearing with incorrect coordinates
836+
drawVectorSource.clear()
837+
829838
if (mapRef.value?.map) {
830839
//console.log("SrMap onMounted map:",mapRef.value.map);
831840
mapStore.setMap(mapRef.value.map)
@@ -942,8 +951,15 @@ onMounted(async () => {
942951
//dumpMapLayers(map, 'SrMap onMounted');
943952
// Note: addRecordLayer() is now handled by watch on isTreeLoaded + allReqIds with immediate:true
944953
if (haveReqPoly || haveReqPin) {
945-
//draw and zoom to the current reqParamsStore.poly
954+
// CRITICAL FIX: Delay drawing until after OpenLayers has rendered the updated view
955+
// OpenLayers rendering is asynchronous - it schedules renders on animation frames.
956+
// If we draw immediately after updateReqMapView, features may be rendered with
957+
// stale view transforms, causing visual offset even though coordinates are correct.
958+
// requestAnimationFrame(() => {
959+
// //draw and zoom to the current reqParamsStore.poly
960+
// logger.debug('Drawing polygon after requestAnimationFrame')
946961
drawCurrentReqPolyAndPin()
962+
//})
947963
}
948964
} else {
949965
logger.error('mapRef.value?.map is null in onMounted')

web-client/src/composables/SrProjections.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,10 @@ export const srProjections = ref<{ [key: string]: SrProjection }>({
2626
default_zoom: 2,
2727
min_zoom: 0,
2828
max_zoom: 19,
29-
bbox: [-180.0, -85.06, 180.0, 85.06]
29+
bbox: [-180.0, -85.06, 180.0, 85.06],
30+
// CRITICAL: Define extent explicitly to prevent applyTransform from using tainted projection state
31+
// Web Mercator extent must be symmetric for correct coordinate transformations
32+
extent: [-20037508.342789244, -20037508.342789244, 20037508.342789244, 20037508.342789244]
3033
},
3134
'EPSG:4326': {
3235
// Web Mercator -- This is the 'standard' projection for web maps (coordinate units in lon lat)

0 commit comments

Comments
 (0)