Error in the azure-maps-control library

Santiago Mesa Parra 10 Reputation points
2023-06-07T15:57:58.6333333+00:00

I have an error when I try to load the maps using your library, At first I installed the library and ran my application and everything was fine, it worked great, then I created a component, there I implemented the OnInit method, called the library and it stopped working.

And I don't understand why I get that error knowing that what I use inside the OnInit is fine

And this would be the error that I get
User's image

This is my package.json

{
  "name": "azuremapstestdllo",
  "version": "0.0.0",
  "scripts": {
    "ng": "ng",
    "start": "ng serve",
    "build": "ng build",
    "watch": "ng build --watch --configuration development",
    "test": "ng test"
  },
  "private": true,
  "dependencies": {
    "@angular/animations": "^16.0.0",
    "@angular/common": "^16.0.0",
    "@angular/compiler": "^16.0.0",
    "@angular/core": "^16.0.0",
    "@angular/forms": "^16.0.0",
    "@angular/platform-browser": "^16.0.0",
    "@angular/platform-browser-dynamic": "^16.0.0",
    "@angular/router": "^16.0.0",
    "azure-maps-control": "^2.2.7",
    "rxjs": "~7.8.0",
    "tslib": "^2.3.0",
    "zone.js": "~0.13.0"
  },
  "devDependencies": {
    "@angular-devkit/build-angular": "^16.0.4",
    "@angular/cli": "~16.0.4",
    "@angular/compiler-cli": "^16.0.0",
    "@types/jasmine": "~4.3.0",
    "jasmine-core": "~4.6.0",
    "karma": "~6.4.0",
    "karma-chrome-launcher": "~3.2.0",
    "karma-coverage": "~2.2.0",
    "karma-jasmine": "~5.1.0",
    "karma-jasmine-html-reporter": "~2.0.0",
    "typescript": "~5.0.2"
  }
}

My component is like this

import { Component, OnInit } from '@angular/core';
import * as atlas from 'azure-maps-control';

@Component({
  selector: 'app-map',
  templateUrl: './map.component.html',
  styleUrls: ['./map.component.css']
})
export class MapComponent implements OnInit {
  ngOnInit(): void {
    const map = new atlas.Map('mapContainer', {
      authOptions: {
        authType: atlas.AuthenticationType.subscriptionKey,
        subscriptionKey: ''
      }
    });
  }

}
Azure Maps
Azure Maps
An Azure service that provides geospatial APIs to add maps, spatial analytics, and mobility solutions to apps.
833 questions
Microsoft 365 and Office | Development | Office JavaScript API
{count} votes

1 answer

Sort by: Most helpful
  1. rbrundritt 20,836 Reputation points Microsoft Employee Moderator
    2023-06-07T16:38:48.21+00:00

    Azure Maps was designed to be used in standard JavaScript/TypeScript and doesn't do any anything to align with any specific framework. There are open-source libraries that wrap Azure Maps for Angular which I would recommend. Looking at a couple of these libraries, here is how they load the map:

    • Looking at this library, they load the map using ngAfterViewInit.
    • This library uses ngOnInit however it is using the hosted JavaScript files and not the NPM library with TypeScript.
    1 person found this answer helpful.

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.