Skip to content

Commit 5966863

Browse files
authored
Search OSM notes by ID (#10062)
1 parent 2a0024d commit 5966863

File tree

3 files changed

+51
-4
lines changed

3 files changed

+51
-4
lines changed

modules/core/context.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,13 @@ export function coreContext() {
176176
_connection.loadEntityRelations(entityID, afterLoad(cid, callback));
177177
}
178178
};
179+
// Download single note
180+
context.loadNote = (entityID, callback) => {
181+
if (_connection) {
182+
const cid = _connection.getConnectionId();
183+
_connection.loadEntityNote(entityID, afterLoad(cid, callback));
184+
}
185+
};
179186

180187
context.zoomToEntity = (entityID, zoomTo) => {
181188

modules/services/osm.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -729,6 +729,19 @@ export default {
729729
);
730730
},
731731

732+
// Load a single note by id , XML format
733+
// GET /api/0.6/notes/#id
734+
loadEntityNote: function(id, callback) {
735+
var options = { skipSeen: false };
736+
this.loadFromAPI(
737+
'/api/0.6/notes/' + id ,
738+
function(err, entities) {
739+
if (callback) callback(err, { data: entities });
740+
},
741+
options
742+
);
743+
},
744+
732745

733746
// Load a single entity with a specific version
734747
// GET /api/0.6/[node|way|relation]/#id/#version

modules/ui/feature_list.js

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import { isColourValid } from '../osm/tags';
1515
import { services } from '../services';
1616
import { svgIcon } from '../svg/icon';
1717
import { uiCmd } from './cmd';
18+
import { modeSelectNote } from '../modes';
1819

1920
import {
2021
utilDisplayName,
@@ -138,15 +139,15 @@ export function uiFeatureList(context) {
138139
}
139140

140141
// A location search takes priority over an ID search
141-
var idMatch = !locationMatch && q.match(/(?:^|\W)(node|way|relation|[nwr])\W{0,2}0*([1-9]\d*)(?:\W|$)/i);
142+
var idMatch = !locationMatch && q.match(/(?:^|\W)(node|way|relation|note|[nwr])\W{0,2}0*([1-9]\d*)(?:\W|$)/i);
142143

143144
if (idMatch) {
144-
var elemType = idMatch[1].charAt(0);
145+
var elemType = idMatch[1] === 'note' ? idMatch[1] : idMatch[1].charAt(0);
145146
var elemId = idMatch[2];
146147
result.push({
147148
id: elemType + elemId,
148-
geometry: elemType === 'n' ? 'point' : elemType === 'w' ? 'line' : 'relation',
149-
type: elemType === 'n' ? t('inspector.node') : elemType === 'w' ? t('inspector.way') : t('inspector.relation'),
149+
geometry: elemType === 'n' ? 'point' : elemType === 'w' ? 'line' : elemType === 'note' ? 'note' : 'relation',
150+
type: elemType === 'n' ? t('inspector.node') : elemType === 'w' ? t('inspector.way') : elemType === 'note' ? t('note.note') : t('inspector.relation'),
150151
name: elemId
151152
});
152153
}
@@ -232,6 +233,12 @@ export function uiFeatureList(context) {
232233
type: t('inspector.relation'),
233234
name: q
234235
});
236+
result.push({
237+
id: 'note' + q,
238+
geometry: 'note',
239+
type: t('note.note'),
240+
name: q
241+
});
235242
}
236243

237244
return result;
@@ -353,6 +360,26 @@ export function uiFeatureList(context) {
353360
context.enter(modeSelect(context, [d.entity.id]));
354361
context.map().zoomToEase(d.entity);
355362

363+
} else if (d.geometry === 'note') {
364+
// note
365+
// get number part 'note12345'
366+
const noteId = d.id.replace(/\D/g, '');
367+
368+
// load note
369+
context.loadNote(noteId, (err, result) => {
370+
if (err) return;
371+
const entity = result.data.find(e => e.id === noteId);
372+
if (entity) {
373+
// zoom to, used note loc
374+
const note = services.osm.getNote(noteId);
375+
context.map().centerZoom(note.loc,15);
376+
// open note layer
377+
const noteLayer = context.layers().layer('notes');
378+
noteLayer.enabled(true);
379+
// select the note
380+
context.enter(modeSelectNote(context, noteId));
381+
}
382+
});
356383
} else {
357384
// download, zoom to, and select the entity with the given ID
358385
context.zoomToEntity(d.id);

0 commit comments

Comments
 (0)