TypeScript icon, indicating that this package has built-in type declarations

    6.0.0 • Public • Published


    Build Status

    @asymmetrik/leaflet-d3 extension to the @asymmetrik/ngx-leaflet package for Angular.io Provides @asymmetrik/leaflet-d3 integration into Angular.io projects. Compatible with Leaflet v1.x, @asymmetrik/leaflet-d3 v4.x, and d3 v5.x

    Now supports Angular v10, Ahead-of-Time compilation (AOT), and use in Angular-CLI based projects

    Table of Contents


    Install the package and its peer dependencies via npm:

    npm install d3 leaflet @asymmetrik/leaflet-d3 @asymmetrik/ngx-leaflet @asymmetrik/ngx-leaflet-d3

    If you intend to use this library in a typescript project (utilizing the typings), you will need to also install the leaflet typings via npm:

    npm install @types/d3 @types/leaflet

    If you want to run the demo, clone the repository, perform an npm install, npm run demo and then go to http://localhost:4200


    This plugin is used with the Angular.io Leaflet plugin.


    Hexbins allow you to aggregate data into bins with a hexagon geometry. The hexbin layer allows you to bind characteristics of the bound data to both the size and color of the drawn bin within the bin grid element.


    You'll want to style the hexbins at least with a stroke size/color.

    .hexbin-hexagon {
        stroke: #000;
        stroke-width: .5px;

    Basic Example

    To create a hexbin layer on a map, use the leafletHexbin attribute directive. This directive must appear after the leaflet directive. This attribute directive also acts as an input binding for the hexbin data array.

    <div leaflet style="height: 300px;"
    hexbinData: [ number, number ][] = [...];

    Multiple Hexbin Layers on the Same Map

    You can also draw multiple hexbin layers on the same map (see the demo example). In this case, you'd want to have multiple hexbin options so you can set the colors (or sizes) differently. All you need to do is bound the leafletHexbin directive to a child div of the div with the leaflet directive.

    <div leaflet style="height: 300px;"
         <div [leafletHexbin]="hexbinData1" [leafletHexbinOptions]="hexbinOptions1"></div>
         <div [leafletHexbin]="hexbinData2" [leafletHexbinOptions]="hexbinOptions2"></div>
    hexbinOptions1: L.HexbinLayerConfig = { radius: 12, radiusRange: [ 4, 11 ], colorRange: [ 'white', 'tomato' ] };
    hexbinOptions2: L.HexbinLayerConfig = { radius: 12, radiusRange: [ 4, 11 ], colorRange: [ 'white', 'steelblue' ] };
    hexbinData1: [ number, number ][] = [...];
    hexbinData2: [ number, number ][] = [...];

    It's important to note that for performance reasons, we're keeping all change detection strategies default. This means that all bound data structures must be treated as immutable. For changes to be detected, instance equality must change.

    See the README for @asymmetrik/leaflet-d3 for details regarding the default options and default data schema.


    To create a ping layer on a map, use the leafletPing attribute directive. This directive must appear after the leaflet directive.

    <div leaflet style="height: 300px;"

    The output binding for leafletPingObserver provides an Rxjs Observer that you will use to emit ping objects to the directive.


    This section includes more detailed documentation of the functionality of the directives included in this library.


    There are several input and output bindings for the hexbin layer. They are documented and demonstrated below.

    <div leaflet style="height: 300px;"


    Input binding for the data array that is aggregated by the hexbins.


    Input binding for hexbin options (see Leaflet D3's docs). This allows you to set some basic settings for the hexbin layer.


    Event emitter/output binding for hexbin mouseover event (see Leaflet D3's docs). This event is fired when the mouse hovers over a hexbin.


    Event emitter/output binding for hexbin mouseout event (see Leaflet D3's docs). This event is fired when the mouse leaves a hexbin.


    Event emitter/output binding for hexbin click event (see Leaflet D3's docs). This event is fired when the mouse clicks on a hexbin.


    Event emitter/output binding for hexbin layer ready event. This event is emitted after the hexbin layer has been created and includes a reference to the layer. This provides an opportunity to do any advanced configuration not already supported by the directive.


    There is an input binding and an output binding for the ping layer. They are documented and demonstrated below.

    <div leaflet style="height: 300px;"


    This is the directive attribute that activates the directive.


    Input binding for the leaflet ping layer options (see Leaflet D3's docs).


    Event emitter/output binding for ping layer observer. The observer is how pings are emitted to the layer.

    setLeafletPingObserver(observer: Observer<any>) {
        this.leafletPingObserver = observer;
        // Start the ping loop
        setTimeout(this.generatePings.bind(this), 100);
    private generatePings() {
            data: [ 40, 50 ]  // [ lng, lat ]
        setTimeout(this.generatePings.bind(this), 100);

    The data schema for pings is:

    leafletPingObserver.next(pingData: LeafletPingEvent)
    class LeafletPingEvent {
        data: [lng, lat];
        cssClass?: string;


    PRs accepted. If you are part of Asymmetrik, please make contributions on feature branches off of the develop branch. If you are outside of Asymmetrik, please fork our repo to make contributions.


    See LICENSE in repository for details.


    Leaflet Is an awesome mapping package. D3 Is an awesome visualization kernel.




    npm i @asymmetrik/ngx-leaflet-d3

    DownloadsWeekly Downloads






    Unpacked Size

    69.4 kB

    Total Files


    Last publish


    • ekoon121
    • iisluan
    • brianghig
    • rblace
    • reblace
    • robert-w
    • amarcus
    • jlee-asymmetrik
    • soneill
    • astadler4asymmetrik