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:
Quincy Morgan
2020-11-10 10:00:44 -05:00
parent 058676c0e1
commit 481b80e5cb
5 changed files with 34 additions and 7 deletions

View File

@@ -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));
}
};

View File

@@ -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

View File

@@ -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]));
});
}
});

View File

@@ -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]));
});
}
});

View File

@@ -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]));
});
}
});