Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions modules/core/context.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {

Expand Down
13 changes: 13 additions & 0 deletions modules/services/osm.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
35 changes: 31 additions & 4 deletions modules/ui/feature_list.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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
});
}
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down