-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathgoogle-map.js
More file actions
73 lines (60 loc) · 1.48 KB
/
google-map.js
File metadata and controls
73 lines (60 loc) · 1.48 KB
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
/* google-map.js - Google Maps JS Functions
*
* Currently this file is not maintained. The project has switched to using
* leaflet.js. This code is here for reference and may actually still work.
*
* 2020/09/05 Stephen Houser, N1SH
*/
/* Required Map functions:
*
* map = createMap(mapDivName)
* marker = createMarker(latitude, longitude, popupText)
* removeMarker(marker)
* removeAllMarkers()
*/
var _map = null;
var _markers = [];
var _openInfoWindow = null;
function createMap(mapDivName) {
_map = new google.maps.Map(document.getElementById(mapDivName), {
center: { lat: 43.686292, lng: -70.549876 },
zoom: 3,
mapTypeId: "terrain"
});
_markers = [];
return _map;
}
function createMarker(latitude, longitude, popupText) {
let marker = new google.maps.Marker({
title: name,
position: new google.maps.LatLng(latitude, longitude),
map: _map
});
marker.addListener('click', function () {
if (_openInfoWindow !== null) {
_openInfoWindow.close();
}
let infowindow = new google.maps.InfoWindow({
content: popupText
});
infowindow.open(_map, marker);
_openInfoWindow = infowindow;
});
_markers.push(marker);
return marker;
}
function removeMarker(marker) {
if (marker !== null) {
var markerIndex = _markers.indexOf(marker);
if (markerIndex > -1) {
_markers.splice(markerIndex, 1);
}
marker.setMap(null);
}
}
function removeAllMarkers() {
for (var i = 0; i < _markers.length; i++) {
_markers[i].setMap(null);
}
_markers = [];
}