-
Notifications
You must be signed in to change notification settings - Fork 21
/
pune_07-12-17_sync.html
244 lines (189 loc) · 8.54 KB
/
pune_07-12-17_sync.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
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
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Pune prabhag (electoral ward) maps : Pre-2012, 2012-17, 2017 onwards</title>
<link rel="stylesheet" href="https://unpkg.com/[email protected]/dist/leaflet.css" />
<script src="https://unpkg.com/[email protected]/dist/leaflet-src.js"></script>
<script src="https://api.tiles.mapbox.com/mapbox.js/plugins/leaflet-omnivore/v0.3.1/leaflet-omnivore.min.js" alt='lib/leaflet-omnivore.min.js'></script>
<script src="https://jieter.github.io/Leaflet.Sync/L.Map.Sync.js"></script>
<style type="text/css">
html, body { width: 100%; height: 100%; margin: 10; font-family: Arial }
#map, #container { width: 50%; height: 90%;
}
#map { float: left; }
#container { float: right; }
#container .halfmap { width: 90%; height: 50%; }
#map { border-style: solid; border-width: 2px; border-color: black
box-sizing: border-box; -moz-box-sizing: border-box; -webkit-box-sizing: border-box;}
#mapA { border-style: solid; border-width: 2px; border-color: black
box-sizing: border-box; -moz-box-sizing: border-box; -webkit-box-sizing: border-box;}
#mapB { border-style: solid; border-width: 2px; border-color: black
box-sizing: border-box; -moz-box-sizing: border-box; -webkit-box-sizing: border-box;}
/* Corner ribbon code, from http://www.cssportal.com/blog/create-corner-ribbon/ */
.box {
width:200px;height:300px;
position:relative;
border:1px solid #BBB;
background:#eee;
}
.ribbon {
position: absolute;
right: -5px; top: -5px;
z-index: 1000;
overflow: hidden;
width: 80px; height: 80px;
text-align: right;
position: fixed;
}
.ribbon span {
font-size: 10px;
color: #fff;
text-transform: uppercase;
text-align: center;
font-weight: bold; line-height: 24px;
transform: rotate(45deg);
-webkit-transform: rotate(45deg); /* Needed for Safari */
width: 150px; display: block;
background: #79A70A;
background: linear-gradient(#9BC90D 0%, #79A70A 100%);
box-shadow: 0 3px 10px -5px rgba(0, 0, 0, 1);
position: absolute;
top: 23px; right: -42px;
}
.ribbon a {
color: #FFFFFF;
text-decoration: none;
}
</style>
</head>
<body>
<h2>Pune Prabhag boundaries : three layouts over 15 years, synchronized maps.</h2>
<div id="map"></div>
<div id="container">
<div id="mapA" class="halfmap"></div>
<div id="mapB" class="halfmap"></div>
</div>
<br> <br>
<p>Instructions: Click/touch and drag to move the map around. Use the zoom control on top left or +/- keys to zoom in or out. All three maps will move together, and mouse cursor position will be copied.</p>
<p>Click on links to download the shape files.: Green : <a href="maps/pune.2017.wards.geojson">2017-present</a> (41 prahags) | Blue: <a href="maps/pune.2012-17.wards.geojson">2012-17</a> (76 prabhags) | Red: <a href="maps/pune.pre-2012.wards.geojson:">Pre-2012</a> (144 Prabhags). <br>The 2011 Census data for Pune is as per the pre-2012 144 prabhags.</p>
<p>Map prepared by <a href="https://answerquest.github.io">Nikhil VJ</a>, <a href="https://datameet-pune.github.io">DataMeet Pune Chapter</a>, India. Contact : nikhil.js [at] gmail.com.
<p><a href="https://www.instamojo.com/@nikhilvj/">Please contribute</a> if you appreciate this work and would like to see more of it!</p>
<p>Using Leaflet, <a href="http://leafletjs.com/plugins.html#minimaps--synced-maps">Leaflet.Sync</a> plugin and Scenic tileset from Mapbox. <a href="https://github.com/answerquest/answerquest.github.io/blob/master/pune_07-12-17_sync.html" target="_blank">See the code on github</a>.
<p><- Back to <a href="https://answerquest.github.io/">answerquest.github.io</a></p>
<br>
<div class="ribbon"><span><a href="https://www.instamojo.com/@nikhilvj/">Contribute</a></span></div>
<script type="text/javascript">
var DATAPATH = "maps/"
var center = [18.53, 73.85]; //Pune
var osmLink = '<a href="http://openstreetmap.org">OpenStreetMap</a>';
var MBAttrib = '© ' + osmLink + ' Contributors & <a href="https://www.mapbox.com/about/maps/">Mapbox</a>';
var mapboxUrl = 'https://api.mapbox.com/styles/v1/mapbox/streets-v10/tiles/256/{z}/{x}/{y}?access_token=pk.eyJ1IjoibmlraGlsc2hldGgiLCJhIjoiQTREVlJuOCJ9.YpMpVVbkxOFZW-bEq1_LIw'; // from Mapbox account
var scenic = 'https://api.mapbox.com/styles/v1/nikhilsheth/cj8rdd7wu45nl2sps9teusbbr/tiles/256/{z}/{x}/{y}?access_token=pk.eyJ1IjoibmlraGlsc2hldGgiLCJhIjoiQTREVlJuOCJ9.YpMpVVbkxOFZW-bEq1_LIw' ;
var MBstreets = L.tileLayer(scenic, {attribution: MBAttrib});
var MBstreetsA = L.tileLayer(scenic, {attribution: MBAttrib});
var MBstreetsB = L.tileLayer(mapboxUrl, {attribution: MBAttrib});
var map = L.map('map', {
layers: [MBstreets],
center: center,
scrollWheelZoom: false,
zoom: 12
});
var mapA = L.map('mapA', {
layers: [MBstreetsA],
center: center,
zoom: 12,
scrollWheelZoom: false,
zoomControl: false
});
var mapB = L.map('mapB', {
layers: [MBstreetsB],
center: center,
zoom: 12,
scrollWheelZoom: false,
zoomControl: false
});
// syncing
map.sync(mapA, {syncCursor: true});
map.sync(mapB, {syncCursor: true});
mapA.sync(map, {syncCursor: true});
mapA.sync(mapB, {syncCursor: true});
mapB.sync(map, {syncCursor: true});
mapB.sync(mapA, {syncCursor: true});
// Adding layer control
var layerControl = L.control.layers({ },{ }, {collapsed: false}).addTo(map);
var layerControlA = L.control.layers({ }, { }, {collapsed: false}).addTo(mapA);
var layerControlB = L.control.layers({ }, { }, {collapsed: false}).addTo(mapB);
// Loading ward layers on the three maps
var wards = L.geoJson(null, {
style: {weight: 1.5, opacity: 1, color: 'green', dashArray: '0', fillOpacity: 0.0 },
onEachFeature: onEachFeature
}).addTo(map);
omnivore.geojson(DATAPATH+'pune.2017.wards.geojson', null, wards);
layerControl.addOverlay(wards , "2017 onwards (41)");
var wardsA = L.geoJson(null, {
style: {weight: 1.5, opacity: 1, color: 'blue', dashArray: '0', fillOpacity: 0.0 },
onEachFeature: onEachFeatureA
}).addTo(mapA);
omnivore.geojson(DATAPATH+'pune.2012-17.wards.geojson', null, wardsA);
layerControlA.addOverlay(wardsA , "2012-17 (76)");
var wardsB = L.geoJson(null, {
style: {weight: 1.5, opacity: 1, color: '#d55d5d', dashArray: '0', fillOpacity: 0.0 },
onEachFeature: onEachFeatureB
}).addTo(mapB);
omnivore.geojson(DATAPATH+'pune.pre-2012.wards.geojson', null, wardsB);
layerControlB.addOverlay(wardsB , "pre-2012 (144)");
function onEachFeature(feature, layer) {
var popupText = '<big><b>' + feature.properties['prabhag_number'].toString() + "</b>: " + feature.properties['prabhag_name'] +
'</big>';
layer.bindTooltip(popupText,
{ sticky: true }) // to follow the mouse
.addTo(map);
// show all properties on clicking. From https://stackoverflow.com/a/33839514/4355695
var popupcontent = [];
for (var prop in feature.properties) {
popupcontent.push(prop + ": " + feature.properties[prop]);
}
popupcontent.push('<a href="javascript:map.fitBounds('+bounds2string(layer.getBounds())+');">click here to zoom in</a>');
layer.bindPopup(popupcontent.join("<br />"));
/*
// mouse interactivity, from http://leafletjs.com/examples/choropleth/
layer.on({
click: function zoomToFeature(e) {
map.fitBounds(e.target.getBounds());
}
});
*/
}
// tooltip syntax: https://gis.stackexchange.com/a/245183/44746
// .toString() has to be added when taking only a numerical feature.properties.var as tooltip text, from
function bounds2string(zObj) {
return '[ [ ' + zObj._southWest.lat +','+ zObj._southWest.lng +'] , [ '+ zObj._northEast.lat +',' + zObj._northEast.lng + ' ] ]';
}
function onEachFeatureA(feature, layer) {
var popupText = '<big><b>' + feature.properties['wardnum'].toString() + "</b>: " + feature.properties['title'] + '</big>';
layer.bindTooltip(popupText,
{ sticky: true }) // to follow the mouse
.addTo(mapA);
var popupcontent = [];
for (var prop in feature.properties) {
popupcontent.push(prop + ": " + feature.properties[prop]);
}
popupcontent.push('<a href="javascript:mapA.fitBounds('+bounds2string(layer.getBounds())+');">click here to zoom in</a>');
layer.bindPopup(popupcontent.join("<br />"));
}
function onEachFeatureB(feature, layer) {
var popupText = '<big><b>' + feature.properties['wardnum'].toString() + '</b></big>';
layer.bindTooltip(popupText,
{ sticky: true }) // to follow the mouse
.addTo(mapB);
var popupcontent = [];
for (var prop in feature.properties) {
popupcontent.push(prop + ": " + feature.properties[prop]);
}
popupcontent.push('<a href="javascript:mapB.fitBounds('+bounds2string(layer.getBounds())+');">click here to zoom in</a>');
layer.bindPopup(popupcontent.join("<br />"));
}
</script>
</body>
</html>