-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
227 lines (223 loc) · 6.41 KB
/
main.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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
<<<<<<< HEAD
var userArray = [];
=======
var currentCircles = [];
var drawArray = [];
var truckArray = [];
var notifyArray = [];
// Person class with relevant marker data and unique, possibly hilarious name
var people = [];
var Person = function (where, startTime, endTime, randName) {
this.where = where;
this.startTime = startTime;
this.endTime = endTime;
this.randName = randName;
};
var Foodtruck = function (where, truckName) {
this.truckName = truckName;
this.where = where;
}
var Notify = function (randName, truckName) {
this.randName = randName;
this.truckName = truckName;
}
// Function that gets the start time and end time and returns a properly formatted time stamp
start = function () {
var begin = $('.ui-rangeSlider-leftLabel').find('.ui-rangeSlider-label-value').html();
return moment(begin, "h:mma")._d;
};
end = function() {
var end = $('.ui-rangeSlider-rightLabel').find('.ui-rangeSlider-label-value').html();
return moment(end, "h:mma")._d;
};
>>>>>>> master
function initialize() {
var mapOptions = {
center: new google.maps.LatLng(37.77, -122.42),
zoom: 13,
disableDefaultUI: true,
zoomControl: true,
<<<<<<< HEAD
styles: [ { featureType: "poi", elementType: "labels", stylers: [ { visibility: "off" } ] } ]
};
var map = new google.maps.Map(document.getElementById("map-canvas"),
mapOptions);
var addCircle = function(e) {
var myLatlng = e.latLng;
new google.maps.Circle({
map: map,
fillColor: "#F00",
center: myLatlng,
radius: 800,
fillOpacity: .05,
clickable: false,
strokeColor: '#FFF',
strokeOpacity: 0
})
};
//Slider init with current hour to 4 hours from now
$("#slider-el").rangeSlider({
bounds: {
min: 0,
max: 240
},
arrows: true,
defaultValues: {
min: 30,
max: 75
},
range: {
min: 45},
step: 15,
//This adjusts the display of the tooltip values
formatter: function(val) {
if (val===0) {
return moment().format("h:mma");
}
else {
return moment().add('minutes', val).format("h:mma")
}
}
});
// This is the resize listener that makes maps responsive
google.maps.event.addDomListener(window, "resize", function() {
var center = map.getCenter();
google.maps.event.trigger(map, "resize");
map.setCenter(center);
});
google.maps.event.addDomListener(map, 'click', addCircle);
=======
styles:
[
{ featureType: "poi",
elementType: "labels",
stylers:
[
{ visibility: "off" }
]
}
]
};
var map = new google.maps.Map(document.getElementById("map-canvas"),
mapOptions);
var addPerson = function(e) {
var myLatlng = e.latLng;
new google.maps.Circle({
map: map,
fillColor: "#F00",
center: myLatlng,
radius: 800,
fillOpacity: .05,
clickable: false,
strokeColor: '#FFF',
strokeOpacity: 0
});
var person = new Person (myLatlng, start(), end(), chance.name());
people.push(person);
};
var image = {
url: 'truck.png',
origin: new google.maps.Point(0,0),
anchor: new google.maps.Point(20, 20)
};
var addTruck = function(e) {
var myLatlng = e.latLng;
new google.maps.Marker({
map: map,
icon: image,
draggable: true,
position: myLatlng
});
var trucks = new Foodtruck (myLatlng, chance.last());
truckArray.push(trucks)
};
// This function compares foodtruck to users and notifies if < 1000 meters and messes with notify
var truckDistanceCheck = function() {
for (var i = 0; i < people.length; i++) {
var distanceBetween = google.maps.geometry.spherical.computeDistanceBetween(truckArray[0].where, people[i].where);
console.log(distanceBetween);
if (distanceBetween < 1000) {
var notifyLoop = new Notify (people[i].randName, truckArray[0].truckName);
notifyArray.push(notifyLoop);
}
else {
console.log("sorry");
}
}
$('title').text(notifyArray.length + " new");
$("#notify-label").text(notifyArray.length);
$("#notify-label").addClass('active');
truckArray.splice(0,1);
};
// Reset the notify field and pop up a div with the notify information
var notifyReset = function () {
$('#notify-label').removeClass("active");
$('#notify-label').text(0);
$('title').text("Google Maps Demo");
notifyArray = [];
}
//Slider init with current hour to 4 hours from now
$("#slider-el").rangeSlider({
bounds: {
min: 0,
max: 240
},
arrows: true,
defaultValues: {
min: 30,
max: 75
},
range: {
min: 45},
step: 15,
//This adjusts the display of the tooltip values
formatter: function(val) {
if (val===0) {
return moment().format("h:mma");
}
else {
return moment().add('minutes', val).format("h:mma")
}
}
});
// event listeners
$("#notify-label").click(notifyReset);
google.maps.event.addDomListener(map, 'rightclick', addTruck);
google.maps.event.addDomListener(map, 'rightclick', truckDistanceCheck);
google.maps.event.addDomListener(map, 'click', addPerson);
google.maps.event.addDomListener(window, "resize", function() {
var center = map.getCenter();
google.maps.event.trigger(map, "resize");
map.setCenter(center);
});
$("#slider-el").bind("userValuesChanged", function(e, data){
drawArray = dummyData.filter(function (item) {
var rangeBegin = start();
var rangeEnd = end();
var timeBegin = item.startTime;
var timeEnd = item.endTime;
if (moment(timeEnd).isAfter(rangeBegin) && moment(timeBegin).isBefore(rangeEnd))
return true;
});
for (var i = 0; i < currentCircles.length; i++) {
currentCircles[i].setMap(null);
};
currentCircles = [];
for (var i = 0; i < drawArray.length; i++) {
var myLatlng = drawArray[i].where;
var circles = new google.maps.Circle ({
map: map,
fillColor: "#F00",
center: new google.maps.LatLng(drawArray[i].where.d,drawArray[i].where.e),
radius: 800,
fillOpacity: .05,
clickable: false,
strokeColor: '#FFF',
strokeOpacity: 0
})
currentCircles.push(circles);
};
});
>>>>>>> master
}
google.maps.event.addDomListener(window, 'load', initialize);