1
+ async function loadMap ( ) {
2
+ const { Map, InfoWindow} = await google . maps . importLibrary ( "maps" ) ;
3
+ const { AdvancedMarkerElement, PinElement} = await google . maps . importLibrary ( "marker" ) ;
4
+ const infoWindow = new InfoWindow ( ) ;
5
+
6
+ let centerLat = 7.873054 ;
7
+ let centerLng = 80.771797 ;
8
+
9
+ /* Make the map focus into Sri Lanka */
10
+ const map = new Map ( document . getElementById ( "map" ) , {
11
+ zoom : 10 ,
12
+ center : { lat : centerLat , lng : centerLng } ,
13
+ mapId : "DEMO_MAP_ID" ,
14
+ } ) ;
15
+
16
+ await fetch ( 'http://localhost:8080/home-geolocation-technicians' )
17
+ . then ( response => response . json ( ) )
18
+ . then ( technicians => {
19
+ console . log ( technicians ) ;
20
+ technicians . forEach ( technician => {
21
+ const pin = new PinElement ( {
22
+ background : "#0b7ff6" ,
23
+ borderColor : "#025ab8" ,
24
+ glyphColor : "#235c9a" ,
25
+ } ) ;
26
+ const marker = new AdvancedMarkerElement ( {
27
+ position : { lat : parseFloat ( technician [ 'latitude' ] ) , lng : parseFloat ( technician [ 'longitude' ] ) } ,
28
+ map : map ,
29
+ title : `${ technician . fname } ${ technician . lname } ` ,
30
+ content : pin . element ,
31
+ //gmpClikable: true,
32
+ } ) ;
33
+ marker . addListener ( "click" , ( { domEvent, latLng} ) => {
34
+ const { target} = domEvent ;
35
+
36
+ infoWindow . close ( ) ;
37
+ infoWindow . setContent ( marker . title ) ;
38
+ infoWindow . open ( marker . map , marker ) ;
39
+ } ) ;
40
+ } ) ;
41
+ } )
42
+ . catch ( error => console . error ( 'Error fetching technician geo co-ordinates!' ) ) ;
43
+
44
+ await fetch ( 'http://localhost:8080/home-geolocation-service-centres' )
45
+ . then ( response => response . json ( ) )
46
+ . then ( serviceCentres => {
47
+ console . log ( serviceCentres ) ;
48
+ serviceCentres . forEach ( serviceCentre => {
49
+ const marker = new AdvancedMarkerElement ( {
50
+ position : { lat : parseFloat ( serviceCentre [ 'latitude' ] ) , lng : parseFloat ( serviceCentre [ 'longitude' ] ) } ,
51
+ map : map ,
52
+ title : `${ serviceCentre [ 'name' ] } ` ,
53
+ } ) ;
54
+ marker . addListener ( "click" , ( { domEvent, latLng} ) => {
55
+ const { target} = domEvent ;
56
+
57
+ infoWindow . close ( ) ;
58
+ infoWindow . setContent ( marker . title ) ;
59
+ infoWindow . open ( marker . map , marker ) ;
60
+ } ) ;
61
+ } ) ;
62
+ } )
63
+ . catch ( error => console . error ( 'Error fetching service centres geo co-ordinates!' ) ) ;
64
+
65
+ }
66
+
67
+ window . onload = loadMap ;
0 commit comments