-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
3,814 additions
and
4,530 deletions.
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
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,79 @@ | ||
import React, { useEffect, useState } from 'react'; | ||
import { Feature, FeatureCollection, 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} /> | ||
</> | ||
) | ||
|
||
}; |
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
13 changes: 13 additions & 0 deletions
13
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,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" /> | ||
) |
Oops, something went wrong.