1.5.2 • Published 6 years ago

ngx-mapbox-gl-patch v1.5.2

Weekly downloads
2
License
MIT
Repository
github
Last release
6 years ago

ngx-mapbox-gl

Build Status npm version

Angular (5+) wrapper for mapbox-gl-js. Expose a bunch of component meant to be simple to use for Angular.

Play with ngx-mapbox-gl on stackblitz: https://stackblitz.com/edit/ngx-mapbox-gl

Include the following components:

How to start

npm install ngx-mapbox-gl mapbox-gl --save

Also add mapbox-gl types if using typescript

npm install @types/mapbox-gl --save-dev

Load the css of mapbox-gl

For example, with angular-cli add this in .angular-cli.json

"styles": [
        ...
        "../node_modules/mapbox-gl/dist/mapbox-gl.css"
      ],

Or in global css

@import "../node_modules/mapbox-gl/dist/mapbox-gl.css";

Then, in your app's main module (or in any other module), import the NgxMapboxGLModule

...
import { NgxMapboxGLModule } from 'ngx-mapbox-gl';

@NgModule({
  imports: [
    ...
    NgxMapboxGLModule.forRoot({
      accessToken: 'TOKEN' // accessToken can also be set per map (accessToken input of mgl-map)
    })
  ]
})
export class AppModule {}

Display a map

import { Component } from '@angular/core';

@Component({
  template: `
  <mgl-map
    [style]="'mapbox://styles/mapbox/streets-v9'"
    [zoom]="[9]"
    [center]="[-74.50, 40]"
  >
  </mgl-map>
  `,
  styles: [`
    mgl-map {
      height: 100%;
      width: 100%;
    }
  `]
})
export class DisplayMapComponent { }

Important notes for production build

@angular/cli users:

>= 1.5.5 version is required (https://github.com/angular/angular-cli/issues/5804)

< 1.5.5 version users can use this patch: https://github.com/angular/angular-cli/pull/7931 (available in this repo as ngcli-comparisons-false.patch)

Webpack users:

Add noParse: /(mapbox-gl)\.js$/

Built with ngx-mapbox-gl

Todo