11window . loadMap = function ( data ) {
22 console . log ( data ) ;
33 mapboxgl . accessToken = 'pk.eyJ1Ijoic2Fubmx5bm5odHVuLWRldiIsImEiOiJjbG9ia2FoeGkwY25iMmpvNGJ4MDUyY3ZlIn0.FpDwK1yUPLSg_FPnLe_uzQ' ;
4- const geojson = {
5- 'type' : 'FeatureCollection' ,
6- 'features' : [
7- {
8- 'type' : 'Feature' ,
9- 'properties' : {
10- 'message' : 'Foo' ,
11- 'iconSize' : [ 60 , 60 ]
12- } ,
13- 'geometry' : {
14- 'type' : 'Point' ,
15- 'coordinates' : [ - 66.324462 , - 16.024695 ]
16- }
17- } ,
18- {
19- 'type' : 'Feature' ,
20- 'properties' : {
21- 'message' : 'Bar' ,
22- 'iconSize' : [ 50 , 50 ]
23- } ,
24- 'geometry' : {
25- 'type' : 'Point' ,
26- 'coordinates' : [ - 61.21582 , - 15.971891 ]
27- }
28- } ,
29- {
30- 'type' : 'Feature' ,
31- 'properties' : {
32- 'message' : 'Baz' ,
33- 'iconSize' : [ 40 , 40 ]
34- } ,
35- 'geometry' : {
36- 'type' : 'Point' ,
37- 'coordinates' : [ - 63.292236 , - 18.281518 ]
38- }
39- } ,
40- {
41- 'type' : 'Feature' ,
42- 'properties' : {
43- 'message' : 'Baz' ,
44- 'iconSize' : [ 40 , 40 ]
45- } ,
46- 'geometry' : {
47- 'type' : 'Point' ,
48- 'coordinates' : [ 94.90412 , 21.16295 ]
49- }
50- }
51- ]
52- } ;
4+ const geojson = JSON . parse ( data ) ;
535
546 const map = new mapboxgl . Map ( {
557 container : 'map' ,
568 // Choose from Mapbox's core styles, or make your own style with Mapbox Studio
579 style : 'mapbox://styles/mapbox/streets-v12' ,
58- center : [ 94.7758353 , 21.2009934 ] ,
59- zoom : 5
10+ center : [ 94.905 , 21.160 ] ,
11+ zoom : 13
6012 } ) ;
6113
6214 // Add markers to the map.
63- for ( const marker of geojson . features ) {
15+ for ( const marker of geojson ) {
6416 // Create a DOM element for each marker.
6517 const el = document . createElement ( 'div' ) ;
66- //const width = marker.properties.iconSize[0];
67- //const height = marker.properties.iconSize[1];
68- const width = 60 ;
69- const height = 60 ;
18+ const width = 40 ;
19+ const height = 40 ;
7020 el . className = 'marker' ;
7121 el . style . backgroundImage = `url(images/pagoda.png)` ;
7222 el . style . width = `${ width } px` ;
7323 el . style . height = `${ height } px` ;
7424 el . style . backgroundSize = '100%' ;
7525
7626 el . addEventListener ( 'click' , ( ) => {
77- window . alert ( marker . properties . message ) ;
27+ window . alert ( marker . PagodaMmName ) ;
7828 } ) ;
7929
30+
31+ let coordinates = [ ] ;
32+ coordinates . push ( marker . Longitude ) ;
33+ coordinates . push ( marker . Latitude ) ;
8034 // Add markers to the map.
8135 new mapboxgl . Marker ( el )
82- . setLngLat ( marker . geometry . coordinates )
36+ . setLngLat ( coordinates )
8337 . addTo ( map ) ;
8438 }
8539}
0 commit comments