@bluehalo/ngx-leaflet 18.0.2 → 20.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGES.md +3 -0
- package/README.md +128 -189
- package/fesm2022/bluehalo-ngx-leaflet.mjs +27 -27
- package/fesm2022/bluehalo-ngx-leaflet.mjs.map +1 -1
- package/index.d.ts +314 -3
- package/package.json +5 -7
- package/esm2022/bluehalo-ngx-leaflet.mjs +0 -5
- package/esm2022/lib/core/leaflet.directive.mjs +0 -330
- package/esm2022/lib/core/leaflet.directive.wrapper.mjs +0 -12
- package/esm2022/lib/core/leaflet.util.mjs +0 -20
- package/esm2022/lib/layers/base/leaflet-baselayers.directive.mjs +0 -113
- package/esm2022/lib/layers/control/leaflet-control-layers-changes.model.mjs +0 -11
- package/esm2022/lib/layers/control/leaflet-control-layers-config.model.mjs +0 -7
- package/esm2022/lib/layers/control/leaflet-control-layers.directive.mjs +0 -100
- package/esm2022/lib/layers/control/leaflet-control-layers.wrapper.mjs +0 -58
- package/esm2022/lib/layers/leaflet-layer.directive.mjs +0 -78
- package/esm2022/lib/layers/leaflet-layers.directive.mjs +0 -83
- package/esm2022/lib/layers/leaflet-tile-layer-definition.model.mjs +0 -53
- package/esm2022/lib/leaflet.module.mjs +0 -40
- package/esm2022/public-api.mjs +0 -13
- package/lib/core/leaflet.directive.d.ts +0 -94
- package/lib/core/leaflet.directive.wrapper.d.ts +0 -8
- package/lib/core/leaflet.util.d.ts +0 -7
- package/lib/layers/base/leaflet-baselayers.directive.d.ts +0 -45
- package/lib/layers/control/leaflet-control-layers-changes.model.d.ts +0 -6
- package/lib/layers/control/leaflet-control-layers-config.model.d.ts +0 -9
- package/lib/layers/control/leaflet-control-layers.directive.d.ts +0 -35
- package/lib/layers/control/leaflet-control-layers.wrapper.d.ts +0 -14
- package/lib/layers/leaflet-layer.directive.d.ts +0 -30
- package/lib/layers/leaflet-layers.directive.d.ts +0 -41
- package/lib/layers/leaflet-tile-layer-definition.model.d.ts +0 -33
- package/lib/leaflet.module.d.ts +0 -11
- package/public-api.d.ts +0 -12
package/CHANGES.md
CHANGED
package/README.md
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
# @
|
|
1
|
+
# @bluehalo/ngx-leaflet
|
|
2
2
|
|
|
3
3
|
[![Build Status][travis-image]][travis-url]
|
|
4
4
|
|
|
@@ -7,10 +7,6 @@
|
|
|
7
7
|
|
|
8
8
|
> Leaflet packages for Angular.io.
|
|
9
9
|
> Provides flexible and extensible components for integrating Leaflet v0.7.x and v1.x into Angular.io projects.
|
|
10
|
-
> Supports Angular v18 and use in Angular-CLI based projects.
|
|
11
|
-
|
|
12
|
-
> NOTE: This is the last version of this package that will be published under the @asymmetrik namespace.
|
|
13
|
-
> This and future versions will be published under the namespace: @bluehalo
|
|
14
10
|
|
|
15
11
|
## Table of Contents
|
|
16
12
|
- [Install](#install)
|
|
@@ -28,7 +24,7 @@
|
|
|
28
24
|
Install the package and its peer dependencies via npm (or yarn):
|
|
29
25
|
```
|
|
30
26
|
npm install leaflet
|
|
31
|
-
npm install @
|
|
27
|
+
npm install @bluehalo/ngx-leaflet
|
|
32
28
|
```
|
|
33
29
|
|
|
34
30
|
If you intend to use this library in a typescript project (utilizing the typings), you'll need to install the leaflet typings:
|
|
@@ -41,14 +37,16 @@ If you want to run the demo, clone the repository, perform an ```npm install```,
|
|
|
41
37
|
Not using the latest version of Angular.io? Have a look in [CHANGES.md](/CHANGES.md) to find the right version for your project.
|
|
42
38
|
|
|
43
39
|
## Usage
|
|
44
|
-
|
|
40
|
+
> NOTE: We've simplified the getting started instructions to be more targeted at the most recent versions of Angular.io and the use of Angular CLI.
|
|
41
|
+
|
|
45
42
|
Generally, the steps are:
|
|
46
43
|
|
|
47
44
|
* Install Leaflet, this library, and potentially the Leaflet typings (see above).
|
|
48
45
|
* Import the Leaflet stylesheet
|
|
49
|
-
* Import the
|
|
46
|
+
* Import the `LeafletDirective` etc. into your Module or standalone Component
|
|
50
47
|
* Create and configure a map (see docs below and/or demo)
|
|
51
48
|
|
|
49
|
+
Alternatively, you can use the `LeafletModule` to import the module into your application.
|
|
52
50
|
|
|
53
51
|
### Import the Leaflet Stylesheet
|
|
54
52
|
For leaflet to work, you need to have the leaflet stylesheets loaded into your application.
|
|
@@ -58,7 +56,7 @@ How you include the stylesheet will depend on your specific setup. Here are a fe
|
|
|
58
56
|
#### Direct Import from HTML
|
|
59
57
|
If 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.
|
|
60
58
|
|
|
61
|
-
```
|
|
59
|
+
```angular181html
|
|
62
60
|
<head>
|
|
63
61
|
...
|
|
64
62
|
<link rel="stylesheet" type="text/css" href="./node_modules/leaflet/dist/leaflet.css">
|
|
@@ -66,31 +64,6 @@ If you are just building a webpage and not using a bundler for your css, you'll
|
|
|
66
64
|
</head>
|
|
67
65
|
```
|
|
68
66
|
|
|
69
|
-
#### Configuring Webpack Style Loaders
|
|
70
|
-
If you are using Webpack, you will need to import the css file and have a style-loader configured.
|
|
71
|
-
You can use the demo included in this application as a reference.
|
|
72
|
-
|
|
73
|
-
Generally, in ```vendor.ts```:
|
|
74
|
-
```ts
|
|
75
|
-
import 'leaflet/dist/leaflet.css';
|
|
76
|
-
```
|
|
77
|
-
|
|
78
|
-
And then in your webpack config file:
|
|
79
|
-
```js
|
|
80
|
-
{
|
|
81
|
-
...
|
|
82
|
-
"module" : {
|
|
83
|
-
loaders: [
|
|
84
|
-
...
|
|
85
|
-
{ test: /\.css$/, loaders: [ 'style-loader', 'css-loader' ] },
|
|
86
|
-
...
|
|
87
|
-
]
|
|
88
|
-
},
|
|
89
|
-
...
|
|
90
|
-
}
|
|
91
|
-
```
|
|
92
|
-
|
|
93
|
-
|
|
94
67
|
#### Adding Styles in Angular CLI
|
|
95
68
|
If you are using Angular CLI, you will need to add the Leaflet CSS file to the styles array contained in ```angular.json```
|
|
96
69
|
|
|
@@ -105,52 +78,71 @@ If you are using Angular CLI, you will need to add the Leaflet CSS file to the s
|
|
|
105
78
|
}
|
|
106
79
|
```
|
|
107
80
|
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
#### Typescript Angular.io Module Import
|
|
113
|
-
Before 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).
|
|
81
|
+
#### A Note About Markers
|
|
82
|
+
Leaflet marker URLs don't play well with the Angular CLI build pipeline without some special handling.
|
|
83
|
+
The demo contained in this project demonstrates how to get around this problem. Here is a rough overview of the steps taken to get them working.
|
|
114
84
|
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
import { LeafletModule } from '@asymmetrik/ngx-leaflet';
|
|
119
|
-
|
|
120
|
-
...
|
|
121
|
-
imports: [
|
|
85
|
+
1. Include the leaflet marker assets so they are copied intact to the build output.
|
|
86
|
+
```json
|
|
87
|
+
{
|
|
122
88
|
...
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
89
|
+
"assets": [
|
|
90
|
+
{
|
|
91
|
+
"glob": "**/*",
|
|
92
|
+
"input": "public"
|
|
93
|
+
},
|
|
94
|
+
{
|
|
95
|
+
"glob": "**/*",
|
|
96
|
+
"input": "./node_modules/leaflet/dist/images",
|
|
97
|
+
"output": "assets/"
|
|
98
|
+
}
|
|
99
|
+
],
|
|
100
|
+
...
|
|
101
|
+
}
|
|
102
|
+
```
|
|
126
103
|
|
|
104
|
+
1. Configure Leaflet to use the asset URLs as custom marker images.
|
|
105
|
+
|
|
106
|
+
```typescript
|
|
107
|
+
let layer = marker([ 46.879966, -121.726909 ], {
|
|
108
|
+
icon: icon({
|
|
109
|
+
...Icon.Default.prototype.options,
|
|
110
|
+
iconUrl: 'assets/marker-icon.png',
|
|
111
|
+
iconRetinaUrl: 'assets/marker-icon-2x.png',
|
|
112
|
+
shadowUrl: 'assets/marker-shadow.png'
|
|
113
|
+
})
|
|
114
|
+
});
|
|
127
115
|
```
|
|
128
116
|
|
|
129
|
-
Potentially, you'll also need to import it into the module of the component that is going to actually use the ngx-leaflet directives.
|
|
130
|
-
See Angular.io docs of modules for more details (https://angular.io/guide/ngmodule). In this case, in ```my-module.module.ts```, add:
|
|
131
|
-
|
|
132
|
-
```js
|
|
133
|
-
import { LeafletModule } from '@asymmetrik/ngx-leaflet';
|
|
134
117
|
|
|
135
|
-
|
|
136
|
-
imports: [
|
|
137
|
-
...
|
|
138
|
-
LeafletModule
|
|
139
|
-
]
|
|
140
|
-
...
|
|
118
|
+
### Import LeafletDirective
|
|
141
119
|
|
|
142
|
-
|
|
120
|
+
Before you can use the Leaflet components in your Angular.io app, you'll need to import it in your application.
|
|
121
|
+
Depending on if you're using standalone mode or not, you will import it into your modules and/or components.
|
|
143
122
|
|
|
123
|
+
```typescript
|
|
124
|
+
import { LeafletDirective } from '@bluehalo/ngx-leaflet';
|
|
144
125
|
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
126
|
+
@Component({
|
|
127
|
+
imports: [
|
|
128
|
+
LeafletDirective // Import the LeafletDirective here
|
|
129
|
+
// import other directives as needed
|
|
130
|
+
],
|
|
131
|
+
})
|
|
132
|
+
```
|
|
150
133
|
|
|
134
|
+
Alternatively:
|
|
135
|
+
```typescript
|
|
136
|
+
import { LeafletModule } from '@bluehalo/ngx-leaflet';
|
|
137
|
+
|
|
138
|
+
@NgModule({
|
|
139
|
+
imports: [
|
|
140
|
+
LeafletModule // Import the LeafletModule here
|
|
141
|
+
],
|
|
142
|
+
})
|
|
143
|
+
```
|
|
151
144
|
|
|
152
145
|
### Create and Configure a Map
|
|
153
|
-
Once the dependencies are installed and you have imported the ```LeafletModule```, you're ready to add a map to your page.
|
|
154
146
|
To get a basic map to work, you have to:
|
|
155
147
|
|
|
156
148
|
* Apply the ```leaflet``` attribute directive (see the example below) to an existing DOM element.
|
|
@@ -158,7 +150,7 @@ To get a basic map to work, you have to:
|
|
|
158
150
|
* Provide an initial zoom/center and set of layers either via ```leafletOptions``` or by binding to ```leafletZoom```, ```leafletCenter```, and ```leafletLayers```.
|
|
159
151
|
|
|
160
152
|
Template:
|
|
161
|
-
```
|
|
153
|
+
```angular181html
|
|
162
154
|
<div style="height: 300px;"
|
|
163
155
|
leaflet
|
|
164
156
|
[leafletOptions]="options">
|
|
@@ -166,7 +158,7 @@ Template:
|
|
|
166
158
|
```
|
|
167
159
|
|
|
168
160
|
Example leafletOptions object:
|
|
169
|
-
```
|
|
161
|
+
```typescript
|
|
170
162
|
options = {
|
|
171
163
|
layers: [
|
|
172
164
|
tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', { maxZoom: 18, attribution: '...' })
|
|
@@ -187,7 +179,7 @@ The ```[leafletLayersControl]``` input bindings give you the ability to add the
|
|
|
187
179
|
The layers control lets the user toggle layers and overlays on and off.
|
|
188
180
|
|
|
189
181
|
Template:
|
|
190
|
-
```
|
|
182
|
+
```angular181html
|
|
191
183
|
<div style="height: 300px;"
|
|
192
184
|
leaflet
|
|
193
185
|
[leafletOptions]="options"
|
|
@@ -195,17 +187,27 @@ Template:
|
|
|
195
187
|
</div>
|
|
196
188
|
```
|
|
197
189
|
|
|
198
|
-
|
|
199
|
-
```
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
190
|
+
Component with example layersControl object:
|
|
191
|
+
```typescript
|
|
192
|
+
import { LeafletDirective, LeafletLayersControlDirective } from '@bluehalo/ngx-leaflet';
|
|
193
|
+
|
|
194
|
+
@Component({
|
|
195
|
+
imports: [
|
|
196
|
+
LeafletDirective,
|
|
197
|
+
LeafletLayersControlDirective,
|
|
198
|
+
],
|
|
199
|
+
})
|
|
200
|
+
export class MyComponent {
|
|
201
|
+
protected readonly layersControl = {
|
|
202
|
+
baseLayers: {
|
|
203
|
+
'Open Street Map': tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', { maxZoom: 18, attribution: '...' }),
|
|
204
|
+
'Open Cycle Map': tileLayer('https://{s}.tile.opencyclemap.org/cycle/{z}/{x}/{y}.png', { maxZoom: 18, attribution: '...' })
|
|
205
|
+
},
|
|
206
|
+
overlays: {
|
|
207
|
+
'Big Circle': circle([ 46.95, -122 ], { radius: 5000 }),
|
|
208
|
+
'Big Square': polygon([[ 46.8, -121.55 ], [ 46.9, -121.55 ], [ 46.9, -121.7 ], [ 46.8, -121.7 ]])
|
|
209
|
+
}
|
|
210
|
+
}
|
|
209
211
|
}
|
|
210
212
|
```
|
|
211
213
|
|
|
@@ -218,7 +220,7 @@ There are several different ways to add layers to the map.
|
|
|
218
220
|
You can add layers (baselayers, markers, or custom layers) to the map without showing them in the layer control using the ```[leafletLayers]``` directive.
|
|
219
221
|
|
|
220
222
|
Template:
|
|
221
|
-
```
|
|
223
|
+
```angular181html
|
|
222
224
|
<div style="height: 300px;"
|
|
223
225
|
leaflet
|
|
224
226
|
[leafletOptions]="options"
|
|
@@ -227,7 +229,7 @@ Template:
|
|
|
227
229
|
```
|
|
228
230
|
|
|
229
231
|
Layers array:
|
|
230
|
-
```
|
|
232
|
+
```typescript
|
|
231
233
|
layers = [
|
|
232
234
|
circle([ 46.95, -122 ], { radius: 5000 }),
|
|
233
235
|
polygon([[ 46.8, -121.85 ], [ 46.92, -121.92 ], [ 46.87, -121.8 ]]),
|
|
@@ -236,19 +238,22 @@ layers = [
|
|
|
236
238
|
```
|
|
237
239
|
|
|
238
240
|
You can also add an individual layer to the map using the ```[leafletLayer]``` directive.
|
|
239
|
-
Using this approach allows you to use
|
|
241
|
+
Using this approach allows you to use ```@for``` and ```@if``` to control whether individual layers are added to or removed from the map.
|
|
240
242
|
|
|
241
243
|
Template:
|
|
242
|
-
```
|
|
244
|
+
```angular181html
|
|
243
245
|
<div style="height: 300px;"
|
|
244
246
|
leaflet
|
|
245
247
|
[leafletOptions]="options">
|
|
246
|
-
|
|
248
|
+
|
|
249
|
+
@if (showLayer) {
|
|
250
|
+
<div [leafletLayer]="layer"></div>
|
|
251
|
+
}
|
|
247
252
|
</div>
|
|
248
253
|
```
|
|
249
254
|
|
|
250
255
|
Layer:
|
|
251
|
-
```
|
|
256
|
+
```typescript
|
|
252
257
|
layer = circle([ 46.95, -122 ], { radius: 5000 });
|
|
253
258
|
```
|
|
254
259
|
|
|
@@ -287,7 +292,7 @@ This section includes more detailed documentation of the functionality of the di
|
|
|
287
292
|
### Advanced Map Configuration
|
|
288
293
|
There are several input bindings available for configuring the map.
|
|
289
294
|
|
|
290
|
-
```
|
|
295
|
+
```angular181html
|
|
291
296
|
<div leaflet style="height: 300px;"
|
|
292
297
|
[leafletOptions]="options"
|
|
293
298
|
[leafletPanOptions]="panOptions"
|
|
@@ -314,7 +319,7 @@ Input binding for FitBounds options (see [Leaflet's](https://leafletjs.com/Slava
|
|
|
314
319
|
|
|
315
320
|
|
|
316
321
|
### Dynamically changing zoom level, center, fitBounds, etc.
|
|
317
|
-
```
|
|
322
|
+
```angular181html
|
|
318
323
|
<div leaflet style="height: 300px;"
|
|
319
324
|
[leafletOptions]="options"
|
|
320
325
|
[(leafletZoom)]="zoom"
|
|
@@ -355,7 +360,7 @@ If you plan to show more than just baselayers, you should use the more advanced
|
|
|
355
360
|
|
|
356
361
|
For an example of the basic map setup, you should check out the *Simple Base Layers* demo.
|
|
357
362
|
|
|
358
|
-
```
|
|
363
|
+
```angular181html
|
|
359
364
|
<div leaflet style="height: 300px;"
|
|
360
365
|
[leafletOptions]="options"
|
|
361
366
|
[leafletBaseLayers]="baseLayers"
|
|
@@ -366,7 +371,7 @@ For an example of the basic map setup, you should check out the *Simple Base Lay
|
|
|
366
371
|
#### [leafletBaseLayers]: Control.LayersObject
|
|
367
372
|
Input bind an ```Control.LayersObject``` to be synced to the map.
|
|
368
373
|
|
|
369
|
-
```
|
|
374
|
+
```typescript
|
|
370
375
|
baseLayers: {
|
|
371
376
|
'layer1': Layer,
|
|
372
377
|
'layer2': Layer
|
|
@@ -402,7 +407,7 @@ And, use ```[leafletLayersControl]``` to allow users to optionally turn layers/o
|
|
|
402
407
|
|
|
403
408
|
For an example of using the layers controls, you should check out the *Layers and Layer Controls* demo.
|
|
404
409
|
|
|
405
|
-
```
|
|
410
|
+
```angular181html
|
|
406
411
|
<div leaflet style="height: 300px;"
|
|
407
412
|
[leafletOptions]="options"
|
|
408
413
|
[leafletLayers]="layers"
|
|
@@ -423,7 +428,7 @@ As a result of how the map is synced, the order of layers is not guaranteed to b
|
|
|
423
428
|
#### [leafletLayersControl]: Control.Layers
|
|
424
429
|
Input bind a Control.Layers specification. The object contains properties for each of the two constructor arguments for the Control.Layers constructor.
|
|
425
430
|
|
|
426
|
-
```
|
|
431
|
+
```typescript
|
|
427
432
|
layersControl: {
|
|
428
433
|
baseLayers: {
|
|
429
434
|
'layerName': Layer
|
|
@@ -439,16 +444,20 @@ Input binding for Control.Layers options (see [Leaflet's](https://leafletjs.com/
|
|
|
439
444
|
These options are passed into the constructor on creation.
|
|
440
445
|
|
|
441
446
|
|
|
442
|
-
### Advanced Layer Management: Individual Layers and
|
|
447
|
+
### Advanced Layer Management: Individual Layers and @for / @if
|
|
443
448
|
The ```[leafletLayer]``` input bindings gives you the ability to add a single layer to the map.
|
|
444
449
|
While this may seem limiting, you can nest elements inside the map element, each with a ```[leafletLayer]``` input.
|
|
445
450
|
The result of this is that each layer will be added to the map.
|
|
446
|
-
If you add a structural directive -
|
|
451
|
+
If you add a structural directive - ```@for``` or ```@if``` - you can get some added flexibility when controlling layers.
|
|
447
452
|
|
|
448
|
-
```
|
|
453
|
+
```angular181html
|
|
449
454
|
<div leaflet style="height: 300px;"
|
|
450
455
|
[leafletOptions]="options">
|
|
451
|
-
|
|
456
|
+
|
|
457
|
+
@for (layer of layers; track layer.id) {
|
|
458
|
+
<div [leafletLayer]="layer"></div>
|
|
459
|
+
}
|
|
460
|
+
|
|
452
461
|
</div>
|
|
453
462
|
```
|
|
454
463
|
|
|
@@ -507,14 +516,14 @@ With a reference to the directive, you can invoke the ```getMap()``` function to
|
|
|
507
516
|
This output is emitted when once when the map is initially created inside of the Leaflet directive.
|
|
508
517
|
The event will only fire when the map exists and is ready for manipulation.
|
|
509
518
|
|
|
510
|
-
```
|
|
519
|
+
```angular181html
|
|
511
520
|
<div leaflet
|
|
512
521
|
[leafletOptions]="options"
|
|
513
522
|
(leafletMapReady)="onMapReady($event)">
|
|
514
523
|
</div>
|
|
515
524
|
```
|
|
516
525
|
|
|
517
|
-
```
|
|
526
|
+
```typescript
|
|
518
527
|
onMapReady(map: Map) {
|
|
519
528
|
// Do stuff with map
|
|
520
529
|
}
|
|
@@ -534,39 +543,35 @@ This means that you can create your own component or directive and inject the ``
|
|
|
534
543
|
This 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.
|
|
535
544
|
|
|
536
545
|
|
|
537
|
-
```
|
|
546
|
+
```angular181html
|
|
538
547
|
<!-- On the same DOM element -->
|
|
539
|
-
<div leaflet myCustomDirective>
|
|
540
|
-
</div>
|
|
548
|
+
<div leaflet myCustomDirective></div>
|
|
541
549
|
|
|
542
550
|
<!-- On a child DOM element -->
|
|
543
551
|
<div leaflet>
|
|
544
|
-
|
|
552
|
+
<div myCustomDirective></div>
|
|
545
553
|
</div>
|
|
546
554
|
```
|
|
547
555
|
|
|
548
|
-
```
|
|
556
|
+
```typescript
|
|
557
|
+
|
|
549
558
|
@Directive({
|
|
550
|
-
|
|
559
|
+
selector: '[myCustomDirective]'
|
|
551
560
|
})
|
|
552
561
|
export class MyCustomDirective {
|
|
553
|
-
|
|
562
|
+
readonly #leafletDirective = inject(LeafletDirective);
|
|
554
563
|
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
if (null != this.leafletDirective.getMap()) {
|
|
561
|
-
// Do stuff with the map
|
|
562
|
-
}
|
|
563
|
-
}
|
|
564
|
+
someFunction() {
|
|
565
|
+
if (null !== this.#leafletDirective.getMap()) {
|
|
566
|
+
// Do stuff with the map
|
|
567
|
+
}
|
|
568
|
+
}
|
|
564
569
|
}
|
|
565
570
|
```
|
|
566
571
|
|
|
567
572
|
The 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.
|
|
568
573
|
As mentioned above, it might not work depending on how you are packaging your component.
|
|
569
|
-
This is how the ```@
|
|
574
|
+
This is how the ```@bluehalo/ngx-leaflet-draw``` and ```@bluehalo/ngx-leaflet-d3``` packages work, so you can use them as references.
|
|
570
575
|
|
|
571
576
|
|
|
572
577
|
### A Note About Change Detection
|
|
@@ -586,7 +591,7 @@ Leaflet event handlers run outside of Angular's zone, where changes to input bou
|
|
|
586
591
|
To ensure your changes are detected and applied, you need to make those changed inside of Angular's zone.
|
|
587
592
|
Fortunately, this is extremely easy.
|
|
588
593
|
|
|
589
|
-
```
|
|
594
|
+
```typescript
|
|
590
595
|
fitBounds: any = null;
|
|
591
596
|
circle = circle([ 46.95, -122 ], { radius: 5000 });
|
|
592
597
|
|
|
@@ -613,7 +618,7 @@ Another option is to manually tell the change detector to detect changes.
|
|
|
613
618
|
The drawback to this option is that it is less precise.
|
|
614
619
|
This will trigger change detection for this component and all of its children.
|
|
615
620
|
|
|
616
|
-
```
|
|
621
|
+
```typescript
|
|
617
622
|
fitBounds: any = null;
|
|
618
623
|
circle = circle([ 46.95, -122 ], { radius: 5000 });
|
|
619
624
|
|
|
@@ -633,73 +638,7 @@ ngOnInit() {
|
|
|
633
638
|
|
|
634
639
|
});
|
|
635
640
|
}
|
|
636
|
-
```
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
### A Note About Markers
|
|
640
|
-
If 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.
|
|
641
|
-
The issue is related to how Leaflet manipulates the image URLs used to render markers when you are using the default marker images.
|
|
642
|
-
The 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).
|
|
643
|
-
The demo contained in this project demonstrates how to get around this problem (at least in a Webpack environment).
|
|
644
|
-
But, here is a rough overview of the steps taken to get them working.
|
|
645
|
-
|
|
646
|
-
#### Webpack Marker Workaround
|
|
647
|
-
|
|
648
|
-
1. Import the marker images in your vendor file to get Webpack to process the images in the asset pipeline
|
|
649
|
-
|
|
650
|
-
```js
|
|
651
|
-
import 'leaflet/dist/images/marker-shadow.png';
|
|
652
|
-
import 'leaflet/dist/images/marker-icon.png';
|
|
653
|
-
```
|
|
654
|
-
|
|
655
|
-
1. Either host the images statically or use the file-loader Webpack plugin to generate the images.
|
|
656
|
-
1. 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.
|
|
657
|
-
1. Configure Leaflet to use the correct URLs as customer marker images
|
|
658
|
-
|
|
659
|
-
```js
|
|
660
|
-
let layer = marker([ 46.879966, -121.726909 ], {
|
|
661
|
-
icon: icon({
|
|
662
|
-
...Icon.Default.prototype.options,
|
|
663
|
-
iconUrl: '2b3e1faf89f94a4835397e7a43b4f77d.png',
|
|
664
|
-
iconRetinaUrl: '680f69f3c2e6b90c1812a813edf67fd7.png',
|
|
665
|
-
shadowUrl: 'a0c6cc1401c107b501efee6477816891.png'
|
|
666
|
-
})
|
|
667
|
-
});
|
|
668
|
-
```
|
|
669
|
-
|
|
670
|
-
#### Angular CLI Marker Workaround
|
|
671
|
-
|
|
672
|
-
If 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:
|
|
673
|
-
|
|
674
|
-
1. 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.
|
|
675
|
-
```json
|
|
676
|
-
{
|
|
677
|
-
...
|
|
678
|
-
"assets": [
|
|
679
|
-
"assets",
|
|
680
|
-
"favicon.ico",
|
|
681
|
-
{
|
|
682
|
-
"glob": "**/*",
|
|
683
|
-
"input": "./node_modules/leaflet/dist/images",
|
|
684
|
-
"output": "assets/"
|
|
685
|
-
}
|
|
686
|
-
],
|
|
687
|
-
...
|
|
688
|
-
}
|
|
689
|
-
```
|
|
690
|
-
|
|
691
|
-
1. Configure Leaflet to use the correct URLs as customer marker images
|
|
692
|
-
|
|
693
|
-
```js
|
|
694
|
-
let layer = marker([ 46.879966, -121.726909 ], {
|
|
695
|
-
icon: icon({
|
|
696
|
-
...Icon.Default.prototype.options,
|
|
697
|
-
iconUrl: 'assets/marker-icon.png',
|
|
698
|
-
iconRetinaUrl: 'assets/marker-icon-2x.png',
|
|
699
|
-
shadowUrl: 'assets/marker-shadow.png'
|
|
700
|
-
})
|
|
701
|
-
});
|
|
702
|
-
```
|
|
641
|
+
```
|
|
703
642
|
|
|
704
643
|
## Extensions
|
|
705
644
|
There are several libraries that extend the core functionality of ngx-leaflet:
|
|
@@ -711,9 +650,9 @@ There are several libraries that extend the core functionality of ngx-leaflet:
|
|
|
711
650
|
## <a name="help">Getting Help</a>
|
|
712
651
|
Here's a list of articles, tutorials, guides, and help resources:
|
|
713
652
|
* [ngx-leaflet on Stack Overflow](https://stackoverflow.com/questions/tagged/ngx-leaflet)
|
|
714
|
-
* [High-level intro to @
|
|
715
|
-
* [Using @
|
|
716
|
-
* [Integrating 3rd Party Leaflet Libraries with @
|
|
653
|
+
* [High-level intro to @bluehalo/ngx-leaflet](https://github.com/BlueHalo/ngx-leaflet/wiki)
|
|
654
|
+
* [Using @bluehalo/ngx-leaflet in Angular CLI projects](https://github.com/BlueHalo/ngx-leaflet/wiki/Getting-Started-Tutorial)
|
|
655
|
+
* [Integrating 3rd Party Leaflet Libraries with @bluehalo/ngx-leaflet and @angular/cli](https://github.com/BlueHalo/ngx-leaflet/wiki/Integrating-Plugins)
|
|
717
656
|
|
|
718
657
|
|
|
719
658
|
## Contribute
|