mirror of
https://github.com/FoggedLens/iD.git
synced 2026-05-21 07:46:58 +02:00
allow type/id syntax in id hash param, and add support for notes
This commit is contained in:
@@ -4,12 +4,13 @@ import { select as d3_select } from 'd3-selection';
|
||||
|
||||
import { geoSphericalDistance } from '../geo';
|
||||
import { modeBrowse } from '../modes/browse';
|
||||
import { modeSelect } from '../modes/select';
|
||||
import { modeSelect, modeSelectNote } from '../modes';
|
||||
import { utilDisplayLabel, utilObjectOmit, utilQsString, utilStringQs } from '../util';
|
||||
import { utilArrayIdentical } from '../util/array';
|
||||
import { t } from '../core/localizer';
|
||||
import { prefs } from '../core/preferences';
|
||||
|
||||
|
||||
export function behaviorHash(context) {
|
||||
|
||||
// cached window.location.hash
|
||||
@@ -33,6 +34,8 @@ export function behaviorHash(context) {
|
||||
});
|
||||
if (selected.length) {
|
||||
newParams.id = selected.join(',');
|
||||
} else if (context.selectedNoteID()) {
|
||||
newParams.id = `note/${context.selectedNoteID()}`;
|
||||
}
|
||||
|
||||
newParams.map = zoom.toFixed(2) +
|
||||
@@ -147,11 +150,14 @@ export function behaviorHash(context) {
|
||||
|
||||
if (q.id && mode) {
|
||||
var ids = q.id.split(',').filter(function(id) {
|
||||
return context.hasEntity(id);
|
||||
return context.hasEntity(id) || id.startsWith('note/');
|
||||
});
|
||||
if (ids.length &&
|
||||
(mode.id === 'browse' || (mode.id === 'select' && !utilArrayIdentical(mode.selectedIDs(), ids)))) {
|
||||
context.enter(modeSelect(context, ids));
|
||||
if (ids.length && ['browse', 'select-note', 'select'].includes(mode.id)) {
|
||||
if (ids.length === 1 && ids[0].startsWith('note/')) {
|
||||
context.enter(modeSelectNote(context, ids[0]));
|
||||
} else if (!utilArrayIdentical(mode.selectedIDs(), ids)) {
|
||||
context.enter(modeSelect(context, ids));
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
@@ -185,10 +191,17 @@ export function behaviorHash(context) {
|
||||
var q = utilStringQs(window.location.hash);
|
||||
|
||||
if (q.id) {
|
||||
//if (!context.history().hasRestorableChanges()) {
|
||||
// targeting specific features: download, select, and zoom to them
|
||||
context.zoomToEntity(q.id.split(',')[0], !q.map);
|
||||
//}
|
||||
const selectIds = q.id.split(',');
|
||||
if (selectIds.length === 1 && selectIds[0].startsWith('note/')) {
|
||||
const noteId = selectIds[0].split('/')[1];
|
||||
context.zoomToNote(noteId, !q.map);
|
||||
} else {
|
||||
context.zoomToEntities(
|
||||
// convert ids to short form id: node/123 -> n123
|
||||
selectIds.map(id => id.replace(/([nwr])[^/]*\//, '$1')),
|
||||
!q.map);
|
||||
}
|
||||
}
|
||||
|
||||
if (q.walkthrough === 'true') {
|
||||
|
||||
Reference in New Issue
Block a user