MapBox Globe Polar Test
Test polar data on mapbox globe
by fxi
HTML
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Add a polygon to a map using a GeoJSON source</title>
<meta name="viewport" content="initial-scale=1,maximum-scale=1,user-scalable=no">
<link href="https://api.mapbox.com/mapbox-gl-js/v2.9.0-beta.1/mapbox-gl.css" rel="stylesheet">
<script src="https://api.mapbox.com/mapbox-gl-js/v2.9.0-beta.1/mapbox-gl.js"></script>
<style>
body { margin: 0; padding: 0; }
#map { position: absolute; top: 0; bottom: 0; width: 100%; }
</style>
</head>
<body>
<div id="map"></div>
<script>
</script>
</body>
</html>
JavaScript
mapboxgl.accessToken = 'pk.eyJ1IjoiZnJlZGZ4aSIsImEiOiJja2psOTE5YWgwNm1jMnJxcDhmY25qc2gwIn0.VM7P6iTelL_rFnxTkO7LBQ';
const map = new mapboxgl.Map({
container: 'map',
style: 'mapbox://styles/mapbox/light-v10',
center: [0, 90],
zoom: 2,
projection: 'globe'
});
const coords = [];
let lat = 90;
let inc = 180 / 360;
for (let lon = -180; lon < 180; lon++) {
coords.push([lon, lat -= inc])
}
const gj = {
"type": "FeatureCollection",
"name": "polar",
"features": [{
"type": "Feature",
"properties": {
"id": 1
},
"geometry": {
"type": "LineString",
"coordinates": coords
}
}]
}
map.on('load', () => {
map.addSource('polar', {
'type': 'geojson',
'data': gj
});
map.addLayer({
'id': 'polar',
'type': 'line',
'source': 'polar',
'layout': {},
'paint': {
'line-color': 'red',
'line-width': 50
}
});
});