-
Notifications
You must be signed in to change notification settings - Fork 21
/
overlap-custom-side.html
185 lines (163 loc) · 6.2 KB
/
overlap-custom-side.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
<!DOCTYPE html>
<html>
<head>
<meta charset=utf-8 />
<meta name='viewport' content='width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no, minimal-ui' />
<title>Side-by-side compare georeferenced rasters</title>
<script src='lib/leaflet-src.js'></script>
<script src="lib/leaflet-side-by-side.min.js"></script>
<link href='lib/leaflet.css' rel='stylesheet' />
<link rel="stylesheet" href="lib/leaflet-slider.css"/>
<script src="lib/leaflet-slider.js"></script>
<link rel="stylesheet" href="lib/Control.FullScreen.css" />
<script src="lib/leaflet.functionaltilelayer.js"></script>
<script src="lib/leaflet-providers.js"></script>
<style>
body {
font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
margin: 0;
padding: 0;
}
#map {
position: absolute;
bottom: 0;
top: 0;
//height: 90%;
width: 100%;
}
#title_container, #left, #right {
z-index: 1000;
position: fixed;
background-color: rgba(0,0,0,0.5);
color: white;
padding: 5px;
}
#title_container {
left: 10px;
bottom: 10px;
}
#left {
left: 0px;
top: 300px;
}
#right {
right: 0px;
top: 300px;
}
#title_container a:link, #title_container a:visited {
color: white;
}
#leftOverlay, #rightOverlay {
color: white;
background-color: #3d3d3d;
border-width: 1px;
}
</style>
</head>
<body>
<div id="title_container">
<big>Side-by-side compare georeferenced rasters</big>
<small><p>Left side: <input type="text" id="leftOverlay" size="40" value="http://mapwarper.net/maps/tile/26003/{z}/{x}/{y}.png"> </p><p>Right side: <input type="text" id="rightOverlay" size="40" value="http://mapwarper.net/maps/tile/25970/{z}/{x}/{y}.png"></p>
<a href="https://github.com/answerquest/answerquest.github.io/blob/master/overlap-custom-side.html">Source code</a> | <a href="http://datameet.org">Datameet</a>
<br>
By <a href="https://nikhilvj.co.in" target="_blank">Nikhil VJ</a> | <a href="https://nikhilvj.co.in/contribute/" target="_blank">i appreciate this!</a>
</small>
</div>
<div id="left">Left</div>
<div id="right">Right</div>
<div id='map'></div>
<script>
// ************************
// INITIAL
// Initiate Leaflet MAP
// background layers, using Leaflet-providers plugin. See https://github.com/leaflet-extras/leaflet-providers
var OSM = L.tileLayer.provider('OpenStreetMap.Mapnik');
var cartoVoyager = L.tileLayer.provider('CartoDB.VoyagerLabelsUnder');
var cartoPositron = L.tileLayer.provider('CartoDB.Positron');
var cartoDark = L.tileLayer.provider('CartoDB.DarkMatter');
var esriWorld = L.tileLayer.provider('Esri.WorldImagery');
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 gHybrid = L.tileLayer('https://{s}.google.com/vt/lyrs=s,h&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 baseLayers = {
"OpenStreetMap": OSM,
"cartoVoyager": cartoVoyager,
"cartoPositron": cartoPositron ,
"cartoDark": cartoDark,
"esriWorld" : esriWorld,
"gStreets" : gStreets,
"gSat" : gSat,
"gHybrid" : gHybrid
};
// *************************
var map = L.map('map', {layers: [esriWorld]}).setView([13.1, 77.594563], 11);
//var tileLayer = new L.TileLayer('https://api.mapbox.com/styles/v1/nikhilsheth/cj8rdd7wu45nl2sps9teusbbr/tiles/256/{z}/{x}/{y}?access_token=pk.eyJ1IjoibmlraGlsc2hldGgiLCJhIjoiQTREVlJuOCJ9.YpMpVVbkxOFZW-bEq1_LIw').addTo(map);
var overlays = { };
var layerControl = L.control.layers(baseLayers, overlays, {collapsed: true}).addTo(map);
// var leftOverlay = L.tileLayer('http://mapwarper.net/maps/tile/26003/{z}/{x}/{y}.png').addTo(map);
var leftOverlay = new L.TileLayer.Functional(function (view) {
var url = document.getElementById('leftOverlay').value
//example: http://mapwarper.net/maps/tile/15155/{z}/{x}/{y}.png
.replace('{z}', view.zoom)
.replace('{y}', view.tile.row)
.replace('{x}', view.tile.column)
.replace('{3}', view.subdomain);
//.replace('{i}', tileSource);
return url;
},
{ maxZoom: 20 }
).addTo(map);
// var rightOverlay = L.tileLayer('http://mapwarper.net/maps/tile/25970/{z}/{x}/{y}.png').addTo(map);
var rightOverlay = new L.TileLayer.Functional(function (view) {
var url = document.getElementById('rightOverlay').value
//example: http://mapwarper.net/maps/tile/15155/{z}/{x}/{y}.png
.replace('{z}', view.zoom)
.replace('{y}', view.tile.row)
.replace('{x}', view.tile.column)
.replace('{3}', view.subdomain);
//.replace('{i}', tileSource);
return url;
},
{ maxZoom: 20 }
).addTo(map);
// Adding event listeners for whenever the tile sources change. from https://stackoverflow.com/a/24865240/4355695
document.getElementById('leftOverlay').onchange = function() { leftOverlay.redraw(); };
document.getElementById('rightOverlay').onchange = function() { rightOverlay.redraw(); };
// Add to the layers menu
layerControl.addOverlay(leftOverlay , "Left Overlay");
layerControl.addOverlay(rightOverlay , "Right Overlay");
// Side by side : https://github.com/Eclipse1979/leaflet-slider
L.control.sideBySide(leftOverlay, rightOverlay).addTo(map);
// Slider : https://github.com/Eclipse1979/leaflet-slider
slider = L.control.slider(function(value) {
//from https://gis.stackexchange.com/a/167173/44746
leftOverlay.setOpacity(value/100);
rightOverlay.setOpacity(value/100);
}, { // slider options
//orientation:'vertical',
position: 'bottomright',
size: '250px',
min: 0, max: 100,
value: 70,
logo: 'O',
collapsed: false,
title: 'Set Opacity',
syncSlider: true // make slider immediately execute function on changing, instead of waiting for mouseup. see https://github.com/Eclipse1979/leaflet-slider/issues/4
}
).addTo(map);
// Show lat-long
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('Lat-Long: ' + e.latlng.lat.toFixed(4) + ',' + e.latlng.lng.toFixed(4) + '<br>Zoom: ' + map.getZoom() /*+ url*/)
.openOn(map);
}
map.on('click', onMapClick);
function helpPopup() {
window.alert("Created for this: https://groups.google.com/forum/#!topic/datameet/qa0HOh903Co");
}
</script>
</body>
</html>