From aacf31b97a25bf1e3c4357a6103d23e8c54d04ee Mon Sep 17 00:00:00 2001 From: Benjamin Webb <40066515+webb-ben@users.noreply.github.com> Date: Fri, 10 Sep 2021 12:30:52 -0400 Subject: [PATCH] Reduce number of bbox iterations, use en-US locale, inform client when 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 --- pygeoapi/flask_app.py | 2 +- pygeoapi/map.html | 26 +++++++++++++++----------- pygeoapi/river_runner.py | 15 +++++++++++++-- 3 files changed, 29 insertions(+), 14 deletions(-) diff --git a/pygeoapi/flask_app.py b/pygeoapi/flask_app.py index 1b05793..219b3d7 100644 --- a/pygeoapi/flask_app.py +++ b/pygeoapi/flask_app.py @@ -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//jobs') diff --git a/pygeoapi/map.html b/pygeoapi/map.html index 7588b2e..6084c51 100644 --- a/pygeoapi/map.html +++ b/pygeoapi/map.html @@ -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({ @@ -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 = '' + feature.properties.nameID + ''; - 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 = '' + feature.properties.nameID + ''; + layer.bindPopup(html); + } + }); + map.addLayer(items); + map.fitBounds(items.getBounds()); + } }, error: function(error) { console.log(error) diff --git a/pygeoapi/river_runner.py b/pygeoapi/river_runner.py index 03efcc8..ff3f491 100644 --- a/pygeoapi/river_runner.py +++ b/pygeoapi/river_runner.py @@ -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', ''): @@ -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 = [], []