mirror of
https://github.com/FoggedLens/iD.git
synced 2026-02-13 01:02:58 +00:00
Search OSM notes by ID (#10062)
This commit is contained in:
@@ -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) => {
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user