Skip to content

Commit f36f5db

Browse files
Merge pull request #6950 from hotosm/fix/6676-additional-id-url-param-issue
Fix extra iD URL parameter `offset` not working for custom imagery issue
2 parents 503780b + c9b7e5d commit f36f5db

File tree

2 files changed

+29
-2
lines changed

2 files changed

+29
-2
lines changed

frontend/src/components/editor.js

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import '@hotosm/id/dist/iD.css';
88
import { OSM_CLIENT_ID, OSM_REDIRECT_URI, OSM_SERVER_URL } from '../config';
99
import 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) {

frontend/src/components/taskSelection/action.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,7 @@ export function TaskMapAction({ project, tasks, activeTasks, getTasks, action, e
225225
setDisable={setDisable}
226226
comment={project.changesetComment}
227227
presets={project.idPresets}
228+
extraIdParams={project.extraIdParams}
228229
imagery={formatImageryUrlCallback(project.imagery)}
229230
gpxUrl={getTaskGpxUrlCallback(project.projectId, tasksIds)}
230231
/>

0 commit comments

Comments
 (0)