@@ -26,22 +26,39 @@ export default function Editor({ setDisable, comment, presets, imagery, gpxUrl,
2626 setCustomImageryIsSet ( true ) ;
2727 // this line is needed to update the value on the custom background dialog
2828 window . iD . prefs ( 'background-custom-template' , imagery ) ;
29- // this line is needed to keep the extraIdParams when custom imagery is set
30- if ( extraIdParams ) {
31- const params = new URLSearchParams ( extraIdParams ) ;
32- const offsetStr = params . get ( 'offset' ) ; // "10,-10"
33- if ( ! offsetStr ) return ;
34- const offsetInMeters = offsetStr . split ( ',' ) . map ( Number ) ; // [10, -10]
35- const offset = window . iD . geoMetersToOffset ( offsetInMeters ) ;
36- iDContext . background ( ) . offset ( offset ) ;
37- }
3829 } else {
3930 const imagerySource = iDContext . background ( ) . findSource ( imagery ) ;
4031 if ( imagerySource ) {
4132 iDContext . background ( ) . baseLayerSource ( imagerySource ) ;
4233 }
4334 }
4435 }
36+
37+ // wait till iDContext loads background
38+ if ( ! iDContext ?. background ( ) ) return ;
39+
40+ // this fixes the custom imagery persisting from previous load
41+ // when no imagery is selected in project setting
42+ if ( ! imagery ) {
43+ // set Bing as default
44+ const imagerySource = iDContext . background ( ) . findSource ( 'Bing' ) ;
45+ if ( ! imagerySource ) return ;
46+ iDContext . background ( ) . baseLayerSource ( imagerySource ) ;
47+ }
48+
49+ // this sets imagery offset from extraIdParams if present
50+ if ( extraIdParams ) {
51+ const params = new URLSearchParams ( extraIdParams ) ;
52+ const offsetStr = params . get ( 'offset' ) ; // "10,-10"
53+ if ( ! offsetStr ) return ;
54+ const offsetInMeters = offsetStr . split ( ',' ) . map ( Number ) ; // [10, -10]
55+ const offset = window . iD . geoMetersToOffset ( offsetInMeters ) ;
56+ iDContext . background ( ) . offset ( offset ) ;
57+ } else {
58+ // reset offset if params not present
59+ // this is needed to fix the offset persisting from previous project issue
60+ iDContext . background ( ) . offset ( [ 0 , 0 ] ) ;
61+ }
4562 } , [ customImageryIsSet , imagery , iDContext , customSource , extraIdParams ] ) ;
4663
4764 useEffect ( ( ) => {
0 commit comments