Skip to content

Commit 0473372

Browse files
committed
Search OSM notes by ID
re: #7618 only support number without prefix
1 parent 38be2af commit 0473372

File tree

3 files changed

+49
-0
lines changed

3 files changed

+49
-0
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: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -729,6 +729,21 @@ 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 type = osmEntity.id.type(id);
736+
// var osmID = osmEntity.id.toOSM(id);
737+
var options = { skipSeen: false };
738+
this.loadFromAPI(
739+
'/api/0.6/notes/' + id ,
740+
function(err, entities) {
741+
if (callback) callback(err, { data: entities });
742+
},
743+
options
744+
);
745+
},
746+
732747

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

modules/ui/feature_list.js

Lines changed: 27 additions & 0 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,
@@ -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)