From beb4a2fa02a2859093f7dbdcff982e8b712b0f5b Mon Sep 17 00:00:00 2001 From: Jules Laplace Date: Sat, 30 Mar 2019 16:36:09 +0100 Subject: addresses in paper where they belong --- client/map/index.js | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) (limited to 'client') diff --git a/client/map/index.js b/client/map/index.js index 4e6db2de..b35ffddb 100644 --- a/client/map/index.js +++ b/client/map/index.js @@ -37,7 +37,7 @@ const redDot = L.icon({ popupAnchor: [0, -5] // point from which the popup should open relative to the iconAnchor }) -function addMarker(map, latlng, title, subtext, year, pdf) { +function addMarker(map, latlng, title, addresses, year, pdf) { const marker = L.marker(latlng, { icon: redDot }).addTo(map) let message = [ "", title, "", @@ -47,9 +47,10 @@ function addMarker(map, latlng, title, subtext, year, pdf) { message.push("") } + const addressString = addresses.map(addr => addr.name).join('
') message = message.concat([ "
", - subtext, + addressString, ]) if (year) { message.push(" (" + year + ")") @@ -72,7 +73,7 @@ function addArc(map, src, dest, arcStyle) { export default function append(el, payload) { const { data } = payload if (!data) return - let { paper, address, citations } = data + let { paper, addresses, citations } = data let source = [0, 0] let map = L.map(el).setView([25, 0], 2) @@ -86,13 +87,14 @@ export default function append(el, payload) { accessToken: 'pk.eyJ1IjoiZmFuc2FsY3kiLCJhIjoiY2pvN3I1czJwMHF5NDNrbWRoMWpteHlrdCJ9.kMpM5syQUhVjKkn1iVx9fg' }).addTo(map) - if (address) { - source = [address.lat, address.lng].map(n => (parseFloat(n) || 0)) + if (addresses && addresses.length) { + source = [address[0].lat, address[0].lng].map(n => (parseFloat(n) || 0)) } else { console.error("No address found for root paper") // console.log(data) } + // group papers by address citations.forEach(citation => { console.log(citation) if (!citation.addresses) { @@ -102,14 +104,13 @@ export default function append(el, payload) { const citationAddress = citation.addresses[0] const latlng = [citationAddress.lat, citationAddress.lng].map(n => parseFloat(n)) if (Number.isNaN(latlng[0]) || Number.isNaN(latlng[1])) return - const addressString = citation.addresses.map(addr => addr.name).join('
') - addMarker(map, latlng, citation.title, addressString, citation.year, citation.pdf) + addMarker(map, latlng, citation.title, citation.addresses, citation.year, citation.pdf) addArc(map, source, latlng, arcStyles[citationAddress.type]) }) console.log(paper) - const rootMarker = addMarker(map, source, paper.title, address.name, paper.year) + const rootMarker = addMarker(map, source, paper.title, addresses, paper.year) rootMarker.openPopup() // a transparent div to cover the map, so normal scroll events will not be eaten by leaflet -- cgit v1.2.3-70-g09d2