-
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
Closed
Closed
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
6588d5e
Minimal 'CoreDataPlace' widget example
rsimon 91f0579
Added component to index.js
rsimon 720e7d3
Attempts to fix build issues
rsimon 75fdb3a
Added missing @peripleo deps + changed from interface to type
rsimon 924b73f
Various import fixes
rsimon f45f162
Build tweaks
rsimon 429fe76
First working configuration (yay)
rsimon 6b510c3
Cleanup: moved CSS into component
rsimon File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,6 +10,8 @@ | |
}, | ||
"dependencies": { | ||
"@mapbox/mapbox-gl-draw": "^1.4.3", | ||
"@peripleo/maplibre": "^0.3.2", | ||
"@peripleo/peripleo": "^0.3.2", | ||
"@turf/turf": "^6.5.0", | ||
"mapbox-gl": "npm:[email protected]", | ||
"maplibre-gl": "^3.5.2", | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
.p6o-map-container { | ||
height: 100%; | ||
width: 100%; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
// @flow | ||
|
||
import React, { useEffect, useState } from 'react'; | ||
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'; | ||
|
||
import './CoreDataPlace.css'; | ||
import '@peripleo/maplibre/peripleo-maplibre.css'; | ||
import '@peripleo/peripleo/default-theme'; | ||
|
||
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} /> | ||
</> | ||
) | ||
|
||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
packages/storybook/src/geospatial/CoreDataPlace.stories.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import { CoreDataPlace } from '../../../geospatial/src/components/CoreDataPlace'; | ||
|
||
export default { | ||
title: 'Components/Geospatial/CoreDataPlace', | ||
component: CoreDataPlace | ||
}; | ||
|
||
const style = { | ||
"version": 8, | ||
"sources": { | ||
"osm": { | ||
"type": "raster", | ||
"tiles": ["https://a.tile.openstreetmap.org/{z}/{x}/{y}.png"], | ||
"tileSize": 256, | ||
"attribution": "© OpenStreetMap Contributors", | ||
"maxzoom": 19 | ||
} | ||
}, | ||
"layers": [ | ||
{ | ||
"id": "osm", | ||
"type": "raster", | ||
"source": "osm" | ||
} | ||
] | ||
}; | ||
|
||
export const Default = () => ( | ||
<div style={{ width: '100%', height: '300px' }}> | ||
<CoreDataPlace | ||
mapStyle={style} | ||
placeURI="https://core-data-cloud-staging-2c51db0617a5.herokuapp.com/core_data/public/places/3aaf97a4-7052-4e2c-9056-4f4146ef0c87?project_ids=10" /> | ||
</div> | ||
) |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
I think if you add the
// @flow
annotation to the top of this file, it will like the syntax a lot more. There's also a few ESLint errors on the formatting, but less concerned about those.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, 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.