Skip to content

Instantly share code, notes, and snippets.

@andrewharvey
Created July 18, 2019 04:43
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 andrewharvey/f9da7d11d72dc6c40d3195aa9ab94b92 to your computer and use it in GitHub Desktop.
Save andrewharvey/f9da7d11d72dc6c40d3195aa9ab94b92 to your computer and use it in GitHub Desktop.
Display a map // source https://jsbin.com/leyiked
<!DOCTYPE html>
<html>
<head>
<meta charset='utf-8' />
<title>Display a map</title>
<meta name='viewport' content='initial-scale=1,maximum-scale=1,user-scalable=no' />
<script src='https://api.tiles.mapbox.com/mapbox-gl-js/v1.1.1/mapbox-gl.js'></script>
<link href='https://api.tiles.mapbox.com/mapbox-gl-js/v1.1.1/mapbox-gl.css' rel='stylesheet' />
<style>
body { margin:0; padding:0; }
#map { position:absolute; top:0; bottom:0; width:100%; }
</style>
</head>
<body>
<script src='https://api.mapbox.com/mapbox-gl-js/plugins/mapbox-gl-geocoder/v4.4.1/mapbox-gl-geocoder.min.js'></script>
<link rel='stylesheet' href='https://api.mapbox.com/mapbox-gl-js/plugins/mapbox-gl-geocoder/v4.4.1/mapbox-gl-geocoder.css' type='text/css' />
<div id='map'></div>
<div id='map'></div>
<script>
mapboxgl.accessToken = 'pk.eyJ1IjoiYWxhbnRnZW8tcHJlc2FsZXMiLCJhIjoiY2pxcmZ1cW1mMG1tcDN4bDVvYzA4MWg5MyJ9.7QtVj_0ythHwEg1n_zaRTQ';
var map = new mapboxgl.Map({
container: 'map', // container id
style: 'mapbox://styles/alantgeo-presales/cjy2vegut24iv1cl0woxc2qei', // stylesheet location
center: [135.00, -27.18], // starting position [lng, lat]
zoom: 3 // starting zoom
});
map.on("click", "census", function(e) {
var coordinates = e.features[0].geometry.coordinates.slice();
const description = '<ul>' +
'<li>Total Indigenous Persons: ' + e.features[0].properties.Tot_Indigenous_P + '</li>' +
'<li>Total Persons: ' + e.features[0].properties.Tot_Tot_P + '</li>' +
'<li>Indigenous Percent: ' + Math.round(e.features[0].properties.Tot_Indigenous_P * 100.0 / e.features[0].properties.Tot_Tot_P, 2) + '</li>' +
'</ul>';
// document.getElementById('info').innerHTML = html;
new mapboxgl.Popup()
.setLngLat(coordinates)
.setHTML(description)
.addTo(map);
})
</script>
<script id="jsbin-source-html" type="text/html"><!DOCTYPE html>
<html>
<head>
<meta charset='utf-8' />
<title>Display a map</title>
<meta name='viewport' content='initial-scale=1,maximum-scale=1,user-scalable=no' />
<script src='https://api.tiles.mapbox.com/mapbox-gl-js/v1.1.1/mapbox-gl.js'><\/script>
<link href='https://api.tiles.mapbox.com/mapbox-gl-js/v1.1.1/mapbox-gl.css' rel='stylesheet' />
<style>
body { margin:0; padding:0; }
#map { position:absolute; top:0; bottom:0; width:100%; }
</style>
</head>
<body>
<script src='https://api.mapbox.com/mapbox-gl-js/plugins/mapbox-gl-geocoder/v4.4.1/mapbox-gl-geocoder.min.js'><\/script>
<link rel='stylesheet' href='https://api.mapbox.com/mapbox-gl-js/plugins/mapbox-gl-geocoder/v4.4.1/mapbox-gl-geocoder.css' type='text/css' />
<div id='map'></div>
<div id='map'></div>
<script>
mapboxgl.accessToken = 'pk.eyJ1IjoiYWxhbnRnZW8tcHJlc2FsZXMiLCJhIjoiY2pxcmZ1cW1mMG1tcDN4bDVvYzA4MWg5MyJ9.7QtVj_0ythHwEg1n_zaRTQ';
var map = new mapboxgl.Map({
container: 'map', // container id
style: 'mapbox://styles/alantgeo-presales/cjy2vegut24iv1cl0woxc2qei', // stylesheet location
center: [135.00, -27.18], // starting position [lng, lat]
zoom: 3 // starting zoom
});
map.on("click", "census", function(e) {
var coordinates = e.features[0].geometry.coordinates.slice();
const description = '<ul>' +
'<li>Total Indigenous Persons: ' + e.features[0].properties.Tot_Indigenous_P + '</li>' +
'<li>Total Persons: ' + e.features[0].properties.Tot_Tot_P + '</li>' +
'<li>Indigenous Percent: ' + Math.round(e.features[0].properties.Tot_Indigenous_P * 100.0 / e.features[0].properties.Tot_Tot_P, 2) + '</li>' +
'</ul>';
// document.getElementById('info').innerHTML = html;
new mapboxgl.Popup()
.setLngLat(coordinates)
.setHTML(description)
.addTo(map);
})
<\/script>
</body>
</html>
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment