UNPKG

28.3 kBMarkdownView Raw
1# @asymmetrik/ngx-leaflet
2
3[![Build Status][travis-image]][travis-url]
4
5[travis-url]: https://travis-ci.org/Asymmetrik/ngx-leaflet/
6[travis-image]: https://travis-ci.org/Asymmetrik/ngx-leaflet.svg?branch=master
7
8> Leaflet packages for Angular.io.
9> Provides flexible and extensible components for integrating Leaflet v0.7.x and v1.x into Angular.io projects.
10> Supports Angular v14 and use in Angular-CLI based projects.
11
12## Table of Contents
13- [Install](#install)
14- [Usage](#usage)
15- [API](#api)
16- [Extensions](#extensions)
17- [Getting Help](#help)
18- [Contribute](#contribute)
19- [License](#license)
20- [Credits](#credits)
21
22
23
24## Install
25Install the package and its peer dependencies via npm (or yarn):
26```
27npm install leaflet
28npm install @asymmetrik/ngx-leaflet
29```
30
31If you intend to use this library in a typescript project (utilizing the typings), you'll need to install the leaflet typings:
32```
33npm install --save-dev @types/leaflet
34```
35
36If you want to run the demo, clone the repository, perform an ```npm install```, ```npm run demo``` and then go to http://localhost:4200
37
38Not using the latest version of Angular.io? Have a look in [CHANGES.md](/CHANGES.md) to find the right version for your project.
39
40## Usage
41To use this library, there are a handful of setup steps to go through that vary based on your app environment (e.g., Webpack, ngCli, SystemJS, etc.).
42Generally, the steps are:
43
44* Install Leaflet, this library, and potentially the Leaflet typings (see above).
45* Import the Leaflet stylesheet
46* Import the Leaflet module into your Angular project
47* Create and configure a map (see docs below and/or demo)
48
49
50### Import the Leaflet Stylesheet
51For leaflet to work, you need to have the leaflet stylesheets loaded into your application.
52If you've installed via npm, you will need to load ```./node_modules/leaflet/dist/leaflet.css```.
53How you include the stylesheet will depend on your specific setup. Here are a few examples:
54
55#### Direct Import from HTML
56If you are just building a webpage and not using a bundler for your css, you'll want to directly import the css file in your HTML page.
57
58```html
59<head>
60 ...
61 <link rel="stylesheet" type="text/css" href="./node_modules/leaflet/dist/leaflet.css">
62 ...
63</head>
64```
65
66#### Configuring Webpack Style Loaders
67If you are using Webpack, you will need to import the css file and have a style-loader configured.
68You can use the demo included in this application as a reference.
69
70Generally, in ```vendor.ts```:
71```ts
72import 'leaflet/dist/leaflet.css';
73```
74
75And then in your webpack config file:
76```js
77{
78 ...
79 "module" : {
80 loaders: [
81 ...
82 { test: /\.css$/, loaders: [ 'style-loader', 'css-loader' ] },
83 ...
84 ]
85 },
86 ...
87}
88```
89
90
91#### Adding Styles in Angular CLI
92If you are using Angular CLI, you will need to add the Leaflet CSS file to the styles array contained in ```angular.json```
93
94```json
95{
96 ...
97 "styles": [
98 "styles.css",
99 "./node_modules/leaflet/dist/leaflet.css"
100 ],
101 ...
102}
103```
104
105### Import Code Dependencies and Module
106This project is exported using UMD and it includes typings.
107So, you shouldn't have to do anything special to use it if you're building your project in Typescript.
108
109#### Typescript Angular.io Module Import
110Before you can use the module in your Angular.io app, you'll need to import it in your application (and potentially the module that's using it).
111
112For example, in your ```app.module.ts```, add:
113
114```js
115import { LeafletModule } from '@asymmetrik/ngx-leaflet';
116
117...
118imports: [
119 ...
120 LeafletModule
121]
122...
123
124```
125
126Potentially, you'll also need to import it into the module of the component that is going to actually use the ngx-leaflet directives.
127See Angular.io docs of modules for more details (https://angular.io/guide/ngmodule). In this case, in ```my-module.module.ts```, add:
128
129```js
130import { LeafletModule } from '@asymmetrik/ngx-leaflet';
131
132...
133imports: [
134 ...
135 LeafletModule
136]
137...
138
139```
140
141
142#### Not Using Typescript?
143You brave soul.
144The code is exported using UMD.
145The bundles are generated as part of the build (`npm run build`) and placed into the ./dist dir.
146You should be able to import is using whatever module system/builder you're using, even if you aren't using Typescript.
147
148
149### Create and Configure a Map
150Once the dependencies are installed and you have imported the ```LeafletModule```, you're ready to add a map to your page.
151To get a basic map to work, you have to:
152
153* Apply the ```leaflet``` attribute directive (see the example below) to an existing DOM element.
154* Style the map DOM element with a height. Otherwise, it'll render with a 0 pixel height.
155* Provide an initial zoom/center and set of layers either via ```leafletOptions``` or by binding to ```leafletZoom```, ```leafletCenter```, and ```leafletLayers```.
156
157Template:
158```html
159<div style="height: 300px;"
160 leaflet
161 [leafletOptions]="options">
162</div>
163```
164
165Example leafletOptions object:
166```js
167options = {
168 layers: [
169 tileLayer('http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', { maxZoom: 18, attribution: '...' })
170 ],
171 zoom: 5,
172 center: latLng(46.879966, -121.726909)
173};
174```
175
176Changes to leafletOptions are ignored after they are initially set.
177This is because these options are passed into the map constructor, so they can't be changed anyways.
178So, make sure the object exists before the map is created.
179You'll want to create the object in ```ngOnInit``` or hide the map DOM element with ```*ngIf``` until you can create the options object.
180
181
182### Add a Layers Control
183The ```[leafletLayersControl]``` input bindings give you the ability to add the layers control to the map.
184The layers control lets the user toggle layers and overlays on and off.
185
186Template:
187```html
188<div style="height: 300px;"
189 leaflet
190 [leafletOptions]="options"
191 [leafletLayersControl]="layersControl">
192</div>
193```
194
195Example layersControl object:
196```js
197layersControl = {
198 baseLayers: {
199 'Open Street Map': tileLayer('http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', { maxZoom: 18, attribution: '...' }),
200 'Open Cycle Map': tileLayer('http://{s}.tile.opencyclemap.org/cycle/{z}/{x}/{y}.png', { maxZoom: 18, attribution: '...' })
201 },
202 overlays: {
203 'Big Circle': circle([ 46.95, -122 ], { radius: 5000 }),
204 'Big Square': polygon([[ 46.8, -121.55 ], [ 46.9, -121.55 ], [ 46.9, -121.7 ], [ 46.8, -121.7 ]])
205 }
206}
207```
208
209You can add any kind of Leaflet layer you want to the ```overlays``` map.
210This includes markers, shapes, geojson, custom layers from other libraries, etc.
211
212
213### Add Custom Layers (base layers, markers, shapes, etc.)
214There are several different ways to add layers to the map.
215You can add layers (baselayers, markers, or custom layers) to the map without showing them in the layer control using the ```[leafletLayers]``` directive.
216
217Template:
218```html
219<div style="height: 300px;"
220 leaflet
221 [leafletOptions]="options"
222 [leafletLayers]="layers">
223</div>
224```
225
226Layers array:
227```js
228layers = [
229 circle([ 46.95, -122 ], { radius: 5000 }),
230 polygon([[ 46.8, -121.85 ], [ 46.92, -121.92 ], [ 46.87, -121.8 ]]),
231 marker([ 46.879966, -121.726909 ])
232];
233```
234
235You can also add an individual layer to the map using the ```[leafletLayer]``` directive.
236Using this approach allows you to use ```*ngFor``` and ```*ngIf``` to control whether individual layers are added to or removed from the map.
237
238Template:
239```html
240<div style="height: 300px;"
241 leaflet
242 [leafletOptions]="options">
243 <div *ngIf="showLayer" [leafletLayer]="layer"></div>
244</div>
245```
246
247Layer:
248```js
249layer = circle([ 46.95, -122 ], { radius: 5000 });
250```
251
252
253### Dynamically Change Map Layers using [leafletLayers]
254
255> **Layer inputs (arrays and maps) are mutable**
256> Previous versions of this plugin treated layers arrays and layer control objects as immutable data structures.
257> We've changed that behavior.
258> Now, mutable changes to the ```leafletLayers```, ```leafletBaseLayers```, and ```leafletLayersControl``` inputs are detected.
259
260The plugin is now using internal ngx iterable and key/value differs to detect and track changes to mutable data structures.
261This approach requires a deep compare of the contents of the data structure (which can be slow when the contents are really big).
262For immutable data structures, all that is needed is a top-level instance equality check (which is way faster).
263This change is backwards compatible and was motivated by feedback and confusion.
264While there is a performance impact for some use cases, this approach is more intuitive.
265
266There are at least two good approaches to improving performance when there are a lot of layers bound to the map.
267First, you can use the OnPush change detection strategy. There's an example of this in the demo.
268Second, you can wrap a large number of layers into a Leaflet layer group, which will reduce the number of layers the plugin actually has to track during diffs.
269
270
271### Working with Leaflet Events
272Often, you'll want to make changes based on a map click or other Leaflet interaction.
273The ngx-leaflet plugin supports several [map events](#map-events) and [layer events](#layer-events) as documented in the API section.
274
275You may occasionally need to handle events that aren't exposed through the plugin, however.
276When that happens, you will need to be aware of how Zones and change detection work to ensure your event handling works as expected.
277Take a look at [A Note About Change Detection](#a-note-about-change-detection) for more details.
278This is by design and a common thing to deal with when using third party libraries and Angular.
279
280
281## API
282This section includes more detailed documentation of the functionality of the directives included in this library.
283
284### Advanced Map Configuration
285There are several input bindings available for configuring the map.
286
287```html
288<div leaflet style="height: 300px;"
289 [leafletOptions]="options"
290 [leafletPanOptions]="panOptions"
291 [leafletZoomOptions]="zoomOptions"
292 [leafletZoomPanOptions]="zoomPanOptions"
293 [leafletFitBoundsOptions]="fitBoundsOptions">
294</div>
295```
296
297#### [leafletOptions]
298Input binding for the initial leaflet map options (see [Leaflet's](http://leafletjs.com/reference.html#map-option) docs). These options can only be set initially because they are used to create the map. Later changes are ignored.
299
300#### [leafletPanOptions]
301Input binding for pan options (see [Leaflet's](http://leafletjs.com/reference.html#pan-options) docs). These options are stored and used whenever pan operations are invoked.
302
303#### [leafletZoomOptions]
304Input binding for zoom options (see [Leaflet's](http://leafletjs.com/reference.html#zoom-options) docs). These options are stored and used whenever zoom operations are invoked.
305
306#### [leafletZoomPanOptions]
307Input binding for zoom/pan options (see [Leaflet's](http://leafletjs.com/reference.html#zoom/pan-options) docs). These options are stored and used whenever zoom/pan operations are invoked.
308
309#### [leafletFitBoundsOptions]
310Input binding for FitBounds options (see [Leaflet's](http://leafletjs.com/reference.html#fitbounds-options) docs). These options are stored and used whenever FitBounds operations are invoked.
311
312
313### Dynamically changing zoom level, center, fitBounds, etc.
314```html
315<div leaflet style="height: 300px;"
316 [leafletOptions]="options"
317 [(leafletZoom)]="zoom"
318 [(leafletCenter)]="center"
319 [leafletFitBounds]="fitBounds">
320</div>
321```
322
323#### [(leafletZoom)]: number
324Input and Output binding for the map zoom level.
325
326#### [leafletMaxZoom]: number
327Input binding for the maximum zoom level for the map.
328
329#### [leafletMinZoom]: number
330Input binding for the minimum zoom level for the map.
331
332#### [(leafletCenter)]: LatLng
333Input and Output binding for the map center position.
334
335#### Note: center/zoom operations may interfere with each other
336Zoom/Center operations that are applied in rapid succession may interfere with or cancel each other.
337If both changes are picked up at the same time, the component applies the changes as a map.setView() operation to ensure both are processed.
338Additionally, if a zoom level or center is applied that is not allowed (e.g., beyond max zoom level or outside of max bounds), Leaflet will determine the new value.
339
340#### [leafletFitBounds]: LatLngBounds
341Input bind a ```LatLngBounds``` value that will be applied to the map using ```Map.setFitBounds()```.
342This operation has no output binding because the input fitBounds usually results in a slightly different map bounds.
343
344#### [leafletMaxBounds]: LatLngBounds
345Input bind a ```LatLngBounds``` value that will be applied to the map using ```Map.setMaxBounds()```.
346
347
348### Simple Layer Management: Setting Baselayers
349There is a convenience input binding for setting the baselayers on the map called ```[leafletBaseLayers]```.
350You can also provide ```[leafletLayersControlOptions]``` if you want to show the control on the map that allows you to switch between baselayers.
351If you plan to show more than just baselayers, you should use the more advanced layers controls described in *Advanced Layer Management* below.
352
353For an example of the basic map setup, you should check out the *Simple Base Layers* demo.
354
355```html
356<div leaflet style="height: 300px;"
357 [leafletOptions]="options"
358 [leafletBaseLayers]="baseLayers"
359 [leafletLayersControlOptions]="layersControlOptions">
360</div>
361```
362
363#### [leafletBaseLayers]: Control.LayersObject
364Input bind an ```Control.LayersObject``` to be synced to the map.
365
366```js
367baseLayers: {
368 'layer1': Layer,
369 'layer2': Layer
370}
371```
372
373On changes, the component syncs the baseLayers on the map with the layers in this object.
374Syncing is performed by tracking the current baselayer and on changes, searching the map to see if any of the current baselayers is added to the map.
375If it finds a baselayer that is still added to the map, it will assume that is still the baselayer and leave it.
376If none of the baselayers can be found on the map, it will add the first layer it finds in the ```Control.LayersObject``` and use that as the new baselayer.
377Layers are compared using instance equality.
378
379If you use this directive, you can still manually use the ```[leafletLayers]``` directive, but you will not be able to use the ```[leafletLayersControl]``` directive.
380This directive internally uses the layers control, so if you add both, they'll interfere with each other.
381Because it uses ```control.layers``` under the hood, you can still provide options for the layers control.
382
383
384#### [leafletLayersControlOptions]
385Input binding for Control.Layers options (see [Leaflet's](http://leafletjs.com) docs).
386These options are passed into the layers control constructor on creation.
387
388
389### Advanced Layer Management: Layers, and Layers Control
390The ```[leafletLayers]``` and ```[leafletLayersControl]``` input bindings give you direct access to manipulate layers and the layers control.
391When the array bound to ```[leafletLayers]``` is changed, the directive will synchronize the layers on the map to the layers in the array.
392This includes tile layers and any added shapes.
393
394The ```[leafletLayersControl]``` input binding allows you to provide a set of base layers and overlay layers that can be managed within leaflet using the layers control.
395When the user manipulates the control via Leaflet, Leaflet will automatically manage the layers, but the input bound layer array isn't going to get updated to reflect those changes.
396
397So, use ```[leafletLayers]``` to add a collection of layers to the map.
398And, use ```[leafletLayersControl]``` to allow users to optionally turn layers/overlays on and off.
399
400For an example of using the layers controls, you should check out the *Layers and Layer Controls* demo.
401
402```html
403<div leaflet style="height: 300px;"
404 [leafletOptions]="options"
405 [leafletLayers]="layers"
406 [leafletLayersControl]="layersControl"
407 [leafletLayersControlOptions]="layersControlOptions">
408</div>
409```
410
411#### [leafletLayers]: Layer[]
412Input bind an array of all layers to be synced (and made visible) in the map.
413
414On changes, the component syncs the layers on the map with the layers in this array.
415Syncing is performed by selectively adding or removing layers.
416Layers are compared using instance equality.
417As a result of how the map is synced, the order of layers is not guaranteed to be consistent as changes are made.
418
419
420#### [leafletLayersControl]: Control.Layers
421Input bind a Control.Layers specification. The object contains properties for each of the two constructor arguments for the Control.Layers constructor.
422
423```js
424layersControl: {
425 baseLayers: {
426 'layerName': Layer
427 },
428 overlays: {
429 'overlayName': Layer
430 }
431}
432```
433
434#### [leafletLayersControlOptions]
435Input binding for Control.Layers options (see [Leaflet's](http://leafletjs.com) docs).
436These options are passed into the constructor on creation.
437
438
439### Advanced Layer Management: Individual Layers and *ngFor / *ngIf
440The ```[leafletLayer]``` input bindings gives you the ability to add a single layer to the map.
441While this may seem limiting, you can nest elements inside the map element, each with a ```[leafletLayer]``` input.
442The result of this is that each layer will be added to the map.
443If you add a structural directive - ```*ngFor``` or ```*ngIf``` - you can get some added flexibility when controlling layers.
444
445```html
446<div leaflet style="height: 300px;"
447 [leafletOptions]="options">
448 <div *ngFor="let l of layers" [leafletLayer]="l"></div>
449</div>
450```
451
452In this example, each layer in the ```layers``` array will create a new child ```div``` element.
453Each element will have a ```[leafletLayer]``` input binding, which will result in the layer being added to the map.
454For more details, you should check out the *Layers and ngFor* demo.
455
456There are several layer events that are available when you are using this approach to controlling layers.
457
458### Layer Events
459When you are using the ```[leafletLayer]``` directive to add a layer, you can also access output bindings for layer events.
460Two events that are currently exposed include: ```(leafletLayerAdd)``` and ```(leafletLayerRemove)```.
461Each of these emits a ```LeafletEvent``` object.
462
463
464### Map Events
465Leaflet exposes a lot of map events including map zoom, map move, and mouse interactions.
466The plugin exposes several of the most common events.
467For each of these events, the event is emitted in the Angular Zone, so you shouldn't have to do anything extra to get change detection to work.
468For a working example, check out the events section of the demo.
469
470#### Mouse Interactions: LeafletMouseEvent
471The following events are provided:
472* ```(leafletClick)```
473* ```(leafletDoubleClick)```
474* ```(leafletMouseDown)```
475* ```(leafletMouseUp)```
476* ```(leafletMouseMove)```
477* ```(leafletMouseOver)```
478* ```(leafletMouseOut)```
479
480#### Map Zoom and Move: LeafletEvent
481The following events are provided:
482* ```(leafletMapMove)```
483* ```(leafletMapMoveStart)```
484* ```(leafletMapMoveEnd)```
485* ```(leafletMapZoom)```
486* ```(leafletMapZoomStart)```
487* ```(leafletMapZoomEnd)```
488
489
490
491### Getting a Reference to the Map
492Occasionally, you may need to directly access the Leaflet map instance.
493For example, to call ```invalidateSize()``` when the map div changes size or is shown/hidden.
494There are a couple of different ways to achieve this depending on what you're trying to do.
495
496The easiest and most flexible way is to use the output binding ```leafletMapReady```.
497This output is invoked after the map is created, the argument of the event being the ```Map``` instance.
498
499The second is to get a reference to the leaflet directive itself - and there are a couple of ways to do this.
500With a reference to the directive, you can invoke the ```getMap()``` function to get a reference to the ```Map``` instance.
501
502
503#### (leafletMapReady): Map
504This output is emitted when once when the map is initially created inside of the Leaflet directive.
505The event will only fire when the map exists and is ready for manipulation.
506
507```html
508<div leaflet
509 [leafletOptions]="options"
510 (leafletMapReady)="onMapReady($event)">
511</div>
512```
513
514```js
515onMapReady(map: Map) {
516 // Do stuff with map
517}
518```
519
520This method of getting the map makes the most sense if you are using the Leaflet directive inside your own component
521and just need to add some limited functionality or register some event handlers.
522
523
524#### Inject LeafletDirective into your Component
525This is the more advanced technique and it won't always work depending on your setup.
526In particular, this will likely not work unless you are writing your own third-party library that extends the functionality of `ngx-leaflet`.
527If this approach does not work for you, try using the `leafletMapReady` event described above.
528
529In Angular.io, directives are injectable the same way that Services are.
530This means that you can create your own component or directive and inject the ```LeafletDirective``` into it.
531This will only work if your custom component/directive exists on the same DOM element and is ordered after the injected LeafletDirective, or if it is on a child DOM element.
532
533
534```html
535<!-- On the same DOM element -->
536<div leaflet myCustomDirective>
537</div>
538
539<!-- On a child DOM element -->
540<div leaflet>
541 <div myCustomDirective></div>
542</div>
543```
544
545```js
546@Directive({
547 selector: '[myCustomDirective]'
548})
549export class MyCustomDirective {
550 leafletDirective: LeafletDirective;
551
552 constructor(leafletDirective: LeafletDirective) {
553 this.leafletDirective = leafletDirective;
554 }
555
556 someFunction() {
557 if (null != this.leafletDirective.getMap()) {
558 // Do stuff with the map
559 }
560 }
561}
562```
563
564The benefit of this approach is it's a bit cleaner if you're interested in adding some reusable capability to the existing leaflet map directive.
565As mentioned above, it might not work depending on how you are packaging your component.
566This is how the ```@asymmetrik/ngx-leaflet-draw``` and ```@asymmetrik/ngx-leaflet-d3``` packages work, so you can use them as references.
567
568
569### A Note About Change Detection
570Change detection is at the core of how Angular works.
571Angular.io uses Zone.js to scope how and when (events, actions, etc.) to trigger change detection.
572It's important to scope it carefully because change detection can be fairly expensive, so you don't want it to happen constantly.
573
574Libraries like ngx-leaflet have to decide what to do inside and outside of the Angular zone, balancing convenience and performance.
575Leaflet registers handlers for a lot of mouse events.
576To mitigate the performance impact of constantly running change detection on all mouse events (including mousemove), ngx-leaflet runs most of the Leaflet code outside of the Angular zone.
577The impact of this is that Angular won't automatically detect changes that you make inside of a Leaflet event callback.
578
579The solution is to either make sure that Angular relevant changes are made inside of Angular's zone or to manually tell Angular to detect changes.
580
581#### Running Inside of Angular's Zone
582Leaflet event handlers run outside of Angular's zone, where changes to input bound fields will not be detected automatically.
583To ensure your changes are detected and applied, you need to make those changed inside of Angular's zone.
584Fortunately, this is extremely easy.
585
586```js
587fitBounds: any = null;
588circle = circle([ 46.95, -122 ], { radius: 5000 });
589
590// Inject the Change Detector into your component
591constructor(private zone: NgZone) {}
592
593ngOnInit() {
594
595 // The 'add' event callback handler happens outside of the Angular zone
596 this.circle.on('add', () => {
597
598 // But, we can run stuff inside of Angular's zone by calling NgZone.run()
599 // everything inside the arrow function body happens inside of Angular's zone, where changes will be detected
600 this.zone.run(() => {
601 this.fitBounds = this.circle.getBounds();
602 });
603
604 });
605}
606```
607
608#### Manually Triggering Change Detection
609Another option is to manually tell the change detector to detect changes.
610The drawback to this option is that it is less precise.
611This will trigger change detection for this component and all of its children.
612
613```js
614fitBounds: any = null;
615circle = circle([ 46.95, -122 ], { radius: 5000 });
616
617// Inject the Change Detector into your component
618constructor(private changeDetector: ChangeDetectorRef) {}
619
620ngOnInit() {
621
622 // The 'add' event callback happens outside of the Angular zone
623 this.circle.on('add', () => {
624
625 // Because we're outside of Angular's zone, this change won't be detected
626 this.fitBounds = this.circle.getBounds();
627
628 // But, it will if we tell Angular to detect changes
629 this.changeDetector.detectChanges();
630
631 });
632}
633```
634
635
636### A Note About Markers
637If you use this component in an Angular.io project and your project uses a bundler like Webpack, you might run into issues using Markers on maps.
638The issue is related to how Leaflet manipulates the image URLs used to render markers when you are using the default marker images.
639The url manipulation is done at runtime and it alters the URLs in a way that breaks their format (this happens regardless of if you're using a file-loader or a url-loader).
640The demo contained in this project demonstrates how to get around this problem (at least in a Webpack environment).
641But, here is a rough overview of the steps taken to get them working.
642
643#### Webpack Marker Workaround
644
6451. Import the marker images in your vendor file to get Webpack to process the images in the asset pipeline
646
647 ```js
648 import 'leaflet/dist/images/marker-shadow.png';
649 import 'leaflet/dist/images/marker-icon.png';
650 ```
651
6521. Either host the images statically or use the file-loader Webpack plugin to generate the images.
6531. Determine the correct URL for the marker and marker-shadow images. If you're using a file hasher, you should be able to check Webpack's output for the generated images. If you are serving them directly without chunk hashing just figure out how to resolve the images on your server.
6541. Configure Leaflet to use the correct URLs as customer marker images
655
656 ```js
657 let layer = marker([ 46.879966, -121.726909 ], {
658 icon: icon({
659 ...Icon.Default.prototype.options,
660 iconUrl: '2b3e1faf89f94a4835397e7a43b4f77d.png',
661 iconRetinaUrl: '680f69f3c2e6b90c1812a813edf67fd7.png',
662 shadowUrl: 'a0c6cc1401c107b501efee6477816891.png'
663 })
664 });
665 ```
666
667#### Angular CLI Marker Workaround
668
669If you build your project using the [Angular CLI](https://github.com/angular/angular-cli), you can make the default leaflet marker assets available by doing the following:
670
6711. Configure the CLI (by editing `angular.json`)to include leaflet assets as below. Detailed instructions can be found in the [asset-configuration](https://github.com/angular/angular-cli/blob/master/docs/documentation/stories/asset-configuration.md) documentation.
672 ```json
673 {
674 ...
675 "assets": [
676 "assets",
677 "favicon.ico",
678 {
679 "glob": "**/*",
680 "input": "./node_modules/leaflet/dist/images",
681 "output": "assets/"
682 }
683 ],
684 ...
685 }
686 ```
687
6881. Configure Leaflet to use the correct URLs as customer marker images
689
690 ```js
691 let layer = marker([ 46.879966, -121.726909 ], {
692 icon: icon({
693 ...Icon.Default.prototype.options,
694 iconUrl: 'assets/marker-icon.png',
695 iconRetinaUrl: 'assets/marker-icon-2x.png',
696 shadowUrl: 'assets/marker-shadow.png'
697 })
698 });
699 ```
700
701## Extensions
702There are several libraries that extend the core functionality of ngx-leaflet:
703* [Leaflet Draw](https://github.com/Asymmetrik/ngx-leaflet-draw)
704* [Leaflet Markercluster](https://github.com/Asymmetrik/ngx-leaflet-markercluster)
705* [Leaflet D3 (Hexbins)](https://github.com/Asymmetrik/ngx-leaflet-d3)
706
707
708## <a name="help">Getting Help</a>
709Here's a list of articles, tutorials, guides, and help resources:
710* [ngx-leaflet on Stack Overflow](https://stackoverflow.com/questions/tagged/ngx-leaflet)
711* [High-level intro to @asymmetrik/ngx-leaflet](https://www.asymmetrik.com/introducing-ngx-leaflet)
712* [Using @asymmetrik/ngx-leaflet in Angular CLI projects](https://www.asymmetrik.com/ngx-leaflet-tutorial-angular-cli)
713* [Integrating 3rd Party Leaflet Libraries with @asymmetrik/ngx-leaflet and @angular/cli](https://github.com/Asymmetrik/ngx-leaflet-tutorial-3rd-party-libs)
714
715
716## Contribute
717PRs 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.
718
719
720## License
721See LICENSE in repository for details.
722
723
724## Credits
725**[Leaflet](http://leafletjs.com/)** Is an awesome mapping package.
726
\No newline at end of file