Coder Social home page Coder Social logo

wuenping / ngx-mapbox-gl Goto Github PK

View Code? Open in Web Editor NEW

This project forked from wykks/ngx-mapbox-gl

0.0 2.0 0.0 7.36 MB

Angular binding of mapbox-gl-js

Home Page: https://wykks.github.io/ngx-mapbox-gl

License: MIT License

JavaScript 1.55% TypeScript 95.80% HTML 1.47% CSS 1.09% Shell 0.10%

ngx-mapbox-gl's Introduction

ngx-mapbox-gl

Build Status npm version

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

v1.X : Angular 5 & 6 (rxjs 5)

v2.X : Angular 6 & 7 (rxjs 6)

v3.X : Angular 7.2

Include the following components:

How to start

npm install ngx-mapbox-gl [email protected] --save

If using typescript add mapbox-gl types

npm install @types/[email protected] --save-dev

Load the css of mapbox-gl (and mapbox-gl-geocoder if mglGeocoder is used)

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

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

Or in global css

@import "~mapbox-gl/dist/mapbox-gl.css";
@import "~@mapbox/mapbox-gl-geocoder/lib/mapbox-gl-geocoder.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.withConfig({
      accessToken: 'TOKEN', // Optionnal, can also be set per map (accessToken input of mgl-map)
      geocoderAccessToken: 'TOKEN' // Optionnal, specify if different from the map access token, can also be set per mgl-geocoder (accessToken input of mgl-geocoder)
    })
  ]
})
export class AppModule {}

How to get a mapbox token: https://www.mapbox.com/help/how-access-tokens-work/

Note: mapbox-gl can works without token, if you have your own source, example: https://stackblitz.com/edit/ngx-mapbox-gl-without-token

You can use https://github.com/klokantech/tileserver-gl to serve vector tiles

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 { }

ngx-mapbox-gl's People

Contributors

wykks avatar bernhardrode avatar andrejb1 avatar angular-cli avatar dmytro-gokun avatar eimanip avatar lennyz71 avatar paullryan avatar raysuelzer avatar sroettering avatar wheredoesyourmindgo avatar

Watchers

James Cloos avatar  avatar

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.