我正在尝试在网页上显示地图。为此,我正在使用带有角度的 mapbox gl。在这里我想检查访问令牌是否有效然后调用此方法
initMapIndividuals();
如果令牌无效/未经授权我想显示错误消息。
loadMap(): void {
try {
// Initialize map
mapboxgl!.accessToken = this.mapReportConfigData.accessToken;
this.map = new mapboxgl.Map({
container: this.mapReportConfigData.container,
style: this.mapReportConfigData.style,
});
// Set map
this.initMap();
// If mapbox server issue
this.map.on("error", (response) => {
this.showError(
"500",
"err_no_map_reports",
);
});
} catch (error) {
throw new CustomError(error.message, 404, false);
}
}
在这里,如果令牌有效,我想调用
initMap()
方法。如果失败,我想显示此错误消息。