-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwebcamsjs2.js
More file actions
123 lines (107 loc) · 3.56 KB
/
webcamsjs2.js
File metadata and controls
123 lines (107 loc) · 3.56 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
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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
var map;
var openedInfoWindow = null;
function initMap() {
map = new google.maps.Map(document.getElementById('map'), {
center: {lat: 38.987200, lng: -76.942765},
zoom: 16
});
//Add text to main Webcam page
addMainBoxText();
//loops through all of webcams stored in webcamlist javascript array
for(var i = 0; i < cameras.length; i++){
var camera = cameras[i];
if(camera[4] === 'unsecured'){
makeMarker(camera, 'survcam_green.png');
}else{
makeMarker(camera, 'survcam_red.png');
}
}
//Webcams without location and Story
var marker = new google.maps.Marker({
position: {lat: unknownLocationCameras[2],
lng: unknownLocationCameras[3]},
map: map,
icon: {url: 'questionmark4.png',
anchor: new google.maps.Point(25, 25)},
title: unknownLocationCameras[0]
});
//Not using functions described below because this marker acts differently
var infowindow = new google.maps.InfoWindow({
content: unknownLocationCameras[1],
maxWidth: 300
//Could add max height later
});
//Open storywindow upon loading the page and intialize first use settings
infowindow.open(map, marker);
openedInfoWindow = infowindow;
google.maps.event.addListener(map, 'click', function() {
infowindow.close();
});
//this code is for everytime besides the first time, the story window is
//opened.
google.maps.event.addListener(marker, "click", function(){
//closes last opened info window
if (openedInfoWindow != null) {
openedInfoWindow.close();
};
//opens new info window (Ver. 1&2 just have this)
infowindow.open(map, marker);
//update current info window
openedInfoWindow = infowindow;
//let program know that there are no opened windows after one is closed
google.maps.event.addListener(infowindow, 'closeclick', function() {
openedInfoWindow = null;
});
//closes info window when map is pressed
google.maps.event.addListener(map, 'click', function() {
infowindow.close();
});
});
}
function makeMarker(dataArr, image){
var marker = new google.maps.Marker({
position: {lat: dataArr[2],
lng: dataArr[3]},
map: map,
icon: {url: image, anchor: new google.maps.Point(25, 25)},
title: dataArr[0]
});
var contentString = dataArr[0] + '<br/>' +
dataArr[1];
attachMessage(marker,contentString);
}
//attaches message argument to marker argument
function attachMessage(marker, message) {
var infowindow = new google.maps.InfoWindow({
content: message,
maxWidth: 330
});
google.maps.event.addListener(marker, "click", function(){
//closes last opened info window
if (openedInfoWindow != null){
openedInfoWindow.close();
};
//opens new info window (Ver. 1&2 just have this)
infowindow.open(map, marker);
//update current info window
openedInfoWindow = infowindow;
//let program know that there are no opened windows after one is closed
google.maps.event.addListener(infowindow, 'closeclick', function() {
openedInfoWindow = null;
});
//closes info window when map is pressed
google.maps.event.addListener(map, 'click', function() {
infowindow.close();
});
});
}
function addMainBoxText() {
var myTitle = document.createElement('h1');
myTitle.style.color = 'black';
myTitle.style.fontSize = 'medium';
myTitle.innerHTML = 'UMD Campus Webcams '+
'- Click a camera to begin - Updated 2/22/2016';
var myTextDiv = document.createElement('div');
myTextDiv.appendChild(myTitle);
map.controls[google.maps.ControlPosition.BOTTOM_CENTER].push(myTextDiv);
}