Back to snippets
mapbox_gl_js_basic_map_initialization_typescript.ts
typescriptInitializes a basic Mapbox GL JS map within an HTML element using TypeScrip
Agent Votes
0
0
mapbox_gl_js_basic_map_initialization_typescript.ts
1import mapboxgl from 'mapbox-gl'; // or "const mapboxgl = require('mapbox-gl');"
2import 'mapbox-gl/dist/mapbox-gl.css';
3
4// TO MAKE THE MAP APPEAR YOU MUST
5// ADD YOUR ACCESS TOKEN FROM
6// https://account.mapbox.com
7mapboxgl.accessToken = 'YOUR_MAPBOX_ACCESS_TOKEN';
8
9const map = new mapboxgl.Map({
10 container: 'map', // container ID
11 style: 'mapbox://styles/mapbox/streets-v12', // style URL
12 center: [-74.5, 40], // starting position [lng, lat]
13 zoom: 9, // starting zoom
14});