-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathheatmap.js
87 lines (75 loc) · 1.92 KB
/
heatmap.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
var map;
var pointarray;
var heatmap;
var MY_MAPTYPE_ID = 'custom_style';
var featureOpts = [
{
stylers: [
{ color: '#333333' },
]
},
{
elementType: 'labels',
stylers: [
{ visibility: 'off' }
]
},
{
featureType: 'road.local',
stylers: [
{ visibility: 'off' }
]
},
{
featureType: 'road.arterial',
stylers: [
{ visibility: 'off' }
]
},
{
featureType: 'water',
stylers: [
{ color: '#000000' }
]
}
];
function initialize(){
// build map
// ---------------------------------
var myLatlng = new google.maps.LatLng(34.052235, -118.243683);
var myOptions = {
zoom: 9,
center: myLatlng,
mapTypeControlOptions: {
mapTypeIds: [google.maps.MapTypeId.ROADMAP, MY_MAPTYPE_ID]
},
mapTypeId: MY_MAPTYPE_ID
};
map = new google.maps.Map(document.getElementById('map-canvas'), myOptions);
// customize map
// ---------------------------------
var styledMapOptions = {
name: 'Custom Style'
};
var customMapType = new google.maps.StyledMapType(featureOpts, styledMapOptions);
map.mapTypes.set(MY_MAPTYPE_ID, customMapType);
// build array of latLng
// ---------------------------------
var data = [];
var obj = null;
points.forEach(function(point){
// check for crimes with no latLng
if ( point.latitude && point.longitude ){
obj = new google.maps.LatLng(point.latitude, point.longitude);
data.push(obj);
}
});
// build heat layer
// ---------------------------------
var pointArray = new google.maps.MVCArray(data);
heatmap = new google.maps.visualization.HeatmapLayer({
data: pointArray
});
heatmap.setMap(map);
}
google.maps.event.addDomListener(window, 'load', initialize);