Skip to content

Instantly share code, notes, and snippets.

@peterqliu
Last active April 13, 2021 22:21
Show Gist options
  • Save peterqliu/7147b0a605ee1d0f3412a35cb10c6c46 to your computer and use it in GitHub Desktop.
Save peterqliu/7147b0a605ee1d0f3412a35cb10c6c46 to your computer and use it in GitHub Desktop.
<!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/v0.47.0/mapbox-gl.js'></script>
<link href='https://api.tiles.mapbox.com/mapbox-gl-js/v0.47.0/mapbox-gl.css' rel='stylesheet' />
<style>
body { margin:0; padding:0; }
#map { position:absolute; top:0; bottom:0; width:100%; }
</style>
</head>
<body>
<div id='map'></div>
<script>
mapboxgl.accessToken = 'pk.eyJ1IjoicGV0ZXJxbGl1IiwiYSI6ImNrbmdoM2d0cDBjeXAydnBjcTFvcDV4YWIifQ._dh1WoYUQQxa8qzjNXEPRQ';
var map = new mapboxgl.Map({
container: 'map', // container id
style: 'mapbox://styles/mapbox/dark-v9', // stylesheet location
center:[0,10],
pitch:60,
zoom: 9 // starting zoom
});
var data = {
"type": "FeatureCollection",
"features": [
{
"type": "Feature",
"properties": {},
"geometry": {
"type": "Point",
"coordinates": [0,10]
}
}
]
}
map.on('load', function(){
map
.addLayer({
id: 'leaderline',
type: 'symbol',
source: {
'type': 'geojson',
'data': data
},
layout: {
'text-font':["Source Code Pro Medium","Arial Unicode MS Regular"],
'text-field':'------------',
'text-letter-spacing':-1,
'text-rotate':90,
'text-anchor':'left',
'text-max-width':40,
'text-justify':'left',
'text-allow-overlap': true
},
paint:{
'text-color':'red'
}
})
.addLayer({
id: 'label',
type: 'symbol',
source: {
'type': 'geojson',
'data': data
},
layout: {
'text-field':'Mali',
'text-size':16,
'text-offset': [0,-6],
'text-allow-overlap': true
},
paint: {
'text-color': 'red',
}
})
})
map.on('pitch', function(){
var ratio = map.getPitch()/60
map
.setLayoutProperty('leaderline', 'text-size', ratio*16)
.setLayoutProperty('label', 'text-offset', [0, -6*ratio])
})
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment