Skip to content

Commit

Permalink
Reduce number of bbox iterations, use en-US locale, inform client whe…
Browse files Browse the repository at this point in the history
…n no features found (#4)

* add map to river-runner

* add limit to bbox expansion

* reduce max # of bboxes, tell client when no features returned, add en-US locale
  • Loading branch information
webb-ben authored Sep 10, 2021
1 parent 8e62581 commit aacf31b
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 14 deletions.
2 changes: 1 addition & 1 deletion pygeoapi/flask_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ def get_processes_map(process_id=None):
:returns: HTTP response
"""
return render_j2_template(CONFIG, 'processes/map.html', {})
return render_j2_template(CONFIG, 'processes/map.html', {}, 'en-US')


@BLUEPRINT.route('/processes/<process_id>/jobs')
Expand Down
26 changes: 15 additions & 11 deletions pygeoapi/map.html
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
map.setView(e.latlng);
var popup = L.popup(keepInView=true)
.setLatLng(e.latlng)
.setContent('Finding flowpath from this point')
.setContent('Finding flowpath from this point.')
.openOn(map);

$.ajax({
Expand All @@ -53,17 +53,21 @@
processData: false,
success: function(response) {
popup.remove();
var geojson_data = response.value;
var items = new L.GeoJSON(geojson_data, {
onEachFeature: function (feature, layer) {
var url = "{{ config['server']['url'] }}/collections/merit/items/" + feature.id + '?f=html';
var html = '<span><a href="' + url + '">' + feature.properties.nameID + '</a></span>';
layer.bindPopup(html);
}
});
map.addLayer(items);
map.fitBounds(items.getBounds());
loading = false;
var geojson_data = response.value;
if (geojson_data.features.length === 0){
alert('No flowpath found. :(')
} else {
var items = new L.GeoJSON(geojson_data, {
onEachFeature: function (feature, layer) {
var url = "{{ config['server']['url'] }}/collections/merit/items/" + feature.id + '?f=html';
var html = '<span><a href="' + url + '">' + feature.properties.nameID + '</a></span>';
layer.bindPopup(html);
}
});
map.addLayer(items);
map.fitBounds(items.getBounds());
}
},
error: function(error) {
console.log(error)
Expand Down
15 changes: 13 additions & 2 deletions pygeoapi/river_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,13 @@ def __init__(self, processor_def):

def execute(self, data):
mimetype = 'application/json'
outputs = {
'id': 'echo',
'value': {
'type': 'FeatureCollection',
'features': []
}
}
if len(data.get('bbox', [])) != 4 and \
not data.get('lat', '') and \
not data.get('lng', ''):
Expand All @@ -143,12 +150,16 @@ def execute(self, data):

value = self.p.query(bbox=bbox)
i = 1
while len(value['features']) < 1 and i < 10:
while len(value['features']) < 1 and i < 3:
LOGGER.debug(f'No features in bbox {bbox}, expanding')
bbox = self._expand_bbox(bbox, e=0.125*i)
bbox = self._expand_bbox(bbox, e=0.5*i)
value = self.p.query(bbox=bbox)
i = i + 1

if len(value['features']) < 1:
LOGGER.debug('No features found')
return mimetype, outputs

LOGGER.debug('fetching downstream features')
mh = self._compare(value, 'hydroseq', min)
out, trim = [], []
Expand Down

0 comments on commit aacf31b

Please sign in to comment.