Created
March 22, 2019 14:58
-
-
Save vincentsarago/4794500ab1b9eb042384dd8e939be485 to your computer and use it in GitHub Desktop.
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.tiles.mapbox.com/mapbox-gl-js/v0.49.0/mapbox-gl.css' rel='stylesheet' /> | |
| <link href="https://api.mapbox.com/mapbox-assembly/v0.16.0/assembly.min.css" rel="stylesheet"> | |
| <script async defer src="https://api.mapbox.com/mapbox-assembly/v0.16.0/assembly.js"></script> | |
| <style> | |
| body { margin:0; padding:0; } | |
| #map { position:absolute; top:0; bottom:0; width:100%; } | |
| 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%; | |
| } | |
| .zoom-info { | |
| z-index: 10; | |
| position: absolute; | |
| bottom: 20px; | |
| right: 0; | |
| padding: 5px; | |
| width: auto; | |
| height: auto; | |
| font-size: 18px; | |
| color: #FFF; | |
| } | |
| </style> | |
| </head> | |
| <body> | |
| <script src='https://api.tiles.mapbox.com/mapbox-gl-js/v0.49.0/mapbox-gl.js'></script> | |
| <script src='https://code.jquery.com/jquery-3.2.1.min.js'></script> | |
| <div id='map' class='map'> | |
| <div class="zoom-info"><span></span></div> | |
| </div> | |
| <script> | |
| const parseParams = (wLoc) => { | |
| const paramList = wLoc.replace('?', '').split('&') | |
| const outParams = {} | |
| for (let i = 0; i < paramList.length; i++) { | |
| let tPar = paramList[i].split('=') | |
| outParams[tPar[0]] = tPar[1] | |
| } | |
| return outParams | |
| } | |
| const endpoint = 'https://mg97rjtar2.execute-api.us-east-1.amazonaws.com/production' | |
| mapboxgl.accessToken = 'pk.eyJ1IjoidmluY2VudHNhcmFnbyIsImEiOiJjanNienU3M2swMmZmM3lubTN3Z3QwOXNmIn0.cJy8Uht_QUMNB0K9u9nrwg' | |
| var map = new mapboxgl.Map({ | |
| container: 'map', | |
| style: 'mapbox://styles/mapbox/satellite-v9', | |
| center: [ -80.123086, 25.992706 ], | |
| attributionControl: true, | |
| zoom: 5, | |
| hash: true | |
| }) | |
| map.addControl(new mapboxgl.NavigationControl()) | |
| map.on('load', () => { | |
| const params = parseParams(window.location.search) | |
| if (params.id) { | |
| $.getJSON(`${endpoint}/${params.id}.json`).done() | |
| .then(data => { | |
| map.addLayer({ | |
| 'id': 'raster-tiles', | |
| 'type': 'raster', | |
| 'source': { | |
| 'type': 'raster', | |
| 'tiles': [ data.tiles ], | |
| 'bounds': data.bounds, | |
| 'minzoom': data.minzoom, | |
| 'maxzoom': data.maxzoom, | |
| 'tileSize': 256 | |
| } | |
| }) | |
| map.fitBounds([[data.bounds[0], data.bounds[1]], [data.bounds[2], data.bounds[3]]]) | |
| }) | |
| .catch(err => { | |
| console.warn(err) | |
| }) | |
| } | |
| }) | |
| map.on('zoom', function (e) { | |
| $('.zoom-info span').text((map.getZoom() + 1).toString().slice(0,6)) | |
| }) | |
| </script> | |
| </body> | |
| </html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment