0

I'm trying to add Azure Maps to a simple Angular app.

I get the error below. Any idea why it happens and how I can fix it?

atlas.min.js:2509 Error: AuthenticationManager finished initializing, but no token is available
    at atlas.min.js:2509
    at ZoneDelegate.invoke (zone-evergreen.js:365)
    at Object.onInvoke (core.js:40794)
    at ZoneDelegate.invoke (zone-evergreen.js:364)
    at Zone.run (zone-evergreen.js:124)
    at zone-evergreen.js:851
    at ZoneDelegate.invokeTask (zone-evergreen.js:400)
    at Object.onInvokeTask (core.js:40772)
    at ZoneDelegate.invokeTask (zone-evergreen.js:399)
    at Zone.runTask (zone-evergreen.js:168)

The steps I have followed to add it are:

1 - Install Azure Maps

npm i azure-maps-control

2 - Create a component for the map

import { Component, OnInit } from '@angular/core';
import { FormGroup, FormControl } from '@angular/forms';
import { AddressSearchService } from '../address-search.service';
import { AddressSearchJson, AddressSearchResult } from '../address-search-result.model';
import { Map, AuthenticationType, HtmlMarker } from 'azure-maps-control';


@Component({
  selector: 'app-address-search',
  templateUrl: './address-search.component.html',
  styleUrls: ['./address-search.component.css']
})
export class AddressSearchComponent implements OnInit {


  // Azure Active Directory Authentication Client ID
  // or Shared Key Authentication KEY
  // get it from portal.azure.com
  key: 'sharedKeyPrimaryKey';
  map: any;


  ngOnInit(): void { 
        // Initialize a map instance.
    this.map = new Map('mapContainer', {
      authOptions: {
        authType: AuthenticationType.subscriptionKey,
        subscriptionKey: this.key
      }
    });

    // Wait until the map resources are ready.
    this.map.events.add('ready', () => {
      // Create a HTML marker and add it to the map.
      this.map.markers.add(new HtmlMarker({
        color: 'DodgerBlue',
        text: '10',
        position: [0, 0]
      }));
    });
   }

  constructor(private adressSearchService: AddressSearchService) { }
}

3 - Create the view

    <div id="mapContainer"></div>

4 - Modify angular.json

            "styles": [
              "src/styles.css",
              "node_modules/azure-maps-control/dist/atlas.min.css"
            ],
            "scripts": [
              "node_modules/azure-maps-control/dist/atlas.min.js"
            ]

5 - ensure that I'm using the correct Azure Maps key (Shared Key Authentication - Primary Key)

enter image description here

1 Answer 1

1

Hey I believe I can help you on this! I had a lot of trouble getting Azure maps to work with Angular. I am fairly new to Angular and don't know exactly why your code gives that error but I know its something to do in your component because everything else is correct and is exactly how I have it. I have copied my component code for loading the map below in the hopes that it helps you.

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


@Component({
  selector: 'app-azureMap',
  templateUrl: './azureMap.component.html',
  styleUrls: ['./azureMap.component.css']
})

export class AzureMapComponent implements OnInit {
  // Azure Active Directory Authentication Client ID
  // or Shared Key Authentication KEY
  // get it from portal.azure.com
  key: string = 'your key';
  map: any;

  constructor(
  ) {
  }

  ngOnInit() {
    //Initialize a map instance.
    this.map = new atlas.Map('mapContainer', {
      center: [-122.33, 47.6],
      zoom: 12,
      view: 'Auto',

      authOptions: {
        authType: atlas.AuthenticationType.subscriptionKey,
        subscriptionKey: this.key
      }
    });

    //Wait until the map resources are ready.
    this.map.events.add('ready', () => {
      //Create a HTML marker and add it to the map.
       this.map.markers.add(new atlas.HtmlMarker({
         color: 'DodgerBlue',
         text: '10',
         position: [0, 0]
       }));
    });
  }

}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.