-
Notifications
You must be signed in to change notification settings - Fork 35
/
Copy pathapp.js
99 lines (61 loc) · 1.87 KB
/
app.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
function initMap(){
// Map option
var options = {
center: {lat: 38.3460 , lng:-0.4907 },
zoom: 10
}
//New Map
map = new google.maps.Map(document.getElementById("map"),options)
//listen for click on map location
google.maps.event.addListener(map, "click", (event) => {
//add Marker
addMarker({location:event.latLng});
})
//Marker
/*
const marker = new google.maps.Marker({
position:{lat: 37.9922, lng: -1.1307},
map:map,
icon:"https://img.icons8.com/nolan/2x/marker.png"
});
//InfoWindow
const detailWindow = new google.maps.InfoWindow({
content: `<h2>Murcia City</h2>`
});
marker.addListener("mouseover", () =>{
detailWindow.open(map, marker);
})
*/
//Add Markers to Array
let MarkerArray = [ {location:{lat: 37.9922, lng: -1.1307},
imageIcon: "https://img.icons8.com/nolan/2x/marker.png",
content: `<h2>Murcia City</h2>`},
{location:{lat: 39.4699, lng: -0.3763}},
{location:{lat: 38.5411, lng: -0.1225},content: `<h2>Benidorm City</h2>` }
]
// loop through marker
for (let i = 0; i < MarkerArray.length; i++){
addMarker(MarkerArray[i]);
}
// Add Marker
function addMarker(property){
const marker = new google.maps.Marker({
position:property.location,
map:map,
//icon: property.imageIcon
});
// Check for custom Icon
if(property.imageIcon){
// set image icon
marker.setIcon(property.imageIcon)
}
if(property.content){
const detailWindow = new google.maps.InfoWindow({
content: property.content
});
marker.addListener("mouseover", () =>{
detailWindow.open(map, marker);
})
}
}
}