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 1 commit
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
79 changes: 79 additions & 0 deletions lib/components/map/connected-geojson-layer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
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'

const GeoJSONOverlay = (props) => {
const { setLocation, url } = props

Check failure on line 12 in lib/components/map/connected-geojson-layer.js

View workflow job for this annotation

GitHub Actions / test-build-release

'setLocation' is missing in props validation

Check failure on line 12 in lib/components/map/connected-geojson-layer.js

View workflow job for this annotation

GitHub Actions / test-build-release

'url' is missing in props validation

const [locations, setLocations] = useState([])
useEffect(() => {
async function downloadLocations() {
const json = await (await fetch(url)).json()
setLocations(json)
}
if (url) downloadLocations()
}, [])

Check warning on line 21 in lib/components/map/connected-geojson-layer.js

View workflow job for this annotation

GitHub Actions / test-build-release

React Hook useEffect has a missing dependency: 'url'. Either include it or remove the dependency array

return (
<>
{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>
}
popupProps={{ offset: 10 }}
position={[geometry.coordinates[1], geometry.coordinates[0]]}
>
<img
alt={properties.Name}
src={properties.icon}
style={{ height: 40 }}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is coming across as very tall!!

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree let's remove it

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think a className should still be set on the <img> tag so that the configs can style the images if needed.

/>
</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 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 @@ -70,7 +71,7 @@
/**
* Determines the localized name of a map layer by its type.
*/
function getLayerName(overlay, config, intl) {

Check warning on line 74 in lib/components/map/default-map.tsx

View workflow job for this annotation

GitHub Actions / test-build-release

Function 'getLayerName' has a complexity of 17. Maximum allowed is 12
const { companies, name, type } = overlay

// HACK: Support for street/satellite configs that use the name.
Expand Down Expand Up @@ -156,7 +157,7 @@
* as that UI mode sets the access mode and company in the query params.
* TODO: Implement for the batch interface.
*/
_handleQueryChange = (oldQuery, newQuery) => {

Check warning on line 160 in lib/components/map/default-map.tsx

View workflow job for this annotation

GitHub Actions / test-build-release

Arrow function has a complexity of 19. Maximum allowed is 12
const { overlays = [] } = this.props.mapConfig || {}
if (oldQuery.mode) {
// Determine any added/removed modes
Expand Down Expand Up @@ -324,6 +325,10 @@
name: getLayerName(overlayConfig, config, intl)
}
switch (overlayConfig.type) {
case 'geojson':
return (
<GeoJsonLayer {...namedLayerProps} url={overlayConfig.url} />
)
case 'bike-rental':
return (
<VehicleRentalOverlay
Expand Down
Loading