-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
241 lines (205 loc) · 8.91 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
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
<html>
<head>
<meta charset="utf-8" />
<title>Pune Watershed Project</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: calc(100% - 2em);
}
</style>
</head>
<body>
<div align="center">
<input type="button" value="previous" onClick="nextTiles(-1)">
<select id="overlaySelector" onChange="changeTiles()">
<optgroup label="Ramnadi">
<option value="ramnadi" selected>Ramnadi Watershed Geology</option>
<option value="elevation">Ramnadi Elevation</option>
<option value="drainage">Ramnadi Drainage</option>
</optgroup>
<optgroup label="Villages">
<option value="baner">Baner village GSDA map</option>
<option value="pashan">Pashan village GSDA map</option>
<option value="sunarwadi">Sunarwadi village GSDA map</option>
<option value="bavdhanBk">Bavdhan Bk village GSDA map</option>
<option value="bavdhanKh">Bavdhan Kh village GSDA map</option>
<option value="bhugaon">Bhugaon village GSDA map</option>
<option value="bhukum">Bhukum village GSDA map</option>
<option value="villages">All villages combined</option>
</optgroup>
</select>
<input type="button" value="next" onClick="nextTiles(1)">
<div style="display:inline-block" id="overlayInfo"></div>
</div>
<div id="map"></div>
<script src="lib/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 src="lib/leaflet.tilelayer.fallback.js"></script> not using for now.. could not combine with Functional -->
<script type="text/JavaScript">
var DATAPATH = "shapes/";
var OpenStreetMap_Mapnik = L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
maxZoom: 19,
attribution: '© <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors'
});
var CartoDB_Positron = 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 CartoDB_DarkMatter = L.tileLayer('https://{s}.basemaps.cartocdn.com/dark_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 CartoDB_Voyager = L.tileLayer('https://{s}.basemaps.cartocdn.com/rastertiles/voyager/{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 gStreets = L.tileLayer('https://{s}.google.com/vt/lyrs=m&x={x}&y={y}&z={z}',{
maxZoom: 20,
subdomains:['mt0','mt1','mt2','mt3']
});
var gSat = L.tileLayer('https://{s}.google.com/vt/lyrs=s&x={x}&y={y}&z={z}',{
maxZoom: 20,
subdomains:['mt0','mt1','mt2','mt3']
});
// var googleLayer = new L.Google('ROADMAP'); // google maps layer initiation
var baseLayers = {
"Voyager": CartoDB_Voyager,
"Positron": CartoDB_Positron,
"DarkMatter": CartoDB_DarkMatter ,
"OpenStreetMap": OpenStreetMap_Mapnik,
"Streets": gStreets,
"Satellite": gSat
};
var map = L.map('map', {
layers: [CartoDB_Voyager],
fullscreenControl: true,
fullscreenControlOptions: {
position: 'topleft'
},
minZoom: 11, maxZoom: 15
})
.setView([18.51,73.75], 12);
var overlays = { };
var layerControl = L.control.layers(baseLayers, overlays, {collapsed: true}).addTo(map);
// ###################################################################
// CUSTOM TILES SOURCE
var tileSource = '';
var funcLayer = new L.TileLayer.Functional(function (view) {
//var url = 'https://{s}.tiles.mapbox.com/v4/{i}/{z}/{x}/{y}.png?access_token=pk.eyJ1IjoiY2VlcHVuZSIsImEiOiJjajZ0OXNpMW0wYzh2MnFycDR5bGdwbTN3In0.z5P1lIR3V_QUmCq44-0tZg'
// var url = 'tiles/{i}/{z}/{x}/{y}.png'
var url = 'https://server.nikhilvj.co.in/watershed_overlap_map/tiles/{i}/{z}/{x}/{y}.png'
.replace('{z}', view.zoom)
.replace('{y}', view.tile.row)
.replace('{x}', view.tile.column)
.replace('{s}', view.subdomain)
.replace('{i}', tileSource);
return url;
},
{ maxZoom: 17 }
);
layerControl.addOverlay(funcLayer , "Overlay Layer");
function changeTiles() {
var e = document.getElementById("overlaySelector");
var id = e.options[e.selectedIndex].value;
tileSource = id;
funcLayer.redraw();
console.log("Changed tile source to " + tileSource );
//document.getElementById('overlayInfo').innerHTML = '<a href="https://www.mapbox.com/studio/tilesets/'+tileSource + '/">' + tileSource + '</a>';
}
changeTiles();
//###############################
// Adding other layers
var wards = L.geoJson(null, {
style: {weight: 2, opacity: 1, color: 'orange', dashArray: '4', fillOpacity: 0, fillColor: "yellow" },
onEachFeature: onEachFeature
});
omnivore.geojson(DATAPATH+'pune.2017.wards.geojson', null, wards);
layerControl.addOverlay(wards , "2017-onwards Pune prabhags");
// Loading three talukas overlapping the area
var talukas = L.geoJson(null, {
style: {weight: 1, opacity: 1, color: 'blue', dashArray: '6', fillOpacity: 0.0 },
onEachFeature: onEachFeature
});
omnivore.geojson(DATAPATH+'punecity.haveli.mulshi.geojson', null, talukas);
layerControl.addOverlay(talukas , "talukas punecity,haveli,mulshi");
function onEachFeature(feature, layer) {
// 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]);
}
layer.bindPopup(popupcontent.join("<br />"));
}
/*
var adminlayer = L.geoJson(null, {
//onEachFeature: function (feature, layer) { defaultOnEachFeature(feature, layer, title, fields); },
style: {weight: 2, opacity: 1, color: 'purple', dashArray: '4', fillOpacity: 0,
fillColor: "yellow" }
});
omnivore.geojson(DATAPATH+'pune-admin-wards-boundaries.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)
.setContent(`${e.latlng.lat}, ${e.latlng.lng}`) //just the lat-long, no tile info
.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>