forked from edward/owl-map
Auto load Wikidata items
This commit is contained in:
parent
0c98ca921c
commit
f0cb54bf95
|
@ -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();
|
||||
}
|
||||
});
|
||||
|
||||
|
|
18
web_view.py
18
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")
|
||||
|
|
Loading…
Reference in a new issue