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

Minimal 'CoreDataPlace' Widget Example #247

Closed
wants to merge 8 commits into from
Closed
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
92 changes: 92 additions & 0 deletions packages/geospatial/src/components/CoreDataPlace.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
import React, { useEffect, useState } from 'react';
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 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.

Copy link
Collaborator Author

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.

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';

interface CoreDataPlaceProps {

mapStyle: string | object;

placeURI: string;

fillStyle?: object;

pointStyle?: object;

strokeStyle?: object;

}

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>
)

}

interface 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
}
} as Feature;

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} />
</>
)

}

export default CoreDataPlace;
36 changes: 36 additions & 0 deletions packages/geospatial/src/components/CoreDataPlaceStyles.js
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
}
}
1 change: 1 addition & 0 deletions packages/geospatial/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@
// Components
export { default as DrawControl } from './components/DrawControl';
export { default as MapDraw } from './components/MapDraw';
export { default as CoreDataPlace } from './components/CoreDataPlace';
2 changes: 2 additions & 0 deletions packages/storybook/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
"@babel/preset-flow": "^7.22.5",
"@babel/preset-react": "^7.22.5",
"@faker-js/faker": "^8.0.2",
"@peripleo/maplibre": "^0.3.1",
Copy link
Collaborator

Choose a reason for hiding this comment

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

Should we also add these dependencies to the geospatial package?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Of course - done!

"@peripleo/peripleo": "^0.3.1",
"@storybook/addon-a11y": "^7.0.26",
"@storybook/addon-actions": "^7.0.26",
"@storybook/addon-docs": "^7.0.26",
Expand Down
13 changes: 13 additions & 0 deletions packages/storybook/src/geospatial/CoreDataPlace.stories.js
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" />
)
Loading