From f0cb54bf95b309edb2ab5437d98487a14b83d553 Mon Sep 17 00:00:00 2001 From: Edward Betts Date: Thu, 17 Jun 2021 19:14:42 +0200 Subject: [PATCH] Auto load Wikidata items --- frontend/App.vue | 16 ++++++++++++++++ web_view.py | 18 ++++++++++++++++++ 2 files changed, 34 insertions(+) diff --git a/frontend/App.vue b/frontend/App.vue index c3e8b4f..89ea390 100644 --- a/frontend/App.vue +++ b/frontend/App.vue @@ -531,6 +531,7 @@ export default { var lon = parseFloat(hit.lon).toFixed(5); this.map.setView([lat, lon], 16); + this.auto_load(); }, process_wikidata_items(load_items) { @@ -625,6 +626,19 @@ export default { this.osm_loading = false; this.check_for_missing(); + this.hits = []; + }); + }, + auto_load() { + var count_url = this.api_base_url + "/api/1/count"; + var bounds = this.map.getBounds(); + var params = { bounds: bounds.toBBoxString() }; + axios.get(count_url, { params: params }).then((response) => { + var count = response.data.count; + if (count < 1000) { + this.load_wikidata_items(); + } + }); }, run_search() { @@ -744,6 +758,8 @@ export default { this.detail_qid = this.qid_from_url(); if (this.detail_qid) { this.load_wikidata_items(); + } else { + this.auto_load(); } }); diff --git a/web_view.py b/web_view.py index a8eba45..d686230 100755 --- a/web_view.py +++ b/web_view.py @@ -409,6 +409,24 @@ def get_bbox_centroid(bbox): return lat, lon +@app.route("/api/1/count") +def api_wikidata_items_count(): + t0 = time() + bounds = request.args.get("bounds") + + db_bbox = make_envelope(bounds) + + q = ( + model.Item.query.join(model.ItemLocation) + .filter(func.ST_Covers(db_bbox, model.ItemLocation.location)) + ) + + t1 = time() - t0 + response = jsonify(success=True, count=q.count(), duration=t1) + response.headers["Access-Control-Allow-Origin"] = "*" + return response + + @app.route("/api/1/items") def api_wikidata_items(): bounds = request.args.get("bounds")