@@ -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' )
0 commit comments