Skip to content

Instantly share code, notes, and snippets.

@mastersigat
Created February 12, 2021 22:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mastersigat/444552e8fda5d0adc12f1a0c428721b5 to your computer and use it in GitHub Desktop.
Save mastersigat/444552e8fda5d0adc12f1a0c428721b5 to your computer and use it in GitHub Desktop.
#MapboxGL / SwipeMaps
license: mit
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>Swipe between maps</title>
<meta name="viewport" content="initial-scale=1,maximum-scale=1,user-scalable=no" />
<script src="https://cdn.maptiler.com/maplibre-gl-js/v1.13.0-rc.4/mapbox-gl.js"></script>
<link href="https://cdn.maptiler.com/maplibre-gl-js/v1.13.0-rc.4/mapbox-gl.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%;
}
</style>
<script src="https://api.mapbox.com/mapbox-gl-js/plugins/mapbox-gl-compare/v0.4.0/mapbox-gl-compare.js"></script>
<link
rel="stylesheet"
href="https://api.mapbox.com/mapbox-gl-js/plugins/mapbox-gl-compare/v0.4.0/mapbox-gl-compare.css"
type="text/css"
/>
<div id="comparison-container">
<div id="before" class="map"></div>
<div id="after" class="map"></div>
</div>
<script>
var beforeMap = new mapboxgl.Map({
container: 'before',
style: 'https://openmaptiles.geo.data.gouv.fr/styles/osm-bright/style.json',
zoom: 14,
center: [-1.68, 48.1272],
});
var afterMap = new mapboxgl.Map({
container: 'after',
style: 'https://geoserveis.icgc.cat/contextmaps/icgc.json',
zoom: 14,
center: [-1.68, 48.1272],
});
// A selector or reference to HTML element
var container = '#comparison-container';
var map = new mapboxgl.Compare(beforeMap, afterMap, container, {
// Set this to enable comparing two maps by mouse movement:
// mousemove: true
});
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment