-
Notifications
You must be signed in to change notification settings - Fork 20
/
Copy pathoverlap.html
286 lines (251 loc) · 11.8 KB
/
overlap.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
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
<html>
<head>
<meta charset="utf-8" />
<title>Pune various maps overlapping</title>
<link rel="stylesheet" href="lib/leaflet.css" />
<link rel="stylesheet" href="lib/Control.Opacity.css" />
<link rel="stylesheet" href="lib/jquery-ui-1.10.3.custom.min.css" />
<link rel="stylesheet" href="lib/Control.FullScreen.css" />
<style type="text/css">
body, html {
height: 100%;
width: 100%;
margin: 0;
font-family: Sans-serif;
}
#map {
width: 100%;
height: 95%;
}
</style>
</head>
<body>
<div align="center">
<input type="button" value="previous" onClick="nextTiles(-1)">
<select id="overlaySelector" onChange="changeTiles()">
<optgroup label="Pune ward maps">
<option value="15921" selected="selected">PMC proposed map 2017 Election</option>
<option value="9881">PMC Official 76 Wards map 2012 Election</option>
<option value="10735">PMC pre-2012 144 Wards map</option>
</optgroup>
<optgroup label="Pune Development Plan, inner ciy limits, Nov 2015">
<option value="12684">Pune DP nov2015 sec1_1</option>
<option value="12687">Pune DP nov2015 sec1_2</option>
<option value="13195">Pune DP nov2015 sec1_3</option>
<option value="13196">Pune DP nov2015 sec1_4</option>
<option value="13197">Pune DP nov2015 sec1_5</option>
<option value="13198">Pune DP nov2015 sec1_6</option>
<option value="13199">Pune DP nov2015 sec1_7</option>
<option value="13201">Pune DP nov2015 sec1_8</option>
<option value="13200">Pune DP nov2015 sec1_9</option>
<option value="13202">Pune DP nov2015 sec1_10</option>
<option value="13203">Pune DP nov2015 sec2to6_1</option>
<option value="13204">Pune DP nov2015 sec2to6_2</option>
<option value="13205">Pune DP nov2015 sec2to6_3</option>
<option value="13206">Pune DP nov2015 sec2to6_4</option>
<option value="13207">Pune DP nov2015 sec2to6_5</option>
<option value="13208">Pune DP nov2015 sec2to6_6</option>
<option value="13209">Pune DP nov2015 sec2to6_7</option>
<option value="13210">Pune DP nov2015 sec2to6_8</option>
<option value="13211">Pune DP nov2015 sec2to6_9</option>
<option value="13212">Pune DP nov2015 sec2to6_10</option>
<option value="13213">Pune DP nov2015 sec2to6_11</option>
</optgroup>
<optgroup label="Development Plan, outer villages">
<option value="9985">pune dp Planning Unit no.1 EP sanction 30.8.2013</option>
<option value="9961">pune dp 13.2.14 Planning Unit No.2</option>
<option value="9962">pune dp 13.2.14 Planning Unit No.3</option>
<option value="9963">pune dp 13.2.14 Planning Unit No.4</option>
<option value="9964">pune dp 13.2.14 Planning Unit No.5 & 6</option>
<option value="9965">pune dp 13.2.14 Planning Unit No.7</option>
<option value="9981">pune dp 13.2.14 Planning Unit No.8</option>
<option value="9984">pune dp 13.2.14 Planning Unit No.9_vadgaonsheri</option>
<option value="9982">pune dp 13.2.14 Planning Unit No.9_kharadi</option>
<option value="9983">pune dp 13.2.14 Planning Unit No.10</option>
</optgroup>
<optgroup label="Stormwater Plan">
<option value="9994">Pune City Final Base Map for Storm Water Plan</option>
</optgroup>
</select>
<input type="button" value="next" onClick="nextTiles(1)">
<div style="display:inline-block; visibility:hidden" id="overlayInfo">Hello</div>
</div>
<div id="map"></div>
<!-- <script src="lib/leaflet.js"></script>-->
<script src="lib/leaflet.js" orig="http://cdnjs.cloudflare.com/ajax/libs/leaflet/0.7.3/leaflet.js"></script>
<script src="lib/Control.Opacity.js"></script>
<script src="lib/jquery-1.9.1.js"></script>
<script src="lib/jquery-ui-1.10.3.custom.min.js"></script>
<script src='lib/leaflet-omnivore.min.js'></script>
<script src="lib/leaflet.functionaltilelayer.js"></script>
<script src="lib/Control.FullScreen.js"></script> <!-- From https://github.com/brunob/leaflet.fullscreen -->
<script type="text/JavaScript">
var DATAPATH = "data/";
var osmLink = '<a href="http://openstreetmap.org">OpenStreetMap</a>',
mapboxUrl = 'https://{s}.tiles.mapbox.com/v3/{id}/{z}/{x}/{y}.png',
MBAttrib = '© ' + osmLink + ' Contributors & <a href="https://www.mapbox.com/about/maps/">Mapbox</a>',
osmUrl = 'http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png',
osmAttrib = '© ' + osmLink + ' Contributors';
PMCAttrib = '<a href="http://www.punecorporation.org/">Pune Municipal Corporation</a>',
cycleOverlay = '<br>Load overlay: <button onclick="nextTiles(-1)">Previous</button> | <button onclick="nextTiles(1)">Next</button>' +
'<br><span id="wardNum"></span>' ;
MBAttrib += cycleOverlay;
osmAttrib += cycleOverlay;
var MBstreets = L.tileLayer(mapboxUrl, {id: 'nikhilsheth.m0mlpl2d', attribution: MBAttrib, maxZoom: 20}),
MBsatlabel = L.tileLayer(mapboxUrl, {id: 'nikhilsheth.m0mmaa87', attribution: MBAttrib}),
MBsat = L.tileLayer(mapboxUrl, {id: 'nikhilsheth.m0mni8e7', attribution: MBAttrib}),
MBemerald = L.tileLayer(mapboxUrl, {id: 'nikhilsheth.m0mmebk6', attribution: MBAttrib}),
MBrun = L.tileLayer(mapboxUrl, {id: 'nikhilsheth.m0mmicn2', attribution: MBAttrib}),
MBlight = L.tileLayer(mapboxUrl, {id: 'nikhilsheth.m0mmobne', attribution: MBAttrib}),
MBbw = L.tileLayer(mapboxUrl, {id: 'nikhilsheth.m0mn13df', attribution: MBAttrib}),
MBdark = L.tileLayer(mapboxUrl, {id: 'nikhilsheth.jme9hi44', attribution: MBAttrib}),
MBpencil = L.tileLayer(mapboxUrl, {id: 'nikhilsheth.m0mn5lf5', attribution: MBAttrib}),
MBpirates = L.tileLayer(mapboxUrl, {id: 'nikhilsheth.m0mn8b72', attribution: MBAttrib}),
MBwheatpaste = L.tileLayer(mapboxUrl, {id: 'nikhilsheth.m0mnld61', attribution: MBAttrib}),
MBcomic = L.tileLayer(mapboxUrl, {id: 'nikhilsheth.m0mo16hg', attribution: MBAttrib}),
OsmIndia = L.tileLayer(mapboxUrl, {id: 'openstreetmap.1b68f018', attribution: MBAttrib, maxZoom: 20}),
osmMap = L.tileLayer(osmUrl, {attribution: osmAttrib, maxZoom: 20});
//var PMCwards = L.tileLayer('http://mapwarper.net/maps/tile/9881/{z}/{x}/{y}.png', {attribution: PMCAttrib});
// var googleLayer = new L.Google('ROADMAP'); // google maps layer initiation
var baseLayers = {
"OpenStreetMap.IN": OsmIndia,
"OpenStreetMap": osmMap,
"Mapbox Streets": MBstreets,
"Mapbox Satellite w/labels": MBsatlabel ,
"Mapbox Light": MBlight,
"Mapbox Dark" : MBdark
// "Google Maps": googleLayer
};
var map = L.map('map', {
layers: [MBsatlabel],
zoomControl: false,
fullscreenControl: true,
fullscreenControlOptions: {
position: 'topleft'
},
minZoom: 11, maxZoom: 20
})
.setView([18.51591, 73.84666], 13);
var overlays = { };
var layerControl = L.control.layers(baseLayers, overlays, {collapsed: true}).addTo(map);
map.addControl(L.control.zoom({position:'bottomright'}));
// ###################################################################
// CUSTOM TILES SOURCE
var tileSource = '';
var funcLayer = new L.TileLayer.Functional(function (view) {
var url = 'http://mapwarper.net/maps/tile/{i}/{0}/{1}/{2}.png'
.replace('{0}', view.zoom)
.replace('{2}', view.tile.row)
.replace('{1}', view.tile.column)
.replace('{3}', view.subdomain)
.replace('{i}', tileSource);
return url;
},
{ maxZoom: 20 }
);
layerControl.addOverlay(funcLayer , "Overlay Layer");
function changeTiles() {
var e = document.getElementById("overlaySelector");
var id = e.options[e.selectedIndex].value;
tileSource = id;
funcLayer.redraw();
document.getElementById("overlayInfo").innerHTML = '<small>See on <a href="http://mapwarper.net/maps/' + id + '#Preview_Map_tab" target="_blank">http://mapwarper.net/maps/' + id + '#Preview_Map_tab</a></small>';
console.log("Changed tile source to " + tileSource );
}
changeTiles();
//###############################
// Adding other layers
var wards = L.geoJson(null, {
//onEachFeature: function (feature, layer) { defaultOnEachFeature(feature, layer, title, fields); },
style: {weight: 2, opacity: 1, color: 'blue', dashArray: '4', fillOpacity: 0 },
onEachFeature: function(feature, layer) {
layer.on({
//click: onMapClick,
click: function (e) {
var loc = '<br>Located in Prabhag : ' + feature.properties.wardnum + ' (2012-17)';
url = getTileURL(e.latlng.lat, e.latlng.lng, map.getZoom()); //integrated the tile solution from http://jsfiddle.net/84P9r/ with this popup.
popup
.setLatLng(e.latlng)
.setContent(e.latlng.toString() + loc)
.openOn(map);
},
mouseover: function (e) {
$('#wardNum').html('Mouse currently over Prabhag <b>' + feature.properties.wardnum + '</b> (2012-17)');
},
mouseout: function (e) {
$('#wardNum').html('');
}
}); // end of layer.on
} // end of onEachFeature
}).addTo(map);
omnivore.geojson(DATAPATH+'pune-electoral-wards.geojson', null, wards);
layerControl.addOverlay(wards , "2012-17 Electoral Ward Boundaries");
var adminlayer = L.geoJson(null, {
//onEachFeature: function (feature, layer) { defaultOnEachFeature(feature, layer, title, fields); },
style: {weight: 2, opacity: 1, color: 'yellow', dashArray: '4', fillOpacity: 0 },
onEachFeature: function(feature, layer) {
layer.on({
//click: onMapClick,
click: function (e) {
var loc = '<br>Located in ' + feature.properties.name;
url = getTileURL(e.latlng.lat, e.latlng.lng, map.getZoom()); //integrated the tile solution from http://jsfiddle.net/84P9r/ with this popup.
popup
.setLatLng(e.latlng)
.setContent(e.latlng.toString() + loc)
.openOn(map);
},
mouseover: function (e) {
$('#wardNum').html('Mouse currently over ' + feature.properties.name);
},
mouseout: function (e) {
$('#wardNum').html('');
}
}); // end of layer.on
} // end of onEachFeature
});
omnivore.geojson(DATAPATH+'pune-admin-wards.geojson', null, adminlayer);
//omnivore.csv(DATAPATH+'pune-admin-ward-offices.csv', null, adminlayer);
layerControl.addOverlay(adminlayer , "Admin Ward Boundaries");
//######################################################
// OPACITY CONTROL:
//Create the opacity controls
var opacitySlider = new L.Control.opacitySlider({position: 'topright'});
map.addControl(opacitySlider);
//Specify the layer for which you want to modify the opacity. Note that the setOpacityLayer() method applies to all the controls.
//You only need to call it once.
opacitySlider.setOpacityLayer(funcLayer);
funcLayer.setOpacity(0.8).addTo(map);
//funcLayer.bringToFront();
// popup giving lat-long + tile, zoom level
var popup = L.popup();
function onMapClick(e) {
url = getTileURL(e.latlng.lat, e.latlng.lng, map.getZoom()); //integrated the tile solution from http://jsfiddle.net/84P9r/ with this popup.
popup
.setLatLng(e.latlng)
.setContent(e.latlng.toString() /*+ url*/)
.openOn(map);
}
map.on('click', onMapClick);
function getTileURL(lat, lon, zoom) {
// From http://jsfiddle.net/84P9r/ : To get tile on clicking
var xtile = parseInt(Math.floor( (lon + 180) / 360 * (1<<zoom) ));
var ytile = parseInt(Math.floor( (1 - Math.log(Math.tan(lat * Math.PI / 180) + 1 / Math.cos(lat* Math.PI / 180)) / Math.PI) / 2 * (1<<zoom) ));
return "<br>Tile " + zoom + "/" + xtile + "/" + ytile;
//modifying this to directly show mapwarper tile
//Commenting this out, use for debugging / development:
//var mapwarperURL = 'http://mapwarper.net/maps/tile/'+tileSource+ '/' +zoom+ '/' +xtile+ '/' +ytile+ '.png';
//return '<br>Tile <a href="'+mapwarperURL+'" target="_blank">'+mapwarperURL+'</a>';
}
function nextTiles(i) {
var e = document.getElementById("overlaySelector");
e.selectedIndex +=i ;
//loop-around from the top or bottom depending on increment/decrement
if(e.selectedIndex == -1) {
if(i>0) e.selectedIndex = 0;
else e.selectedIndex = e.length - 1;
}
changeTiles();
}
</script>
</body>
</html>