@@ -8,7 +8,7 @@ import '@hotosm/id/dist/iD.css';
88import { OSM_CLIENT_ID , OSM_REDIRECT_URI , OSM_SERVER_URL } from '../config' ;
99import messages from './messages' ;
1010
11- export default function Editor ( { setDisable, comment, presets, imagery, gpxUrl } ) {
11+ export default function Editor ( { setDisable, comment, presets, imagery, gpxUrl, extraIdParams } ) {
1212 const dispatch = useDispatch ( ) ;
1313 const intl = useIntl ( ) ;
1414 const session = useSelector ( ( state ) => state . auth . session ) ;
@@ -33,7 +33,33 @@ export default function Editor({ setDisable, comment, presets, imagery, gpxUrl }
3333 }
3434 }
3535 }
36- } , [ customImageryIsSet , imagery , iDContext , customSource ] ) ;
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+ }
62+ } , [ customImageryIsSet , imagery , iDContext , customSource , extraIdParams ] ) ;
3763
3864 useEffect ( ( ) => {
3965 if ( windowInit ) {
0 commit comments