Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add GeoJSONOverlay #1082

Merged
merged 5 commits into from
Dec 8, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
82 changes: 82 additions & 0 deletions lib/components/map/connected-geojson-layer.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
import {
Styled as BaseMapStyled,
MarkerWithPopup
} from '@opentripplanner/base-map'
import { connect } from 'react-redux'
import FromToLocationPicker from '@opentripplanner/from-to-location-picker'
import React, { useEffect, useState } from 'react'

import { setLocation } from '../../actions/map'
miles-grant-ibigroup marked this conversation as resolved.
Show resolved Hide resolved
import { SetLocationHandler } from '../util/types'

type Props = {
setLocation: SetLocationHandler
url: string
}
const GeoJSONOverlay = (props: Props) => {
const { setLocation, url } = props

const [locations, setLocations] = useState([])
useEffect(() => {
async function downloadLocations() {
const json = await (await fetch(url)).json()
setLocations(json)
}
if (url) downloadLocations()
miles-grant-ibigroup marked this conversation as resolved.
Show resolved Hide resolved
}, [url])

return (
<>
miles-grant-ibigroup marked this conversation as resolved.
Show resolved Hide resolved
{/* @ts-expect-error TODO: geojson types */}
miles-grant-ibigroup marked this conversation as resolved.
Show resolved Hide resolved
{locations?.features?.map((feature, k) => {
const { geometry, properties } = feature
if (!geometry || !geometry.coordinates) return null
return (
<MarkerWithPopup
key={k}
popupContents={
<BaseMapStyled.MapOverlayPopup>
{properties.Name && (
<BaseMapStyled.PopupTitle>
{properties.Name}
</BaseMapStyled.PopupTitle>
)}
<BaseMapStyled.PopupRow>
{properties.popupContent && (
<div>{properties.popupContent}</div>
)}
{properties.Address && (
<div>
{properties.Address}, {properties.Zip}, {properties.City},{' '}
{properties.State}
</div>
)}
{properties.Phone && <div>{properties.Phone}</div>}
<FromToLocationPicker
label
location={{
lat: geometry.coordinates[1],
lon: geometry.coordinates[0],
name: properties.Name
}}
setLocation={setLocation}
/>
</BaseMapStyled.PopupRow>
</BaseMapStyled.MapOverlayPopup>
}
// @ts-expect-error popup props are incorrect
popupProps={{ offset: 10 }}
position={[geometry.coordinates[1], geometry.coordinates[0]]}
>
<img alt={properties.Name} src={properties.icon} />
</MarkerWithPopup>
)
})}
</>
)
}
const mapDispatchToProps = {
setLocation
}

export default connect(null, mapDispatchToProps)(GeoJSONOverlay)
5 changes: 5 additions & 0 deletions lib/components/map/default-map.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import { updateOverlayVisibility } from '../../actions/config'

import ElevationPointMarker from './elevation-point-marker'
import EndpointsOverlay from './connected-endpoints-overlay'
import GeoJsonLayer from './connected-geojson-layer'
import ParkAndRideOverlay from './connected-park-and-ride-overlay'
import PointPopup from './point-popup'
import RoutePreviewOverlay from './route-preview-overlay'
Expand Down Expand Up @@ -324,6 +325,10 @@ class DefaultMap extends Component {
name: getLayerName(overlayConfig, config, intl)
}
switch (overlayConfig.type) {
case 'geojson':
return (
<GeoJsonLayer {...namedLayerProps} url={overlayConfig.url} />
)
case 'bike-rental':
return (
<VehicleRentalOverlay
Expand Down
Loading