summaryrefslogtreecommitdiff
path: root/client/map/index.js
diff options
context:
space:
mode:
authorJules Laplace <julescarbon@gmail.com>2019-03-30 16:36:09 +0100
committerJules Laplace <julescarbon@gmail.com>2019-03-30 16:36:09 +0100
commitbeb4a2fa02a2859093f7dbdcff982e8b712b0f5b (patch)
tree138b95763b9bb65b0b01e92eff7955da893b4acc /client/map/index.js
parentc0503f43919f52e216d92c2a64ca515dbbc3b099 (diff)
addresses in paper where they belong
Diffstat (limited to 'client/map/index.js')
-rw-r--r--client/map/index.js17
1 files changed, 9 insertions, 8 deletions
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 = [
"<b>", title, "</b>",
@@ -47,9 +47,10 @@ function addMarker(map, latlng, title, subtext, year, pdf) {
message.push("</a>")
}
+ const addressString = addresses.map(addr => addr.name).join('<br/>')
message = message.concat([
"<br>",
- 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('<br/>')
- 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