Skip to content

Commit 10cbb9a

Browse files
committed
Update README.md
1 parent 0ac211d commit 10cbb9a

File tree

1 file changed

+52
-1
lines changed

1 file changed

+52
-1
lines changed

README.md

Lines changed: 52 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ const useStyles = makeStyles({
111111

112112
export default function SimpleCard() {
113113
const classes = useStyles();
114-
114+
115115
return (
116116
<Card>
117117
<CardContent>
@@ -253,3 +253,54 @@ export default function ForecastLocationDetails({ woeid }) {
253253
);
254254
}
255255
```
256+
257+
## Setting up a component to display a map
258+
A map would be a great addition to our weather app. Since MetaWeather provides the latitude and longitude of a location, it would be nice to focus that location on a map.
259+
260+
It would be a bit awkward to make plans for a nice weekend BBQ based on the forecast for [Lisbon, Florida](https://en.wikipedia.org/wiki/Lisbon,_Florida) or some other [Lisbon](https://en.wikipedia.org/wiki/Lisbon_(disambiguation)#United_States), just in the USA.
261+
262+
As you can imagine, there are quite a few components at our disposal, and we suggest the usage of [react-mapbox-gl](https://github.com/alex3165/react-mapbox-gl).
263+
It is quite simple to integrate and to display a point at a certain latitude and longitude.
264+
Feel free to play with their [demos](https://alex3165.github.io/react-mapbox-gl/demos) to get a feeling about how it works and look around their [documentation](https://alex3165.github.io/react-mapbox-gl/documentation).
265+
The most important components to focus upon a location would be `ReactMapboxGl`, `Layer` and `Feature`.
266+
267+
We can install it into our project with:
268+
```bash
269+
npm install react-mapbox-gl mapbox-gl
270+
```
271+
272+
273+
In order to use react-mapbox-gl, we will need an accessToken, that we already requested:
274+
275+
```
276+
pk.eyJ1IjoicHNpbHZhaWMiLCJhIjoiY2tobmI5YTRlMDAzbTMxcGV6NDk3ZHNrdCJ9.mpgz1tj9j8cLrhrsZ5hlhw
277+
```
278+
279+
The snippet bellow we displays how we can create a Map, with the provide accessToken, that will focus upon Lisbon, Portugal and place a small marker:
280+
281+
```JavaScript
282+
283+
import ReactMapboxGl, { Layer, Feature } from 'react-mapbox-gl';
284+
import 'mapbox-gl/dist/mapbox-gl.css';
285+
286+
const Map = ReactMapboxGl({
287+
accessToken:
288+
'pk.eyJ1IjoicHNpbHZhaWMiLCJhIjoiY2tobmI5YTRlMDAzbTMxcGV6NDk3ZHNrdCJ9.mpgz1tj9j8cLrhrsZ5hlhw'
289+
});
290+
291+
function MyMap() {
292+
return (
293+
<Map
294+
style="mapbox://styles/mapbox/streets-v9"
295+
containerStyle={{
296+
height: '100%',
297+
width: '100%'
298+
}}
299+
>
300+
<Layer type="symbol" id="marker" layout={{ 'icon-image': 'marker-15' }}>
301+
<Feature coordinates={[38.725670, -9.150370]} />
302+
</Layer>
303+
</Map>
304+
)
305+
}
306+
```

0 commit comments

Comments
 (0)