Skip to content

Commit

Permalink
Fetch the parent relations when downloading a single entity, e.g. whe…
Browse files Browse the repository at this point in the history
…n launching iD with a feature selected (close #6731)
  • Loading branch information
quincylvania committed Nov 10, 2020
1 parent 058676c commit 481b80e
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 7 deletions.
3 changes: 3 additions & 0 deletions modules/core/context.js
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
};

Expand Down
20 changes: 19 additions & 1 deletion modules/services/osm.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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
Expand Down
6 changes: 4 additions & 2 deletions modules/ui/improveOSM_details.js
Original file line number Diff line number Diff line change
Expand Up @@ -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]));
});
}
});
Expand Down
6 changes: 4 additions & 2 deletions modules/ui/keepRight_details.js
Original file line number Diff line number Diff line change
Expand Up @@ -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]));
});
}
});
Expand Down
6 changes: 4 additions & 2 deletions modules/ui/osmose_details.js
Original file line number Diff line number Diff line change
Expand Up @@ -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]));
});
}
});
Expand Down

0 comments on commit 481b80e

Please sign in to comment.