-
Notifications
You must be signed in to change notification settings - Fork 6
/
index.html
158 lines (148 loc) · 4.61 KB
/
index.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
154
155
156
157
158
<html>
<title>TweetOMap</title>
<link rel="stylesheet" href="https://unpkg.com/leaflet@1.5.1/dist/leaflet.css" />
<script src="https://unpkg.com/leaflet@1.5.1/dist/leaflet.js"></script>
<script src="heatmap.min.js"></script>
<script src="leaflet-heatmap.js"></script>
<script src="/socket.io/socket.io.js"></script>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<style>
#map-canvas { height: 700px; }
</style>
<body>
See source code:<a href=https://github.com/tomsoft1/TweetOMap>https://github.com/tomsoft1/TweetOMap</a>
<a class="twitter-share-button"
href="https://twitter.com/intent/tweet">
Tweet</a>
<script>window.twttr = (function(d, s, id) {
var js, fjs = d.getElementsByTagName(s)[0],
t = window.twttr || {};
if (d.getElementById(id)) return t;
js = d.createElement(s);
js.id = id;
js.src = "https://platform.twitter.com/widgets.js";
fjs.parentNode.insertBefore(js, fjs);
t._e = [];
t.ready = function(f) {
t._e.push(f);
};
return t;
}(document, "script", "twitter-wjs"));</script>
<div class="demo-wrapper">
<div class="heatmap" id="map-canvas">
</div>
</div>
<script>
$.urlParam = function(name){
try{
var results = new RegExp('[\?&]' + name + '=([^&#]*)').exec(window.location.href);
return results[1] || 0;
}catch(e){}
}
var NB_TWEETS=5;
var hover_bubble=[];
var showTweets=true;
var socket=null;
window.onload = function() {
var baseLayer = L.tileLayer('https://{s}.basemaps.cartocdn.com/light_all/{z}/{x}/{y}{r}.png', {
attribution: '© <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors © <a href="https://carto.com/attributions">CARTO</a>',
subdomains: 'abcd',
maxZoom: 19
});
var cfg = {
"radius": 5,
"maxOpacity": .8,
"scaleRadius": false,
"useLocalExtrema": true,
latField: 'lat',
lngField: 'lng',
valueField: 'count'
};
heatmapLayer = new HeatmapOverlay(cfg);
console.log(heatmapLayer);
map = new L.Map('map-canvas', {
center: new L.LatLng(46.99,2.58),
zoom: 7,
layers: [baseLayer, heatmapLayer]
});
map.on('zoomend',updateSocket);
map.on('dragend',updateSocket);
if(bounds=$.urlParam('bounds')){
rect=JSON.parse(bounds);
map.fitBounds(L.latLngBounds([rect[1],rect[0]],[rect[3],rect[2]]));
}
// All of this to add a simple button on top of the map
MyControl = L.Control.extend({
options: {
position: 'topleft'
},
onAdd: function (map) {
// create the control container with a particular class name
var container = L.DomUtil.create('div', 'my-custom-control');
controlUI = L.DomUtil.create('button', 'toggle-tweet', container);
return container;
}
});
map.addControl(new MyControl());
var myBut=$(".toggle-tweet")
myBut.text("Hide");
myBut.click(toggleTweets);
// End of button extra
for(var i=0;i<NB_TWEETS;i++){
hover_bubble.push(new L.Popup({ offset: new L.Point(0,-10), closeButton: false, autoPan: false }));
}
startSocket();
};
function addPoint(tweet)
{
if(tweet.geo){
pt={lng:tweet.geo.coordinates[1],lat:tweet.geo.coordinates[0],count:1};
if(showTweets){
bubble=hover_bubble.shift();
bubble.setContent("<img src="+tweet.user.profile_image_url+" align=left><b>@"+tweet.user.screen_name+"</b><br>"+tweet.text)
.setLatLng(tweet.geo.coordinates)
.addTo(map);
hover_bubble.push(bubble);
}
heatmapLayer.addData(pt);
}
}
function toggleTweets()
{
showTweets=!showTweets;
console.log(showTweets);
}
function updateSocket(){
window.history.pushState("TweetOMap","TweetOMap","/?bounds=["+map.getBounds().toBBoxString()+"]");
if(socket)socket.emit("recenter",map.getBounds().toBBoxString());
}
function startSocket(){
socket = io.connect('/', {query: "bounds=["+map.getBounds().toBBoxString()+"]"});
socket.on('stream', function(tweet){
addPoint(tweet);
});
socket.on('reconnect',function(){
console.log("Reconnect");
updateSocket();
});
}
</script>
<!-- Start of StatCounter Code for Default Guide -->
<script type="text/javascript">
var sc_project=10207804;
var sc_invisible=1;
var sc_security="be5c25a8";
var scJsHost = (("https:" == document.location.protocol) ?
"https://secure." : "http://www.");
document.write("<sc"+"ript type='text/javascript' src='" +
scJsHost+
"statcounter.com/counter/counter.js'></"+"script>");
</script>
<noscript><div class="statcounter"><a title="free hit
counter" href="http://statcounter.com/" target="_blank"><img
class="statcounter"
src="http://c.statcounter.com/10207804/0/be5c25a8/1/"
alt="free hit counter"></a></div></noscript>
<!-- End of StatCounter Code for Default Guide -->
</body>
</html>