-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaverage_prices.html
executable file
·153 lines (128 loc) · 5.28 KB
/
average_prices.html
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
<!DOCTYPE html>
<html>
<head>
<style>
#map-canvas {
width: 640px;
height: 640px;
}
</style>
<script src="https://maps.googleapis.com/maps/api/js?libraries=visualization&sensor=true_or_false&key=AIzaSyCGFXpg1qLpVIv72b8tTy-6xexMJWVI2Hk"></script>
<script src="./scripts/oms.min.js"></script>
<script>
function initialize() {
var mapCanvas = document.getElementById('map-canvas');
var mapOptions = {
center: new google.maps.LatLng(50.58, -126.95),
zoom: 4,
//mapTypeId: google.maps.MapTypeId.ROADMAP
}
var heatMapData = [];
var map = new google.maps.Map(mapCanvas, mapOptions)
map.data.loadGeoJson('https://maps.dev4.catalogue.libraries.coop:4433/geojson/average_prices.json');
map.data.loadGeoJson('https://maps.dev4.catalogue.libraries.coop:4433/geojson/econ_region.json');
//does not load, no javascript error, so hard to detect. Download takes a long time because
//it is 160MB, so the javascript may never execute on this file, hence no error.
//map.data.loadGeoJson('https://maps.dev4.catalogue.libraries.coop:4433/geojson/school_dist.json');
var oms = new OverlappingMarkerSpiderfier(map);
var book_count = 0;
var current_library = '';
var old_library = '';
map.data.addListener('addfeature', function (e) {
if (e.feature.getGeometry().getType() === 'Point') {
old_library = current_library;
current_library = e.feature.getProperty('library_name0');
if (current_library == old_library) {
book_count++;
} else {
book_count = 0;
}
if (book_count < 8) {
var marker = new google.maps.Marker({
position: e.feature.getGeometry().get(),
title: e.feature.getProperty('title0'),
map: map
});
//We are displaying this marker, so set it's
//zIndex high so it receives clicks
marker.setZIndex(100000);
var text = '';
e.feature.forEachProperty(function (data, key) {
key = key.replace(/[0-9][0-9]*/, '');
key = key.charAt(0).toUpperCase() + key.slice(1);
text += '<strong>' + key + ':</strong> ' + data + "<br\>";
});
marker.desc = text;
var average_price_per_library = 0;
var average_lend_per_work = 0;
var infowindow = new google.maps.InfoWindow();
infowindow.setContent(marker.desc);
google.maps.event.addListener(marker, 'click', function() {
infowindow.open(map, marker);
});
e.feature.forEachProperty(function (data, key) {
if (key == 'average_price_per_library0') {
average_price_per_library = data;
} else if (key == 'average_lending_per_work0') {
average_lending_per_work = data;
}
});
var new_weight = average_price_per_library / average_lending_per_work;
var position = e.feature.getGeometry().get();
var lat = position.lat();
var lng = position.lng();
var new_heat_map_point = {location: new google.maps.LatLng(lat, lng), weight: new_weight};
heatMapData.push(new_heat_map_point);
}
} else {
var color;
switch (e.feature.getProperty('OBJECTID')) {
case 9:
color = 'red';
break;
case 10:
color = 'yellow';
break;
case 11:
color = 'orange';
break;
case 12:
color = 'green';
break;
case 13:
color = 'purple';
break;
case 14:
color = 'brown';
break;
case 15:
color = 'white';
break;
case 16:
color = 'blue';
break;
default:
color = 'blue';
}
map.data.overrideStyle(e.feature, {fillColor: color});
map.data.overrideStyle(e.feature, {fillOpacity: 0.15});
if (e.feature.getProperty('OBJECTID') == 16) {
var heatmap = new google.maps.visualization.HeatmapLayer({
data: heatMapData,
dissipating: false,
radius: 0.25,
gradient: ['rgba(0, 0, 0, 0)', 'rgba(0, 200, 0, 1)', 'rgba(200, 200, 0, 1)',
'rgba(200, 0, 0, 1)', 'rgba(255, 0, 0, 1)']
});
heatmap.setMap(map);
}
}
});
}
google.maps.event.addDomListener(window, 'load', initialize);
</script>
</head>
<body>
<div id="map-canvas"></div>
</body>
</html>