From 5137acabfe55259fd816d5b1eaaa733d15d8e2f9 Mon Sep 17 00:00:00 2001 From: Edward Betts Date: Fri, 16 Jul 2021 11:58:37 +0200 Subject: [PATCH] Store item.osm as object instead of array --- frontend/App.vue | 50 +++++++++++++++++++++++++----------------------- 1 file changed, 26 insertions(+), 24 deletions(-) diff --git a/frontend/App.vue b/frontend/App.vue index a56c016..d0394f9 100644 --- a/frontend/App.vue +++ b/frontend/App.vue @@ -1102,11 +1102,7 @@ export default { axios.get(item_osm_candidates_url, { params: params }).then((response) => { var qid = response.data.qid; var item = this.items[qid]; - var osm_identifiers = [] - - if (item.osm) { - item.osm.forEach((osm) => { osm_identifiers.push(osm.identifier); }); - } + var osm_identifiers = item.osm ? Object.keys(item.osm) : []; item.nearby = response.data.nearby; item.nearby.forEach((osm) => { @@ -1213,7 +1209,22 @@ export default { this.items = {}; this.clear_isa(); }, + add_osm_to_map(item, osm) { + var group = item.group ||= L.featureGroup(); + var icon = osmYellowMarker; + var marker = L.marker(osm.centroid, { opacity: 0.9, title: osm.name, icon: icon }); + osm.marker = marker; + marker.addTo(group); + this.mouse_events(marker, item.qid); + if (osm.type != "node" && osm.geojson) { + var mapStyle = { fillOpacity: 0 }; + var geojson = L.geoJSON(null, { style: mapStyle }); + geojson.addData(osm.geojson); + geojson.addTo(group); + item.outline = geojson; + } + }, load_wikidata_items(bounds) { this.load_button_pressed = true; this.wikidata_loaded = false; @@ -1249,24 +1260,15 @@ export default { axios.get(osm_objects_url, { params: params }).then((response) => { response.data.objects.forEach((osm) => { var qid = osm.wikidata; - this.items[qid] ||= {'qid': qid}; - if (this.items[qid].osm) return; - this.items[qid].osm = []; - this.items[qid].osm.push(osm); - var group = this.items[qid].group ||= L.featureGroup(); - var icon = osmYellowMarker; - var marker = L.marker(osm.centroid, { opacity: 0.9, title: osm.name, icon: icon }); - osm.marker = marker; - marker.addTo(group); - this.mouse_events(marker, qid); - - if (osm.type != "node" && osm.geojson) { - var mapStyle = { fillOpacity: 0 }; - var geojson = L.geoJSON(null, { style: mapStyle }); - geojson.addData(osm.geojson); - geojson.addTo(group); - this.items[qid].outline = geojson; + var item = this.items[qid] ||= {'qid': qid}; + if (item.osm) { + if (item.osm[osm.identifier]) return; + } else { + item.osm = {}; } + item.osm[osm.identifier] = osm; + this.add_osm_to_map(item, osm); + }); this.osm_loaded = true; this.osm_loading = false; @@ -1370,7 +1372,7 @@ export default { var wd_item = item.wikidata; - item.osm.forEach((osm) => { + Object.values(item.osm).forEach((osm) => { osm.marker.setIcon(wd_item ? osmYellowMarker : osmOrangeMarker); }); @@ -1380,7 +1382,7 @@ export default { var marker = this.item_has_edit(item) ? greenDarkMarker : greenMarker; marker_data.marker.setIcon(marker); item.lines ||= []; - item.osm.forEach((osm) => { + Object.values(item.osm).forEach((osm) => { var path = [osm.centroid, marker_data]; var polyline = L.polyline(path, { color: "green" }); polyline.addTo(item.group)