Skip to content

Commit 8e987f9

Browse files
committed
render markers on the map
1 parent b0de500 commit 8e987f9

File tree

5 files changed

+64
-2
lines changed

5 files changed

+64
-2
lines changed

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,10 @@ EXPO_PUBLIC_MAPBOX_KEY=pk.ey123...
6060

6161
-------------------- First Commit --------------------
6262

63+
9 - Create a json file with lat and long of scooters and update Map component to render scooter icons on the map with those lat and long
64+
65+
-------------------- Second Commit --------------------
66+
6367
## Credit
6468

6569
[Building an e-Scooter App with React Native and Mapbox](https://www.youtube.com/watch?v=uxj8jnlooP8)

assets/pin.png

5.51 KB
Loading

components/Map.tsx

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,36 @@
1-
import Mapbox, { Camera, LocationPuck, MapView } from '@rnmapbox/maps';
1+
import Mapbox, {
2+
Camera,
3+
LocationPuck,
4+
MapView,
5+
ShapeSource,
6+
SymbolLayer,
7+
Images,
8+
} from '@rnmapbox/maps';
9+
import { featureCollection, point } from '@turf/helpers';
10+
11+
import pin from '~/assets/pin.png';
12+
import scooters from '~/data/scooters.json';
213

314
Mapbox.setAccessToken(process.env.EXPO_PUBLIC_MAPBOX_KEY || '');
415

516
export default function Map() {
17+
const points = scooters.map((scooter) => point([scooter.long, scooter.lat]));
618
return (
719
<MapView style={{ flex: 1 }} styleURL="mapbox://styles/mapbox/dark-v11">
8-
<Camera followZoomLevel={16} followUserLocation />
20+
<Camera followZoomLevel={12} followUserLocation />
921
<LocationPuck puckBearingEnabled puckBearing="heading" pulsing={{ isEnabled: true }} />
22+
<ShapeSource id="scooters" shape={featureCollection(points)}>
23+
<SymbolLayer
24+
id="scooter-icons"
25+
style={{
26+
iconImage: 'pin',
27+
iconSize: 0.5,
28+
iconAllowOverlap: true,
29+
iconAnchor: 'bottom',
30+
}}
31+
/>
32+
<Images images={{ pin }} />
33+
</ShapeSource>
1034
</MapView>
1135
);
1236
}

data/scooters.json

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
[
2+
{ "id": 1, "long": -122.4115, "lat": 37.795 },
3+
{ "id": 2, "long": -122.395, "lat": 37.793 },
4+
{ "id": 3, "long": -122.4135, "lat": 37.797 },
5+
{ "id": 4, "long": -122.4145, "lat": 37.774 },
6+
{ "id": 5, "long": -122.4165, "lat": 37.78 },
7+
{ "id": 6, "long": -122.423, "lat": 37.777 },
8+
{ "id": 7, "long": -122.414, "lat": 37.776 },
9+
{ "id": 8, "long": -122.425, "lat": 37.79 },
10+
{ "id": 9, "long": -122.427, "lat": 37.795 },
11+
{ "id": 10, "long": -122.418, "lat": 37.796 },
12+
{ "id": 11, "long": -122.404, "lat": 37.799 },
13+
{ "id": 12, "long": -122.423, "lat": 37.799 },
14+
{ "id": 13, "long": -122.413, "lat": 37.796 },
15+
{ "id": 14, "long": -122.414, "lat": 37.795 },
16+
{ "id": 15, "long": -122.414, "lat": 37.779 },
17+
{ "id": 16, "long": -122.415, "lat": 37.784 },
18+
{ "id": 17, "long": -122.43, "lat": 37.784 },
19+
{ "id": 18, "long": -122.426, "lat": 37.778 },
20+
{ "id": 19, "long": -122.432, "lat": 37.798 },
21+
{ "id": 20, "long": -122.435, "lat": 37.786 },
22+
{ "id": 21, "long": -122.417, "lat": 37.785 },
23+
{ "id": 22, "long": -122.407, "lat": 37.775 },
24+
{ "id": 23, "long": -122.406, "lat": 37.784 },
25+
{ "id": 24, "long": -122.415, "lat": 37.795 },
26+
{ "id": 25, "long": -122.424, "lat": 37.792 },
27+
{ "id": 26, "long": -122.435, "lat": 37.782 },
28+
{ "id": 27, "long": -122.425, "lat": 37.794 },
29+
{ "id": 28, "long": -122.414, "lat": 37.772 },
30+
{ "id": 29, "long": -122.406, "lat": 37.785 },
31+
{ "id": 30, "long": -122.4, "lat": 37.775 }
32+
]

index.d.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
declare module '*.png';
2+
declare module '*.jpg';

0 commit comments

Comments
 (0)