Closed Waidhoferj closed 3 years ago
3 hrs
Inputting data into a GeoJSONLayer
is more performant than using individual pins on the map. Simple GeoJSON for our artwork could look like this:
{
"type": "FeatureCollection",
"features" : [
{
"type": "Feature",
"id": 1,
"geometry": {
"type": "Point",
"coordinates": [12, 23]
},
"properties": {
artworks: [...]
}
}
]
}
Where:
Until we can grab data from the backend, you can put this data in a art-areas.json
file and import it into your React component.
Before displaying this on the map, you'll need an api token from MapBox. You can sign up here (totally free)
Once you have your default map set up, you can display the geojson like this:
import artAreasJSON from "art-areas.json"
...
<Map>
<GeoJSONLayer
data={artAreasJSON}
fillLayout={{ visibility: "visible" }}
fillPaint={{
"fill-color": "blue",
"fill-opacity": 0.4,
}}
/>
...
</Map>
``
To respond to click events, add this listener to the geojson layer:
circleOnClick={handleClick}
...
function handleClick(e) {
// Respond to click
}
Then you can pass the targeted latitude and longitude to the compass.
Took 3 hours
Highly recommend using react-mapbox-gl