Can anyone help me figure out how to set the accessToken for mapbox-gl in an example on StackBlitz?
After attempting to do so, I received an error message stating "Cannot assign to 'accessToken' because it is a constant or a read-only property".
I've already tried some solutions suggested in another question: Mapbox-gl typing won't allow accessToken assignment
import { Component, ViewChild, ElementRef } from '@angular/core';
import * as mapboxgl from 'mapbox-gl';
@Component({
selector: 'my-app',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css']
})
export class AppComponent {
@ViewChild('map') mapElement: ElementRef;
map: mapboxgl.Map;
ngOnInit() {
mapboxgl.accessToken = '<token>';
this.map = new mapboxgl.Map({
container: this.mapElement.nativeElement,
style: 'mapbox://styles/mapbox/streets-v11',
center: [-77.04, 38.907],
zoom: 11.15
});
}
}
For the complete code example, check out: https://stackblitz.com/edit/angular-9djiw2