import React from 'react'
import { Portal } from 'react-portal'
class MapNarratives extends React.Component {
projectPoint(location) {
const latLng = new L.LatLng(location[0], location[1])
return {
x: this.props.map.latLngToLayerPoint(latLng).x + this.props.mapTransformX,
y: this.props.map.latLngToLayerPoint(latLng).y + this.props.mapTransformY
}
}
getNarrativeStyle(narrativeId) {
const styleName = (narrativeId && narrativeId in this.props.narrativeProps)
? narrativeId
: 'default'
return this.props.narrativeProps[styleName]
}
getStrokeWidth(narrative, step) {
if (!step) return 0
return this.getNarrativeStyle(narrative.id).strokeWidth
}
getStrokeDashArray(narrative, step) {
if (!step) return 'none'
return (this.getNarrativeStyle(narrative.id).style === 'dotted') ? "2px 5px" : 'none'
}
getStroke(narrative, step) {
if (!step || this.props.narrative === null) return 'none'
return this.getNarrativeStyle(narrative.id).stroke
}
getStrokeOpacity(narrative, step) {
if (this.props.narrative === null) return 0
if (!step || narrative.id !== this.props.narrative.id) return 0.1
return 1
}
hasNoLocation(step) {
return (step.latitude === '' || step.longitude === '')
}
renderNarrativeStep(allSteps, step, idx, n) {
const { x, y } = this.projectPoint([step.latitude, step.longitude])
const step2 = allSteps[idx + 1]
// don't draw if one of the steps has no location
if (this.hasNoLocation(step) || this.hasNoLocation(step2))
return null
const p2 = this.projectPoint([step2.latitude, step2.longitude])
return (