Use Osmose tiles API endpoint instead of issues

- Simplifies our code a little bit
- Quick to provide and gives us the `item` + `class` without requesting
all other information (the two things needed to know the error type)
- Removed handling of associated elements for now, need to implement
fetching for that data on a per-issue basis when the UI loads
- Set things up for the possibility of using the provided translation
strings (need to determine if desirable)

See: https://github.com/osm-fr/osmose-frontend/issues/193
This commit is contained in:
SilentSpike
2019-12-28 18:55:04 +00:00
parent 680fdb6b54
commit ebd206595a
3 changed files with 21 additions and 26 deletions
-1
View File
@@ -34,7 +34,6 @@
}
},
"osmose": {
"items": ["0", "1040", "1050", "1070", "1080", "1150", "1280"],
"errorTypes": {
"0-1": {
"icon": "maki-home"
+20 -24
View File
@@ -14,7 +14,7 @@ var dispatch = d3_dispatch('loaded');
var _erCache;
var _erZoom = 14;
var _osmoseUrlRoot = 'https://osmose.openstreetmap.fr/en/api/0.3beta/';
var _osmoseUrlRoot = 'https://osmose.openstreetmap.fr/';
function abortRequest(controller) {
if (controller) {
@@ -91,11 +91,8 @@ export default {
},
loadErrors: function(projection) {
var options = {
full: 'true', // Returns element IDs
level: '1,2,3',
zoom: '19',
item: services.osmose.items.join() // only interested in certain errors
var params = {
level: '1,2,3'
};
// determine the needed tiles to cover the view
@@ -110,10 +107,9 @@ export default {
tiles.forEach(function(tile) {
if (_erCache.loadedTile[tile.id] || _erCache.inflightTile[tile.id]) return;
var rect = tile.extent.rectangle(); // E, N, W, S
var params = Object.assign({}, options, { bbox: rect.join() });
var url = _osmoseUrlRoot + 'issues?' + utilQsString(params);
var lang = 'en'; // todo: may want to use provided translations
var path = [tile.xyz[2], tile.xyz[0], tile.xyz[1]].join('/');
var url = _osmoseUrlRoot + lang + '/map/issues/' + path + '.json?' + utilQsString(params);
var controller = new AbortController();
_erCache.inflightTile[tile.id] = controller;
@@ -123,15 +119,12 @@ export default {
delete _erCache.inflightTile[tile.id];
_erCache.loadedTile[tile.id] = true;
if (data.issues) {
data.issues.forEach(function(issue) {
// Elements provided as string, separated by _ character
var elems = issue.elems.split('_').map(function(i) {
return i.substring(0,1) + i.replace(/node|way|relation/, '');
});
var loc = [issue.lon, issue.lat];
if (data.features) {
data.features.forEach(function(issue) {
var loc = issue.geometry.coordinates; // lon, lat
var props = issue.properties;
// Item is the type of error, w/ class tells us the sub-type
var type = [issue.item, issue.classs].join('-');
var type = [props.item, props.class].join('-');
// Filter out unsupported error types (some are too specific or advanced)
if (type in services.osmose.errorTypes) {
@@ -143,21 +136,22 @@ export default {
service: 'osmose',
error_type: type,
// Extra details needed for this service
identifier: issue.id, // this is used to post changes to the error
elems: elems,
item: issue.item // category of the issue for styling
identifier: props.issue_id, // this is used to post changes to the error
item: props.item // category of the issue for styling
});
// Variables used in the description
d.replacements = elems.map(function(i) {
return linkEntity(i);
});
// d.replacements = elems.map(function(i) {
// return linkEntity(i);
// });
_erCache.data[d.id] = d;
_erCache.rtree.insert(encodeErrorRtree(d));
}
});
}
dispatch.call('loaded');
})
.catch(function() {
delete _erCache.inflightTile[tile.id];
@@ -166,6 +160,8 @@ export default {
});
},
// todo: need to fetch specific error details upon UI loading for element IDs
postUpdate: function(d, callback) {
if (_erCache.inflightPost[d.id]) {
return callback({ message: 'Error update already inflight', status: -2 }, d);
+1 -1
View File
@@ -114,7 +114,7 @@ export function uiOsmoseDetails(context) {
});
// Don't hide entities related to this error - #5880
context.features().forceVisible(_error.elems);
// context.features().forceVisible(_error.elems);
context.map().pan([0,0]); // trigger a redraw
}