Last active
October 3, 2018 03:47
-
-
Save vincentsarago/bf14b820f7a766bb01e5ab6740467fa4 to your computer and use it in GitHub Desktop.
Palu Post/Pre high resolution imagery comparison - Thanks to Digitalglobe
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset='utf-8' /> | |
<title></title> | |
<meta name='viewport' content='initial-scale=1,maximum-scale=1,user-scalable=no' /> | |
<link href="https://api.mapbox.com/mapbox-assembly/v0.16.0/assembly.min.css" rel="stylesheet"> | |
<link href='https://api.tiles.mapbox.com/mapbox-gl-js/v0.49.0/mapbox-gl.css' rel='stylesheet' /> | |
<link href='https://api.mapbox.com/mapbox-gl-js/plugins/mapbox-gl-compare/v0.1.0/mapbox-gl-compare.css' rel='stylesheet' /> | |
<style> | |
body { margin:0; padding:0; } | |
#map { position:absolute; top:0; bottom:0; width:100%; } | |
</style> | |
</head> | |
<body> | |
<style> | |
body { | |
overflow: hidden; | |
} | |
body * { | |
-webkit-touch-callout: none; | |
-webkit-user-select: none; | |
-moz-user-select: none; | |
-ms-user-select: none; | |
user-select: none; | |
} | |
.map { | |
position: absolute; | |
top: 0; | |
bottom: 0; | |
width: 100%; | |
} | |
.left { | |
position: absolute; | |
top: 0; | |
left: 0; | |
} | |
.right { | |
position: absolute; | |
top: 0; | |
right: 0; | |
} | |
.left, .right { | |
z-index: 10; | |
padding: 5px; | |
width: auto; | |
height: auto; | |
font-size: 14px; | |
color: #000; | |
background-color: rgba(255, 255, 255, .5); | |
} | |
.zoom-info { | |
z-index: 10; | |
position: absolute; | |
bottom: 0; | |
right: 0; | |
padding: 0 5px; | |
width: auto; | |
height: auto; | |
font-size: 18px; | |
color: #000; | |
background-color: rgba(255, 255, 255, .5); | |
} | |
</style> | |
<script src='https://api.tiles.mapbox.com/mapbox-gl-js/v0.49.0/mapbox-gl.js'></script> | |
<script src='https://api.mapbox.com/mapbox-gl-js/plugins/mapbox-gl-compare/v0.1.0/mapbox-gl-compare.js'></script> | |
<script async defer src="https://api.mapbox.com/mapbox-assembly/v0.16.0/assembly.js"></script> | |
<script src='https://npmcdn.com/@turf/[email protected]/turf.min.js'></script> | |
<script src="https://code.jquery.com/jquery-3.2.1.min.js"></script> | |
<div id='left' class='map'></div> | |
<div id='right' class='map'></div> | |
<div class='left'></div> | |
<div class='right'></div> | |
<div class='middle-load'></div> | |
<script> | |
const updateHistory = (params) => { | |
const str = []; | |
Object.keys(params).forEach(key => { | |
str.push(`${key}=${params[key]}`); | |
}); | |
const newUrl = `${window.location.origin}/index.html?${str.join('&')}${window.location.hash}` | |
window.history.replaceState( {} , '', newUrl ); | |
return; | |
}; | |
mapboxgl.accessToken = 'pk.eyJ1IjoidmluY2VudHNhcmFnbyIsImEiOiJjamxwa3JkaWkwZ3BjM3dudmZmazQwYjI2In0.eUzks_hqH-QVIlnXUKmKsA'; | |
let center; | |
let zoom; | |
if (window.location.hash !== '') { | |
const hash = window.location.hash.replace('#', '').split('/'); | |
zoom = parseFloat(hash[0]); | |
center = [ parseFloat(hash[1]), parseFloat(hash[2]) ]; | |
} else { | |
center = [119.855,-0.886]; | |
zoom = 15; | |
} | |
var leftMap = new mapboxgl.Map({ | |
container: 'left', | |
style: { version: 8, sources: {}, layers: [] }, | |
center: center, | |
attributionControl : true, | |
zoom: zoom | |
}); | |
var rightMap = new mapboxgl.Map({ | |
container: 'right', | |
style: { version: 8, sources: {}, layers: [] }, | |
center: center, | |
attributionControl : false, | |
zoom: zoom | |
}); | |
rightMap.on('load', () => { | |
$.ajax({ | |
type: 'GET', | |
url: 'https://gist.githubusercontent.com/vincentsarago/e06e8096bf490b1ec2009cbb9d70cb36/raw/' | |
}).done((data) => { | |
rightMap.addSource('gist', { | |
'type': 'geojson', | |
'data': JSON.parse(data) | |
}); | |
rightMap.addLayer({ | |
'id': 'gist-polygon', | |
'type': 'line', | |
'source': 'gist', | |
'layout': { | |
'line-cap': 'round', | |
'line-join': 'round' | |
}, | |
'paint': { | |
'line-color': '#3bb2d0', | |
'line-width': 2 | |
} | |
}); | |
leftMap.addSource('gist', { | |
'type': 'geojson', | |
'data': JSON.parse(data) | |
}); | |
leftMap.addLayer({ | |
'id': 'gist-polygon', | |
'type': 'line', | |
'source': 'gist', | |
'layout': { | |
'line-cap': 'round', | |
'line-join': 'round' | |
}, | |
'paint': { | |
'line-color': '#3bb2d0', | |
'line-width': 2 | |
} | |
}); | |
}); | |
leftMap.addSource('pre', { | |
type: 'raster', | |
url: 'mapbox://mapbox.satellite' | |
}); | |
leftMap.addLayer({ | |
id: 'pre', | |
type: 'raster', | |
source: 'pre', | |
}); | |
$('.left').append(`<span>Pre Event</span>`); | |
rightMap.addSource('post', { | |
type: 'raster', | |
tiles: [ | |
`https://a.tiles.mapbox.com/v4/mapboxsatellite.dg_post_palu_tsunami/{z}/{x}/{y}@2x.jpg?access_token=${mapboxgl.accessToken}`, | |
`https://b.tiles.mapbox.com/v4/mapboxsatellite.dg_post_palu_tsunami/{z}/{x}/{y}@2x.jpg?access_token=${mapboxgl.accessToken}`, | |
`https://c.tiles.mapbox.com/v4/mapboxsatellite.dg_post_palu_tsunami/{z}/{x}/{y}@2x.jpg?access_token=${mapboxgl.accessToken}` | |
], | |
tileSize: 512, | |
bounds: [119.5751953125, -1.142502403706165, 120.0146484375, -0.5273363048115169], | |
minzoom: 13, | |
maxzoom: 18 | |
}); | |
rightMap.addLayer({ | |
id: 'post', | |
type: 'raster', | |
source: 'post', | |
}); | |
$('.right').append(`<span>DG Post Event</span>`); | |
}); | |
rightMap.on('moveend', () => { | |
const zoom = rightMap.getZoom().toString().slice(0,3); | |
const ll = rightMap.getCenter(); | |
const lon = ll.lng.toString().slice(0,7); | |
const lat = ll.lat.toString().slice(0,6); | |
const hash = `#${zoom}/${lon}/${lat}`; | |
window.location.hash = hash; | |
}); | |
var map = new mapboxgl.Compare(leftMap, rightMap, {}); | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment