Waidhoferj / CSC-308-309-Project

3 stars 2 forks source link

Simple Map Screen #4

Closed Waidhoferj closed 3 years ago

Waidhoferj commented 3 years ago

Highly recommend using react-mapbox-gl

Waidhoferj commented 3 years ago

3 hrs

Waidhoferj commented 3 years ago

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.

Waidhoferj commented 3 years ago

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>

``
Waidhoferj commented 3 years ago

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.

gwholland3 commented 3 years ago

Took 3 hours