Skip to content

Commit

Permalink
Merge 75fdb3a into ab85a27
Browse files Browse the repository at this point in the history
  • Loading branch information
rsimon authored Jan 30, 2024
2 parents ab85a27 + 75fdb3a commit c42abdb
Show file tree
Hide file tree
Showing 7 changed files with 3,814 additions and 4,530 deletions.
2 changes: 2 additions & 0 deletions packages/geospatial/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
},
"devDependencies": {
"@performant-software/webpack-config": "^1.0.0",
"@peripleo/maplibre": "^0.3.1",
"@peripleo/peripleo": "^0.3.1",
"react": "^18.2.0",
"react-dom": "^18.2.0"
}
Expand Down
79 changes: 79 additions & 0 deletions packages/geospatial/src/components/CoreDataPlace.js
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} />
</>
)

};
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",
"@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

0 comments on commit c42abdb

Please sign in to comment.