forked from answerquest/answerquest.github.io
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathoverlap-nagpur.html
246 lines (210 loc) · 9.32 KB
/
overlap-nagpur.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
<html>
<head>
<meta charset="utf-8" />
<title>Nagpur 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()">
<option value="15155" selected="selected">Nagpur 2012 wards</option>
</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="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 = "nagpur/";
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([21.145800, 79.088155], 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: 'orange', dashArray: '4', fillOpacity: 0 },
onEachFeature: function(feature, layer) {
layer.on({
//click: onMapClick,
click: function (e) {
var loc = '<br>Located in Prabhag : ' + feature.properties.wardnum;
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>');
},
mouseout: function (e) {
$('#wardNum').html('');
}
}); // end of layer.on
} // end of onEachFeature
}).addTo(map);
omnivore.geojson(DATAPATH+'nagpur-wards.geojson', null, wards);
layerControl.addOverlay(wards , "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+'nagpur-zones.geojson', null, adminlayer);
layerControl.addOverlay(adminlayer , "Zone 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>