-
Notifications
You must be signed in to change notification settings - Fork 1
/
MAPscript.1.js
193 lines (156 loc) · 5.44 KB
/
MAPscript.1.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
var map;
var pos;
var heatmap;
var houston = { lat: 29.7604, lng: -95.3698 };
var nonhouston = { lat: -30, lng: -100 };
var zm = 10;
var markers = true;
var map_toggles;
var markerslist = [];
var numel = 0;
var rendercount = 0;
var needs_analysis
function makeURL(URL, params) {
return URL + "?" + Object
.keys(params)
.map(function(key) {
return key + "=" + encodeURIComponent(params[key])
})
.join("&")
}
function manageMap(params, coords, types){
if (types.length > 0){
if (types[0] == "needs_toggle"){
types.shift();
getNeeds(params, coords, types);
} else if (types[0] == "shelters_toggle"){
types.shift();
getShelters(params, coords, types);
} else {
types.shift();
}
} else {
heatmapVis(coords);
}
}
function updateMaps(){
map_toggles = [document.getElementById("needs_toggle"), document.getElementById("shelters_toggle")];
var active_maps = [];
console.log(map_toggles)
for (var i = 0; i < map_toggles.length; i++){
console.log("Toggle: ", map_toggles[i]);
if (map_toggles[i].checked){
active_maps.push(map_toggles[i].id);
}
}
console.log(active_maps);
console.log(map_toggles);
clearmap();
manageMap(pos, [], active_maps);
}
function getNeeds(params, coords, types) {
var testrequest = new XMLHttpRequest();
var requestURL = makeURL("https://api.harveyneeds.org/api/v1/needs", { "lat": params.lat, "lon": params.lng });
testrequest.open("GET", requestURL, true);
testrequest.responseType = "json";
testrequest.onreadystatechange = function() {
if (testrequest.readyState == 4) {
var needs = testrequest.response.needs;
needs = needs.map(function(point){
point["color"] = 'red-dot.png';
return point;
});
//var coordinates = needs.map(function(point) { return [point.latitude, point.longitude, 'red-dot.png'] });
coords = coords.concat(needs);
manageMap(params, coords, types);
}
};
testrequest.send();
}
function getShelters(params, coords, types) {
var testrequest = new XMLHttpRequest();
var requestURL = makeURL("https://api.harveyneeds.org/api/v1/shelters", { "lat": params.lat, "lon": params.lng });
testrequest.open("GET", requestURL, true);
testrequest.responseType = "json";
testrequest.onreadystatechange = function() {
if (testrequest.readyState == 4) {
var shelters = testrequest.response.shelters;
shelters = shelters.map(function(point){
point['color'] = 'blue-dot.png';
return point;
});
//var coordinates = shelters.map(function(point) { return [point.latitude, point.longitude, 'blue-dot.png', point.id, point.counts, point.shelter, point.address, point.city, point.pets, point.phone, point.accepting, point.updated_by, point.notes, point.volunteer_needs, point.supply_needs] });
coords = coords.concat(shelters);
manageMap(params, coords, types);
}
};
testrequest.send();
}
function initMap() {
map = new google.maps.Map(document.getElementById('map'), {
zoom: zm,
center: houston,
mapTypeId: 'terrain'
});
var infoWindow = new google.maps.InfoWindow;
navigator.geolocation.getCurrentPosition(function(position) {
pos = { lat: position.coords.latitude, lng: position.coords.longitude };
infoWindow.setPosition(pos);
infoWindow.setContent('Location found.');
infoWindow.open(map);
map.setCenter(pos);
map_toggles = [document.getElementById("needs_toggle"), document.getElementById("shelters_toggle")];
manageMap(pos, [], ["needs_toggle", "shelters_toggle"]);
});
var myControl = document.getElementById('name');
map.controls[google.maps.ControlPosition.TOP_LEFT].push(myControl);
}
function heatmapVis(locations) {
console.log(locations);
var heatmapData = [];
var marker;
for (var i = 0; i < locations.length; i++) {
var latLng = new google.maps.LatLng(locations[i]['latitude'], locations[i]['longitude'])
var color = locations[i]['color']
console.log(locations[i].length);
heatmapData.push(latLng);
if(markers){
marker = new google.maps.Marker({
position: latLng,
map: map,
//animation: google.maps.Animation.DROP,
icon: color
});
google.maps.event.addListener(marker, 'click', function() {
map.setZoom(10);
map.setCenter(marker.getPosition());
console.log(marker.getPosition());
});
markerslist.push(marker);
}
}
heatmap = new google.maps.visualization.HeatmapLayer({
data: heatmapData,
dissipating: false,
radius: 0.04,
map: map
});
}
//function display()
function clearmap(){
heatmap.setMap(null);
for(var i=0;i<markerslist.length;i++){
markerslist[i].setMap(null);
}
}
function needs_anal(input) {
$.ajax({
type: "POST",
url: "/needs_anal.py",
data: { param: input },
success: callbackFunc
});
}
function callbackFunc(response) {
console.log(response);
}