File tree 3 files changed +89
-1
lines changed
3 files changed +89
-1
lines changed Original file line number Diff line number Diff line change @@ -3,12 +3,14 @@ import Map1 from './components/Map1'
3
3
import Map2 from './components/Map2'
4
4
import Map3 from './components/Map3'
5
5
import Map4 from './components/Map4'
6
+ import Map5 from './components/Map5'
7
+ import Map6 from './components/Map6'
6
8
7
9
function App ( ) {
8
10
9
11
return (
10
12
< >
11
- < Map3 />
13
+ < Map6 />
12
14
</ >
13
15
)
14
16
} ;
Original file line number Diff line number Diff line change
1
+ import React , { useEffect , useRef } from 'react' ;
2
+ import Mapbox from 'mapbox-gl' ;
3
+
4
+ import MapContainer from '../MapContainer'
5
+
6
+ let map = null ;
7
+ let marker = null ;
8
+
9
+ const Map5 = ( ) => {
10
+
11
+ Mapbox . accessToken = process . env . MAPBOX_API_KEY ;
12
+
13
+ const mapElement = useRef ( null ) ;
14
+
15
+ useEffect ( ( ) => {
16
+ map = new Mapbox . Map ( {
17
+ container : mapElement . current ,
18
+ style : 'mapbox://styles/mapbox/dark-v10' ,
19
+ zoom : 10 ,
20
+ center : [ 12.492285 , 41.890466 ]
21
+ } )
22
+ . on ( 'click' , event => handleMapClick ( event ) )
23
+
24
+ } , [ ] ) ;
25
+
26
+ const handleMapClick = event => {
27
+
28
+ let el = document . createElement ( 'div' ) ;
29
+ el . style . display = 'block' ;
30
+ el . style . height = '40px' ;
31
+ el . style . width = '40px' ;
32
+ el . style . backgroundImage = 'url("https://upload.wikimedia.org/wikipedia/commons/4/4b/McDonald%27s_logo.svg")' ;
33
+ el . style . backgroundSize = '40px 40px'
34
+ el . addEventListener ( 'click' , event => console . log ( "Heihei" ) )
35
+
36
+ const newMarker = new Mapbox . Marker ( el )
37
+ . setLngLat ( event . lngLat ) ;
38
+
39
+ if ( marker !== null ) { marker . remove ( ) } ;
40
+
41
+ newMarker . addTo ( map ) ;
42
+ marker = newMarker ;
43
+
44
+ } ;
45
+
46
+ return (
47
+ < >
48
+ < MapContainer ref = { mapElement } > </ MapContainer >
49
+ </ >
50
+ )
51
+ } ;
52
+
53
+ export default Map5 ;
Original file line number Diff line number Diff line change
1
+ import React , { useEffect , useRef } from 'react' ;
2
+ import Mapbox from 'mapbox-gl' ;
3
+
4
+ import MapContainer from '../MapContainer'
5
+
6
+ let map = null ;
7
+ let marker = null ;
8
+
9
+ const Map6 = ( ) => {
10
+
11
+ Mapbox . accessToken = process . env . MAPBOX_API_KEY ;
12
+
13
+ const mapElement = useRef ( null ) ;
14
+
15
+ useEffect ( ( ) => {
16
+ map = new Mapbox . Map ( {
17
+ container : mapElement . current ,
18
+ style : 'mapbox://styles/mapbox/streets-v11' ,
19
+ zoom : 5 ,
20
+ center : [ 12.492285 , 41.890466 ]
21
+ } )
22
+
23
+ } , [ ] ) ;
24
+
25
+
26
+ return (
27
+ < >
28
+ < MapContainer ref = { mapElement } > </ MapContainer >
29
+ </ >
30
+ )
31
+ } ;
32
+
33
+ export default Map6 ;
You can’t perform that action at this time.
0 commit comments