mirror of
https://github.com/FoggedLens/iD.git
synced 2026-02-26 15:33:50 +00:00
Fetch the parent relations when downloading a single entity, e.g. when launching iD with a feature selected (close #6731)
This commit is contained in:
@@ -177,10 +177,13 @@ export function coreContext() {
|
||||
_deferred.add(handle);
|
||||
};
|
||||
|
||||
// Download the full entity and its parent relations. The callback may be called multiple times.
|
||||
context.loadEntity = (entityID, callback) => {
|
||||
if (_connection) {
|
||||
const cid = _connection.getConnectionId();
|
||||
_connection.loadEntity(entityID, afterLoad(cid, callback));
|
||||
// We need to fetch the parent relations separately.
|
||||
_connection.loadEntityRelations(entityID, afterLoad(cid, callback));
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -635,7 +635,8 @@ export default {
|
||||
},
|
||||
|
||||
|
||||
// Load a single entity by id (ways and relations use the `/full` call)
|
||||
// Load a single entity by id (ways and relations use the `/full` call to include
|
||||
// nodes and members). Parent relations are not included, see `loadEntityRelations`.
|
||||
// GET /api/0.6/node/#id
|
||||
// GET /api/0.6/[way|relation]/#id/full
|
||||
loadEntity: function(id, callback) {
|
||||
@@ -670,6 +671,23 @@ export default {
|
||||
},
|
||||
|
||||
|
||||
// Load the relations of a single entity with the given.
|
||||
// GET /api/0.6/[node|way|relation]/#id/relations
|
||||
loadEntityRelations: function(id, callback) {
|
||||
var type = osmEntity.id.type(id);
|
||||
var osmID = osmEntity.id.toOSM(id);
|
||||
var options = { skipSeen: false };
|
||||
|
||||
this.loadFromAPI(
|
||||
'/api/0.6/' + type + '/' + osmID + '/relations.json',
|
||||
function(err, entities) {
|
||||
if (callback) callback(err, { data: entities });
|
||||
},
|
||||
options
|
||||
);
|
||||
},
|
||||
|
||||
|
||||
// Load multiple entities in chunks
|
||||
// (note: callback may be called multiple times)
|
||||
// Unlike `loadEntity`, child nodes and members are not fetched
|
||||
|
||||
@@ -86,8 +86,10 @@ export function uiImproveOsmDetails(context) {
|
||||
if (entity) {
|
||||
context.enter(modeSelect(context, [entityID]));
|
||||
} else {
|
||||
context.loadEntity(entityID, () => {
|
||||
context.enter(modeSelect(context, [entityID]));
|
||||
context.loadEntity(entityID, (err, result) => {
|
||||
if (err) return;
|
||||
const entity = result.data.find(e => e.id === entityID);
|
||||
if (entity) context.enter(modeSelect(context, [entityID]));
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
@@ -91,8 +91,10 @@ export function uiKeepRightDetails(context) {
|
||||
if (entity) {
|
||||
context.enter(modeSelect(context, [entityID]));
|
||||
} else {
|
||||
context.loadEntity(entityID, () => {
|
||||
context.enter(modeSelect(context, [entityID]));
|
||||
context.loadEntity(entityID, (err, result) => {
|
||||
if (err) return;
|
||||
const entity = result.data.find(e => e.id === entityID);
|
||||
if (entity) context.enter(modeSelect(context, [entityID]));
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
@@ -169,8 +169,10 @@ export function uiOsmoseDetails(context) {
|
||||
if (entity) {
|
||||
context.enter(modeSelect(context, [entityID]));
|
||||
} else {
|
||||
context.loadEntity(entityID, () => {
|
||||
context.enter(modeSelect(context, [entityID]));
|
||||
context.loadEntity(entityID, (err, result) => {
|
||||
if (err) return;
|
||||
const entity = result.data.find(e => e.id === entityID);
|
||||
if (entity) context.enter(modeSelect(context, [entityID]));
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user