Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

angular-pharkas-leaflet

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

angular-pharkas-leaflet

An Observable focused Angular base component for working with Leaflet

  • 3.0.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

Angular-Pharkas-Leaflet

This library provides Angular base component for working with Leaflet, based on the angular-pharkas Component Framework.

It's benefits are:

  • Zone free
    • ChangeDetectionStrategy.OnPush disables Angular's more active change detection which is unnecessary around vanilla controls like Leaflet
  • Observable driven-ish
    • Leaflet itself is inescapably imperative, but this wrapper uses Observables for lifecycle which makes it easier to think in Observables when working with Leaflet
  • Resize aware
    • Uses ResizeObserver to watch container size changes and notifies Leaflet, which is useful for smarter updating in complex reflowing CSS layouts such as CSS Grid

The Inevitable Angular Compatibility Chart

Library versionSupported Angular
3.0.0Angular 15
<=2.0.0Angular 13

Usage

Import PharkasLeafletModule and use LeafletMapComponent as a replacement base component like PharkasComponent. The this.useMap() "hook" takes Leaflet options and returns and Observable<LeafletMap>.

A basic example:

@Component({
  // …
  changeDetection: ChangeDetectionStrategy.OnPush,
})
export class MyExampleComponent extends LeafletMapComponent<MyExampleComponent> {
  constructor(ref: ChangeDetectorRef, element: ElementRef) {
    super(ref, element)

    const exampleLayer = new L.GeoJSON()

    const map = this.useMap({
      layers: [exampleLayer],
    })
  }
}

An example of using a bindEffect with combineLatest to perform an imperative effect on the map based on an input Observable:

@Component({
  // …
  changeDetection: ChangeDetectionStrategy.OnPush,
})
export class MyExampleComponent extends LeafletMapComponent<MyExampleComponent> {
  @Input() set zoomControlPosition(
    value: L.ControlPosition | Observable<L.ControlPosition>
  ) {
    this.setInput('zoomControlPosition', value)
  }

  constructor(ref: ChangeDetectorRef, element: ElementRef) {
    super(ref, element)

    const exampleLayer = new L.GeoJSON()

    const map = this.useMap({
      layers: [exampleLayer],
    })

    var zoomControlPosition = this.useInput('zoomControlPosition')

    this.bindEffect(
      combineLatest([zoomControlPosition, map]),
      ([position, map]) => {
        map.zoomControl.remove()
        L.control.zoom({ position }).addTo(map)
      }
    )
  }
}

Keywords

FAQs

Package last updated on 01 Sep 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc