Coder Social home page Coder Social logo

arnaudleclerc / ng-azure-maps Goto Github PK

View Code? Open in Web Editor NEW
15.0 3.0 14.0 34.02 MB

Angular wrapper around azure maps

License: MIT License

JavaScript 8.90% TypeScript 74.47% HTML 16.00% SCSS 0.60% CSS 0.04%
angular azure-maps azure-maps-control

ng-azure-maps's Introduction

release NPM Version NPM Downloads license

ng-azure-maps

ng-azure-maps is an Angular library, mostly HTML driven wrapper of the azure-maps-controls package allowing to easilly integrate its functionalities into an Angular application.

4 Maps sample

Install the package

The package is available on npm. You need to install the dependencies to the azure-maps-* packages by yourself.

npm i --save azure-maps-control azure-maps-drawing-tools azure-maps-rest ng-azure-maps

Register the module

An AzureMapsModule can be imported from the ng-azure-maps namespace. This class exposes a forRoot method which can be called by your angular module and where the configuration of the library can be given.

import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';

import { AppComponent } from './app.component';
import { AzureMapsModule } from 'ng-azure-maps';
import { environment } from '../environments/environment';

@NgModule({
  declarations: [
    AppComponent
  ],
  imports: [
    BrowserModule,
    AzureMapsModule.forRoot({
      authOptions: environment.authOptions
    })
  ],
  providers: [],
  bootstrap: [AppComponent]
})
export class AppModule { }

The module can also be lazy loaded using the forChild method.

import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
import { MapComponent } from './map/map.component';
import { AzureMapsModule } from 'ng-azure-maps';
import { environment } from '../../environments/environment';
import { RouterModule, Routes } from '@angular/router';

const routes: Routes = [{ path: "", component: MapComponent }];

@NgModule({
  declarations: [MapComponent],
  imports: [
    CommonModule,
    RouterModule.forChild(routes),
    AzureMapsModule.forChild({
      authOptions: environment.authOptions
    })
  ]
})
export class MapModule { }

If you need to dynamically set the azure maps configuration, you can override the AZUREMAPS_CONFIGURATION injection token as follows :

import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';

import { AppComponent } from './app.component';
import { AzureMapsModule, AZUREMAPS_CONFIG } from 'ng-azure-maps';
import { environment } from '../environments/environment';

@NgModule({
  declarations: [
    AppComponent
  ],
  imports: [
    BrowserModule,
    AzureMapsModule.forRoot()
  ],
  providers: [
    {
      provide: AZUREMAPS_CONFIG,
      useValue: {
        authOptions: environment.authOptions
      }
    }
  ],
  bootstrap: [AppComponent]
})
export class AppModule { }

You can also use an APP_INITIALIZER to set the configuration if you need to retrieve the configuration asynchronously :

import { BrowserModule } from '@angular/platform-browser';
import { APP_INITIALIZER, NgModule } from '@angular/core';

import { AppComponent } from './app.component';
import { AzureMapsModule, setAzureMapsConfiguration } from 'ng-azure-maps';
import { HttpClient } from '@angular/common/http';
import { AuthenticationType } from 'azure-maps-control';

function setAuthentication(httpClient: HttpClient): () => Promise<void> {
  return (): Promise<void> => {
    return new Promise<void>((resolve, reject) => {
      httpClient.get<{ subscriptionKey: string }>('<your-api-endpoint>').subscribe(auth => {
        setAzureMapsConfiguration({
          authOptions: {
            authType: AuthenticationType.subscriptionKey,
            subscriptionKey: auth.subscriptionKey
          }
        });
        resolve();
      }, error => {
        reject(error);
      });
    });
  };
}

@NgModule({
  declarations: [
    AppComponent
  ],
  imports: [
    BrowserModule,
    AzureMapsModule.forRoot(),
  ],
  providers: [
    {
      provide: APP_INITIALIZER,
      useFactory: setAuthentication,
      deps: [HttpClient],
      multi: true
    }
  ],
  bootstrap: [AppComponent]
})
export class AppModule { }

How To

Please refer to the Wiki for more details.

ng-azure-maps's People

Contributors

arnaudleclerc avatar dependabot[bot] avatar giotab avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

ng-azure-maps's Issues

Add Angular 17 Support

It's not possible to install the package using Angular 17.

Please, add support for the new Angular version.

Loading script through APP_INITIALIZER fails on interceptor

When trying to dynamically set the subscription key through the APP_INITIALIZER, we need to use a setAzureMapsConfiguration function in order to provide azure maps with configured element
providers: [ { provide: APP_INITIALIZER, useFactory: () => new Promise((res, rej) => {... setAzureMapsConfiguration()}), deps: [...], multi: true } ],
However, this would set
{ provide: AZUREMAPS_CONFIG, useValue: configuration },
AZUREMAPS_CONFIG to have value of undefined, as we are not providing it directly through
AzureMapsModule.forRoot({ authOptions: environment.authOptions })
or overriding it in the app module with
{ provide: AZUREMAPS_CONFIG, useValue: { authOptions: environment.authOptions } }
Without this token the AtlasRestAuthenticationInterceptor is failing, because if loaded asynchronously, the token is never set in the first place. I assume that we would still need to provide this token in order to make interceptor work. So that, it wouldn't really work with APP_INITIALIZER

Use dynamic configuration in AzureMapsModule.forRoot()

Hello,

I'm trying to load ng-azure-maps with data that comes from a settings API. So my subscriptionKey is different per environment, and not static.

I already know it's impossible to have a service injected into the imports part of the @NgModule decorator. But I would think it's possible to have a provider which overrides the AZUREMAPS_CONFIG InjectionToken.

import { AZUREMAPS_CONFIG } from 'ng-azure-maps/lib/configuration';

...

providers: [
  {
      provide: AZUREMAPS_CONFIG,
      useValue: {
          authOptions: {
              authType: AuthenticationType.subscriptionKey,
              subscriptionKey: 'TEST'
          }
      }
  }
]

Now I'm facing the error:

Module not found: Error: Can't resolve 'ng-azure-maps/lib/configuration' in 'C:\MyProject\ClientApp\src\app'

Am I on the right track? Or is there another way to do this?

Zoom control, map-drawing-toolbar and map-html-marker not showing up

Hi!
This code is giving me this layout:

<azure-map id="map" [showLogo]=false (onReady)="mapReady()" >
<map-zoom-control [position]="controlPosition.TopLeft">

<map-compass-control [position]="controlPosition.BottomLeft">
<map-html-marker *ngFor="let markerPosition of markerPositions" [position]='markerPosition'>

image

Why is it not working??

Angular 16 support

It's not possible to install the package using Angular 16.

Please, add support for the new Angular version.

CommonJS or AMD dependencies warning

Warning: /usr/src/node_modules/@azure/ms-rest-js/es/lib/util/utils.js depends on 'uuid/v4'. CommonJS or AMD dependencies can cause optimization bailouts.
For more info see: https://angular.io/guide/build#configuring-commonjs-dependencies

Warning: /usr/src/node_modules/ng-azure-maps/fesm2020/ng-azure-maps.mjs depends on 'azure-maps-drawing-tools'. CommonJS or AMD dependencies can cause optimization bailouts.
For more info see: https://angular.io/guide/build#configuring-commonjs-dependencies

Warning: /usr/src/node_modules/ng-azure-maps/fesm2020/ng-azure-maps.mjs depends on 'azure-maps-rest'. CommonJS or AMD dependencies can cause optimization bailouts.
For more info see: https://angular.io/guide/build#configuring-commonjs-dependencies

Unit-tests are crashing at import AzureMapsModule.

I am following the Readme to implement the maps. The application at runtime works great with no issues.

However, my unit-tests are crashing at import line, the AzureMapsModule for the single reason:

nx run name-plate-app:test --testFile=app.component.spec
[FAIL] apps/nameplate/src/app/app.component.spec.ts
โ— Test suite failed to run

TypeError: window.URL.createObjectURL is not a function

 import { ReactiveFormsModule } from '@angular/forms';
 import { AzureMapsModule } from 'ng-azure-maps';
 ^
 import { environment } from '../../environments/environment';
  
  at i (../../node_modules/azure-maps-control/dist/atlas.min.js:55:606)
  at ../../node_modules/azure-maps-control/dist/atlas.min.js:55:386100
  at e (../../node_modules/azure-maps-control/dist/atlas.min.js:55:376)
  at ../../node_modules/azure-maps-control/dist/atlas.min.js:55:420
  at ../../node_modules/azure-maps-control/dist/atlas.min.js:55:69
  at Object.<anonymous> (../../node_modules/azure-maps-control/dist/atlas.min.js:55:173)
  at ../../node_modules/ng-azure-maps/bundles/ng-azure-maps.umd.js:2:128
  at Object.<anonymous> (../../node_modules/ng-azure-maps/bundles/ng-azure-maps.umd.js:5:2)
  at Object.<anonymous> (src/app/nameplate/nameplate.module.ts:7:1)
  at Object.<anonymous> (src/app/app.component.spec.ts:4:1)

Azure Map not showing properly

I am facing issue with azure map display and adding Markers.

Initially map view is tiny and marker added are also not at its proper position.

Screenshot (7)

Also I want to remove stats and shortcuts. How can I resolve these issues.

Service does not provide aborter

Hi Arnauld,

I implemented fuzzy search using search service you are providing but one thing that is no there as in the orginal one is an aborter. How can I implement this aborter with your service?

constructor(private searchService: SearchService,

private performFuzzySearch(data: any): void {
const { Query } = data;
//enable for debugging purposes only
const pin = true;
const pinAlldataCenter = true;
this.loadingService.showSpinner({ text: 'Searching...', diameter: 100 });

    //Perform a fuzzy search on the users query.
    this.searchService.searchFuzzy(encodeURIComponent(Query), {
        countrySet: this.countrySet,
        maxFuzzyLevel: 2,
        limit: 10,
        view: 'Auto'
    }).subscribe((response) => {
        this.loadingService.closeSpinner();
        let totalHits = response?.summary?.numResults || 0;
        if(totalHits > 0){

Map canvas is not stretched

Hi!
I have managed to see the map but the map control (canvas size) is always the same, 400x300px. How can I get it to stretch?
I have set the width and height on the azure-map but nothing happens.

image

Workflows are referencing vulnerable actions

Hello, there!

As part of the university research we are currently doing regarding the security of Github Actions, we noticed that one or many of the workflows that are part of this repository are referencing vulnerable versions of the third-party actions. As part of a disclosure process, we decided to open issues to notify GitHub Community.

Please note that there are could be some false positives in our methodology, thus not all of the open issues could be valid. If that is the case, please let us know, so that we can improve on our approach. You can contact me directly using an email: ikoishy [at] ncsu.edu

Thanks in advance

  1. The workflow release.yml is referencing action gittools/actions/gitversion/setup using references v0.9.6. However this reference is missing the commit 90150b4 which may contain fix to the vulnerability.
  2. The workflow release.yml is referencing action gittools/actions/gitversion/execute using references v0.9.6. However this reference is missing the commit 90150b4 which may contain fix to the vulnerability.

The vulnerability fix that is missing by actions' versions could be related to:
(1) CVE fix
(2) upgrade of vulnerable dependency
(3) fix to secret leak and others.
Please consider updating the reference to the action.

If you end up updating the reference, please let us know. We need the stats for the paper :-)

Search Service issues

Hi,

I am using search service and I have an issue and 2 questions on it.

  1. CategorySet parameter is missing in SearchNearby

  2. Using Timeout parameter in search service is not creating an aborter, can you please explain how it can he achieved

  3. An issue with search nearby is that despite giving a radius (of 100-500 meters) points are returned only on top right side of the coordinate clicked. I have tried it with multiple geographies and it happened every single time

  4. I am creating a polygon using isochrones around a point and I want to search in geometry. I have tried multiple ways but it does not seem to work as the coordinates I get by using CalculateRange when passed to SearchPolygon give error.

Bug: Lacking return type

Error: node_modules/azure-maps-drawing-tools/typings/index.d.ts:140:20 - error TS7010: 'edit', which lacks return-type annotation, implicitly has an 'any' return type.

140             public edit(shape: azmaps.Shape)

Angular 15 support

Hello, we just updated our project to Angular 15, and realized that this one package is not working with it:
image

Is there a chance that this project will be updated or is there any suggestion for a replacement?

Map showing without style or misplaced items, like Zoom-in, Zoom-out and Pin

I am having an issue with Angular 15 stack,

"azure-maps-control": "~2.3.2",
"azure-maps-drawing-tools": "~1.0.0",
"azure-maps-rest": "^2.1.0",
"ng-azure-maps": "7.0.0",

image

The warning message in console I think related to this is

image

But I tried to include in

It still gives me the warning and the map not showing correctly

If I use Angular 14 with this stack
"azure-maps-control": "~2.3.2",
"azure-maps-drawing-tools": "~1.0.0",
"azure-maps-rest": "^2.1.0",
"ng-azure-maps": "6.0.0",

Everything looks great

"This page appears to be missing CSS declarations for Mapbox GL JS"

During page load I'm seeing the following warning in the console "This page appears to be missing CSS declarations for Mapbox GL JS".

Versions...
"azure-maps-control": "^2.0.31",
"azure-maps-drawing-tools": "^0.1.4",
"azure-maps-rest": "^2.0.5",
"ng-azure-maps": "^2.0.3",

Map does not stretch upon page load

IT does not want to stretch, style is applied.
IT stretches after I resize browser wireframe.
But it should not be this way.
Can you suggest something

azure-map {
position: absolute;
height: 100vh;
width: 100%;
}

image

"Object Unsubscribed" Error On Component Destroy

When navigating away from a page with the azure-maps component loaded on it, two "object unsubscribed" errors appear in the browser console:
image
When omitting the maps component, the error doesn't show up. The component works as expected otherwise.

Using Angular 11.1.2 on the latest Chrome version.

node_modules package error

Hi,
I'm trying to install and use this package to create an azure map on my angular project, but after install the packages and build the application, appears the following errors.
image

I hope you can help me.

Thanks!.

Blank map rendered

Hi!

I was trying to use ng-azure-maps, but when loading the component, the map renders as a white area.

What could I be doing wrong?

This is my module:

image

And this is my component:

image

The resulting page in ng is:

image

Thanks very much in advance!
Thomas

Trying to use togglePopup()

When I try to call marker.togglePopup(), I receive the following error:
The marker must be added to a map before calling togglePopup().

Here is my map setup:
<azure-map [center]="[Longitude, Latitude]"
[pitch]="0"
[showBuildingModels]="true"
[zoom]="16">
<map-html-marker (onMouseUp)="HoverAndLeave($event, marker)"
*ngFor="let marker of PeopleMarkers | async"
[draggable]="false" [position]="marker.getOptions().position"
[text]="marker.getOptions().text">

Here is the PeopleMarkers setup:
PeopleMarkers: Observable<CustomHtmlMarker[]>;

Here is my CustomHtmlMarker:
class CustomHtmlMarker extends atlas.HtmlMarker {
constructor(public customOptions: HtmlMarkerOptions) {
super(customOptions);
}

I just needed to add a custom field for my use.

Here is the creation of a marker:
const marker: CustomHtmlMarker = new CustomHtmlMarker({
text: ${newperson.pwauser.firstName.substring(0, 1)}${newperson.pwauser.lastName.substring(0, 1)},
position: [newperson.longitude, newperson.latitude],
connectionid: connectionid,
popup: new atlas.Popup({
content: <div style="padding: 10px;">${newperson.pwauser.firstName} ${newperson.pwauser.lastName}</div>,
}),
});

Any help is appreciated. I am banging my head against the wall.

Map controls and SearchService response object

Following an Azure Maps tutorial online found here:https://www.youtube.com/watch?v=wpTAU9_H7ro

I have had several issues which have meant I am unable to progress:

  1. When trying the set the map controls position ```
    <azure-map [center]="[-0.182679, 52.336618]" [zoom]="11" [showLogo]="false" (onClick)="mapClick($event.event)"
    (onReady)="mapReady($event)">
``` I am getting this error ``` declare (property) ControlDirective.position: atlas.ControlPosition Type '"top-right"' is not assignable to type 'ControlPosition'.ngtsc(2322) [app.component.ts(3, 59): ]()Error occurs in the template of component AppComponent. ```
  1. Trying to use the Search Service: ```
    constructor(private readonly searchService: SearchService) {}
    mapClick(event:atlas.MapMouseEvent) {
    console.log(event.position)
    }
    mapReady (event: IMapEvent) {
    this.searchService.searchAddress("ramsey", { countrySet: ['uk', 'us']})
    .subscribe(response => {
    const features = [];
    for(const result of response.results) {
    event.map.markers.add(
    new atlas.HtmlMarker({
    position: [result.position.lon, result.position.lat]
    })
    )
    features.push(new atlas.data.Point([result.position.lon, result.position.lat]))
    }
    event.map.setCamera({
    bounds:atlas.data.BoundingBox.fromData(features)
    })
    })
    }
    }
Getting this error please advise:

(parameter) response: atlas.service.Models.SearchAddressResponse
Object is possibly 'undefined'.ts(2532)

Drawing Toolbar events do not fire

I have a simple proof-of-concept project setup to test drawing on a map with the ultimate goal of using data points from the drawing to filter markers that I'll draw on the map. The map draws, with the three 'shapes'/markers, and drawing on the map works, but none of the events on the drawing toolbar fire. My component's .ts file looks like this:

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

@component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css']
})
export class AppComponent {
title = 'angular-azure-maps';

public dataSource: atlas.source.DataSource;
public strokeColor = '#4288f7';
public strokeWidth = 1;
public radius = 7;
public color = "DodgerBlue";
public center = [-92.0076434351666, 42.31463750062173];
public zoom = 6;
public mapStyle = 'grayscale_light';

mapReady() {
this.dataSource = new atlas.source.DataSource('source');
const point1 = new atlas.Shape(new atlas.data.Point([-92.0076434351666, 42.31463750062173]));
this.dataSource.add([point1]);
const point2 = new atlas.Shape(new atlas.data.Point([-92.76434351666, 42.463750062173]));
this.dataSource.add([point2]);
const point3 = new atlas.Shape(new atlas.data.Point([-92.25436, 42.4773]));
this.dataSource.add([point3]);
}

drawingStarted(value: any) {
}
drawingChanged(value: any) {
}
drawingChanging(value: any) {
}
drawingComplete(value: any) {
}
drawingModeChanged(value: any) {
}
}

while the relevant part of the html file looks like this:
<azure-map style="width: 900px; height: 300px;" [mapStyle]="mapStyle" [zoom]="zoom" [center]="center" [dataSources]="[dataSource]" (onReady)="mapReady()">


<map-bubble-layer dataSourceId="source" [strokeColor]="strokeColor" [strokeWidth]="strokeWidth" [color]="color" [radius]="radius">

Having map-drawing-toolbar in the azure-map component causes this error to show up (twice) in the Chrome debug console:
core.js:6210 ERROR Error: One or more layers have a dependency on the source '897df6ac-c09b-4cf7-8d1e-8a6c1e784432'
at Qf._removeSource (atlas.min.js:55)
at Qf.remove (atlas.min.js:55)
at AzureMapDirective.updateDataSources (ng-azure-maps.js:1625)
at ng-azure-maps.js:1558
at atlas.min.js:55
at Map.forEach ()
at qf._invokeListeners (atlas.min.js:55)
at qf.invoke (atlas.min.js:55)
at t.u (atlas.min.js:55)
at t.Mt.fire (atlas.min.js:55)

I suspect that this error breaks the output from the map-drawing-toolbar to the even handlers.

Azure Maps tag not working

Hi, I am creating the project as explained in the readme file but tag doesnt work and isnt recognized.
error message :
'azure-map' is not a known element:

  1. If 'azure-map' is an Angular component, then verify that it is part of this module.
  2. If 'azure-map' is a Web Component then add 'CUSTOM_ELEMENTS_SCHEMA' to the '@NgModule.schemas' of this component to suppress this message.

Angular version used - 10

Also, I cannot understand how the solution on git is supposed to work, should I create a new project and then add parts of it because it does not run in its current state and I tried running from 3-4 folders being the root solution and angular cannot find target project.

It will be great help as I am working on a solution that needs azure map usage extensively.

pointer with text

Hi

I need some help with an example using ng0azure-maps input the gps value ( long and lat ) and displaying a pointer with that address or a text ( i need to display the data without moving the mouse over the pointer)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.