-
Notifications
You must be signed in to change notification settings - Fork 1
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
Minimal 'CoreDataPlace' Widget Example #247
Changes from 5 commits
6588d5e
91f0579
720e7d3
75fdb3a
924b73f
f45f162
429fe76
6b510c3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
import React, { useEffect, useState } from 'react'; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think if you add the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done, but even with Flow enabled, I'm still getting red squiggles under every TypeScript statement, and Flow shows all the TS stuff as "uncovered area". I'll enquire with Camden. |
||
import type { FeatureCollection } from '@peripleo/peripleo'; | ||
import { Peripleo, Controls } from '@peripleo/peripleo'; | ||
import { Map, MixedGeoJSONLayer, PulsingMarkerLayer, Zoom } from '@peripleo/maplibre'; | ||
import { DEFAULT_FILL_STYLE, DEFAULT_POINT_STYLE, DEFAULT_STROKE_STYLE } from './CoreDataPlaceStyles'; | ||
|
||
type CoreDataPlaceProps = { | ||
mapStyle: string | object; | ||
placeURI: string; | ||
fillStyle?: object; | ||
pointStyle?: object; | ||
strokeStyle?: object; | ||
}; | ||
|
||
export const CoreDataPlace = (props: CoreDataPlaceProps) => { | ||
|
||
return ( | ||
<Peripleo> | ||
<Map style={props.mapStyle}> | ||
<Controls position="topright"> | ||
<Zoom /> | ||
</Controls> | ||
|
||
<CoreDataPlaceLayer | ||
uri={props.placeURI} | ||
fillStyle={props.fillStyle} | ||
pointStyle={props.pointStyle} | ||
strokeStyle={props.strokeStyle} /> | ||
</Map> | ||
</Peripleo> | ||
) | ||
|
||
}; | ||
|
||
type CoreDataPlaceLayerProps = { | ||
uri: string; | ||
fillStyle?: object; | ||
pointStyle?: object; | ||
strokeStyle?: object; | ||
}; | ||
|
||
export const CoreDataPlaceLayer = (props: CoreDataPlaceLayerProps) => { | ||
|
||
const [place, setPlace] = useState<FeatureCollection | undefined>(undefined); | ||
|
||
useEffect(() => { | ||
fetch(props.uri) | ||
.then(res => res.json()) | ||
.then(data => { | ||
const place = { | ||
...data, | ||
properties: { | ||
...data.properties, | ||
record_id: data.record_id | ||
} | ||
}; | ||
|
||
setPlace({ | ||
type: 'FeatureCollection', | ||
features: [place] | ||
}); | ||
}); | ||
}, [props.uri]) | ||
|
||
return place && ( | ||
<> | ||
<PulsingMarkerLayer | ||
id="current" | ||
data={place} /> | ||
|
||
<MixedGeoJSONLayer | ||
id={props.uri} | ||
data={place} | ||
fillStyle={props.fillStyle || DEFAULT_FILL_STYLE} | ||
strokeStyle={props.strokeStyle || DEFAULT_STROKE_STYLE} | ||
pointStyle={props.pointStyle || DEFAULT_POINT_STYLE} /> | ||
</> | ||
) | ||
|
||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
export const DEFAULT_POINT_STYLE = { | ||
'type': 'circle', | ||
'paint': { | ||
'circle-radius': [ | ||
'interpolate', | ||
['linear'], | ||
['number', ['get','point_count'], 1 ], | ||
0, 4, | ||
10, 14 | ||
], | ||
'circle-stroke-width': 1, | ||
'circle-color': [ | ||
'case', | ||
['boolean', ['feature-state', 'hover'], false], | ||
'#3b62ff', | ||
'#ff623b' | ||
], | ||
'circle-stroke-color': '#8d260c' | ||
} | ||
}; | ||
|
||
export const DEFAULT_FILL_STYLE = { | ||
'type': 'fill', | ||
'paint': { | ||
'fill-color': '#ff623b', | ||
'fill-opacity': 0.2 | ||
} | ||
} | ||
|
||
export const DEFAULT_STROKE_STYLE = { | ||
'type': 'line', | ||
'paint': { | ||
'line-color': '#ff623b', | ||
'line-opacity': 0.6 | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { CoreDataPlace } from '../../../geospatial/src/components/CoreDataPlace'; | ||
|
||
export default { | ||
title: 'Components/Geospatial/CoreDataPlace', | ||
component: CoreDataPlace | ||
}; | ||
|
||
|
||
export const Default = () => ( | ||
<CoreDataPlace | ||
mapStyle={`https://api.maptiler.com/maps/basic-v2/style.json?key=${process.env.REACT_APP_MAP_TILER_KEY}`} | ||
placeURI="https://core-data-cloud-staging-2c51db0617a5.herokuapp.com/core_data/public/places/3aaf97a4-7052-4e2c-9056-4f4146ef0c87?project_ids=10" /> | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should these be in
dependencies
instead ofdevDependencies
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done!