diff --git a/modules/core/context.js b/modules/core/context.js index e72f06a2b..73b9e9219 100644 --- a/modules/core/context.js +++ b/modules/core/context.js @@ -176,6 +176,13 @@ export function coreContext() { _connection.loadEntityRelations(entityID, afterLoad(cid, callback)); } }; + // Download single note + context.loadNote = (entityID, callback) => { + if (_connection) { + const cid = _connection.getConnectionId(); + _connection.loadEntityNote(entityID, afterLoad(cid, callback)); + } + }; context.zoomToEntity = (entityID, zoomTo) => { diff --git a/modules/services/osm.js b/modules/services/osm.js index d893b63c8..30fdb0b72 100644 --- a/modules/services/osm.js +++ b/modules/services/osm.js @@ -729,6 +729,19 @@ export default { ); }, + // Load a single note by id , XML format + // GET /api/0.6/notes/#id + loadEntityNote: function(id, callback) { + var options = { skipSeen: false }; + this.loadFromAPI( + '/api/0.6/notes/' + id , + function(err, entities) { + if (callback) callback(err, { data: entities }); + }, + options + ); + }, + // Load a single entity with a specific version // GET /api/0.6/[node|way|relation]/#id/#version diff --git a/modules/ui/feature_list.js b/modules/ui/feature_list.js index fe004bf68..31b7cdc04 100644 --- a/modules/ui/feature_list.js +++ b/modules/ui/feature_list.js @@ -15,6 +15,7 @@ import { isColourValid } from '../osm/tags'; import { services } from '../services'; import { svgIcon } from '../svg/icon'; import { uiCmd } from './cmd'; +import { modeSelectNote } from '../modes'; import { utilDisplayName, @@ -138,15 +139,15 @@ export function uiFeatureList(context) { } // A location search takes priority over an ID search - var idMatch = !locationMatch && q.match(/(?:^|\W)(node|way|relation|[nwr])\W{0,2}0*([1-9]\d*)(?:\W|$)/i); + var idMatch = !locationMatch && q.match(/(?:^|\W)(node|way|relation|note|[nwr])\W{0,2}0*([1-9]\d*)(?:\W|$)/i); if (idMatch) { - var elemType = idMatch[1].charAt(0); + var elemType = idMatch[1] === 'note' ? idMatch[1] : idMatch[1].charAt(0); var elemId = idMatch[2]; result.push({ id: elemType + elemId, - geometry: elemType === 'n' ? 'point' : elemType === 'w' ? 'line' : 'relation', - type: elemType === 'n' ? t('inspector.node') : elemType === 'w' ? t('inspector.way') : t('inspector.relation'), + geometry: elemType === 'n' ? 'point' : elemType === 'w' ? 'line' : elemType === 'note' ? 'note' : 'relation', + type: elemType === 'n' ? t('inspector.node') : elemType === 'w' ? t('inspector.way') : elemType === 'note' ? t('note.note') : t('inspector.relation'), name: elemId }); } @@ -232,6 +233,12 @@ export function uiFeatureList(context) { type: t('inspector.relation'), name: q }); + result.push({ + id: 'note' + q, + geometry: 'note', + type: t('note.note'), + name: q + }); } return result; @@ -353,6 +360,26 @@ export function uiFeatureList(context) { context.enter(modeSelect(context, [d.entity.id])); context.map().zoomToEase(d.entity); + } else if (d.geometry === 'note') { + // note + // get number part 'note12345' + const noteId = d.id.replace(/\D/g, ''); + + // load note + context.loadNote(noteId, (err, result) => { + if (err) return; + const entity = result.data.find(e => e.id === noteId); + if (entity) { + // zoom to, used note loc + const note = services.osm.getNote(noteId); + context.map().centerZoom(note.loc,15); + // open note layer + const noteLayer = context.layers().layer('notes'); + noteLayer.enabled(true); + // select the note + context.enter(modeSelectNote(context, noteId)); + } + }); } else { // download, zoom to, and select the entity with the given ID context.zoomToEntity(d.id);