@avanzyl/ngx-leaflet-toolbar
TypeScript icon, indicating that this package has built-in type declarations

1.0.2 • Public • Published

@avanzyl/ngx-leaflet-toolbar

Build Status

Leaflet Toolbar extension for @asymmetrik/ngx-leaflet package to be used with Angular.io.

Table of Contents

Install

# Install required packages
npm install leaflet
npm install leaflet-toolbar
npm install @asymmetrik/ngx-leaflet
npm install @avanzyl/ngx-leaflet-toolbar

# Install types
npm install --save-dev @types/leaflet

Usage

  1. Edit your angular.json file to inject the required assets
{
  ...
   "assets": [
    {
      "glob": "**/*",
      "input": "./node_modules/leaflet/dist/images",
      "output": "/"
    },
    ...
  ],
  "styles": [
    ...
    "./node_modules/leaflet/dist/leaflet.css",
    "./node_modules/leaflet-toolbar/dist/leaflet.toolbar.css"
  ],
  "scripts": [
    ...
    "./node_modules/leaflet/dist/leaflet.js",
    "./node_modules/leaflet-toolbar/dist/leaflet.toolbar.js"
  ]
  ...
}
  1. Import Dependencies and Modules into app.modules.ts
import { LeafletModule } from '@asymmetrik/ngx-leaflet';
import { LeafletToolbarModule } from '@avanzyl/ngx-leaflet-toolbar';

@NgModule({
  ...
  imports: [
    ...
    LeafletModule.forRoot(),
    LeafletToolbarModule.forRoot()
  ]
  ...
})
  1. Create map inside your component .html file..
<div style="height: 400px;"
     leaflet
     leafletToolbar
     [leafletOptions]="options"
     [leafletToolbarControl]="toolbarControl">
</div>
  1. Add leaflet and toolbar options to your component .ts file.
options = {
  layers: [
    tileLayer('http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
      maxZoom: 18
    })
  ],
  zoom: 5,
  center: latLng(46.879966, -121.726909)
};

toolbar = {
  position: 'topleft',
  actions: [
    {
      options: {
        toolbarIcon: {
          html: '<img src="assets/static/images/heatmap.svg" height="30" width="30">',
          tooltip: 'Heatmap'
        }
      },
      addHooks: () => {
        // Do action functionality here
      });
    }
  ]
};

For more config options see documentation for:

Todo

  • [ ] Add support for popup-style

License

See LICENSE in repository for details.

Readme

Keywords

none

Package Sidebar

Install

npm i @avanzyl/ngx-leaflet-toolbar

Weekly Downloads

3

Version

1.0.2

License

MIT

Unpacked Size

32.3 kB

Total Files

30

Last publish

Collaborators

  • avanzyl