-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrender-post-clusters.html
More file actions
140 lines (114 loc) · 4.45 KB
/
render-post-clusters.html
File metadata and controls
140 lines (114 loc) · 4.45 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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
<!DOCTYPE html>
<html>
<head>
<style type="text/css">
html, body, #map-canvas { height: 100%; margin: 0; padding: 0;}
</style>
<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script>
<!--
<script type="text/javascript"
src="https://maps.googleapis.com/maps/api/js?v=3.exp?key=AIzaSyBT6L96hKLQd7Ld9pzbPwR7nUxrRsnySLA&sensor=false">
</script>
-->
<script src="https://cdnjs.cloudflare.com/ajax/libs/d3/3.5.5/d3.min.js"></script>
<!--
<script type="text/javascript" src="../Fluster2/lib/Fluster2.min.js"></script>
-->
<script type="text/javascript" src="../Fluster2/lib/Fluster2.js"></script>
<script type="text/javascript" src="../Fluster2/lib/Fluster2Cluster.js"></script>
<script type="text/javascript" src="../Fluster2/lib/Fluster2ClusterMarker.js"></script>
<script type="text/javascript" src="../Fluster2/lib/Fluster2ProjectionOverlay.js"></script>
<script type="text/javascript" src="markers2.js" />
<script type="text/javascript"></script>
<script type="text/javascript">
;;
// OnLoad function ...
var fluster;
// https://stackoverflow.com/questions/7095574/google-maps-api-3-custom-marker-color-for-default-dot-marker
function pinSymbol(color) {
return {
path: 'M 0,0 C -2,-20 -10,-22 -10,-30 A 10,10 0 1,1 10,-30 C 10,-22 2,-20 0,0 z M -2,-30 a 2,2 0 1,1 4,0 2,2 0 1,1 -4,0',
fillColor: color,
fillOpacity: 1,
strokeColor: '#000',
strokeWeight: 2,
scale: 1,
};
}
function initialize() {
markers = markers.filter(function(d) { return d.gps; });
markers.forEach(function(d) { console.log(d.gps.latitude); })
var latExt = d3.extent(markers, function(d) { return d.gps.latitude; });
var longExt = d3.extent(markers, function(d) { return d.gps.longitude; });
var marker_dates = markers.map( function(d) { if (d.date_time) return new Date(d.date_time); })
var date_extent = d3.extent(marker_dates)
var time_range = d3.time.scale().domain(date_extent).range([0,1])
var mapOptions = {
zoom: 3,
draggableCursor: 'default',
center: new google.maps.LatLng((latExt[1] - latExt[0])/2, (longExt[1] - longExt[0])/2)
};
var map = new google.maps.Map(document.getElementById('map-canvas'),
mapOptions);
// Initialize Fluster and give it a existing map
fluster = new Fluster2(map, true);
for (var i = 0; i < markers.length; i++) {
var m = markers[i];
var myLatLng = new google.maps.LatLng(m.gps.latitude, m.gps.longitude);
console.log(m)
var pin = pinSymbol(d3.interpolateRgb(d3.rgb(0x40,0x00,0x00),
d3.rgb(0xff,0x00,0x00))(time_range(new Date(m.date_time))));
var marker = new google.maps.Marker({
position: myLatLng,
// map:map,
icon: pin,
link: m.post,
title: m.title
});
// marker.link = m.link;
fluster.addMarker(marker);
}
// Set styles
// These are the same styles as default, assignment is only for demonstration ...
fluster.styles = {
// This style will be used for clusters with more than 0 markers
0: {
image: 'http://gmaps-utility-library.googlecode.com/svn/trunk/markerclusterer/1.0/images/m1.png',
textColor: '#FFFFFF',
width: 53,
height: 52
},
// This style will be used for clusters with more than 10 markers
10: {
image: 'http://gmaps-utility-library.googlecode.com/svn/trunk/markerclusterer/1.0/images/m2.png',
textColor: '#FFFFFF',
width: 56,
height: 55
},
20: {
image: 'http://gmaps-utility-library.googlecode.com/svn/trunk/markerclusterer/1.0/images/m3.png',
textColor: '#FFFFFF',
width: 66,
height: 65
}
};
// Initialize Fluster
// This will set event handlers on the map and calculate clusters the first time.
fluster.initialize();
}
function loadScript() {
// var script = document.createElement('script');
// script.type = 'text/javascript';
//?key=AIzaSyBT6L96hKLQd7Ld9pzbPwR7nUxrRsnySLA
//script.src = 'https://maps.googleapis.com/maps/api/js?v=3.exp' +
// '&signed_in=true&callback=initialize';
// document.body.appendChild(script);
initialize();
}
//window.onload = loadScript;
</script>
</head>
<body onload = "loadScript()">
<div id="map-canvas"></div>
</body>
</html>