Giter VIP home page Giter VIP logo

ngx-leaflet's Introduction

@bluehalo/ngx-leaflet

Build Status

Leaflet packages for Angular.io. Provides flexible and extensible components for integrating Leaflet v0.7.x and v1.x into Angular.io projects. Supports Angular v18 and use in Angular-CLI based projects.

NOTE: This is the last version of this package that will be published under the @asymmetrik namespace. This and future versions will be published under the namespace: @bluehalo

Table of Contents

Install

Install the package and its peer dependencies via npm (or yarn):

npm install leaflet
npm install @bluehalo/ngx-leaflet

If you intend to use this library in a typescript project (utilizing the typings), you'll need to install the leaflet typings:

npm install --save-dev @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

Not using the latest version of Angular.io? Have a look in CHANGES.md to find the right version for your project.

Usage

To 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.). Generally, the steps are:

  • Install Leaflet, this library, and potentially the Leaflet typings (see above).
  • Import the Leaflet stylesheet
  • Import the Leaflet module into your Angular project
  • Create and configure a map (see docs below and/or demo)

Import the Leaflet Stylesheet

For leaflet to work, you need to have the leaflet stylesheets loaded into your application. If you've installed via npm, you will need to load ./node_modules/leaflet/dist/leaflet.css. How you include the stylesheet will depend on your specific setup. Here are a few examples:

Direct Import from HTML

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.

<head>
	...
	<link rel="stylesheet" type="text/css" href="./node_modules/leaflet/dist/leaflet.css">
	...
</head>

Configuring Webpack Style Loaders

If you are using Webpack, you will need to import the css file and have a style-loader configured. You can use the demo included in this application as a reference.

Generally, in vendor.ts:

import 'leaflet/dist/leaflet.css';

And then in your webpack config file:

{
	...
	"module" : {
		loaders: [
			...
			{ test: /\.css$/, loaders: [ 'style-loader', 'css-loader' ] },
			...
		]	
	},
	...
}

Adding Styles in Angular CLI

If you are using Angular CLI, you will need to add the Leaflet CSS file to the styles array contained in angular.json

{
	...
	"styles": [
		"styles.css",
		"./node_modules/leaflet/dist/leaflet.css"
	],
	...
}

Import Code Dependencies and Module

This project is exported using UMD and it includes typings. So, you shouldn't have to do anything special to use it if you're building your project in Typescript.

Typescript Angular.io Module Import

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).

For example, in your app.module.ts, add:

import { LeafletModule } from '@bluehalo/ngx-leaflet';

...
imports: [
	...
	LeafletModule
]
...

Potentially, you'll also need to import it into the module of the component that is going to actually use the ngx-leaflet directives. See Angular.io docs of modules for more details (https://angular.io/guide/ngmodule). In this case, in my-module.module.ts, add:

import { LeafletModule } from '@bluehalo/ngx-leaflet';

...
imports: [
	...
	LeafletModule
]
...

Not Using Typescript?

You brave soul. The code is exported using UMD. The bundles are generated as part of the build (npm run build) and placed into the ./dist dir. You should be able to import is using whatever module system/builder you're using, even if you aren't using Typescript.

Create and Configure a Map

Once the dependencies are installed and you have imported the LeafletModule, you're ready to add a map to your page. To get a basic map to work, you have to:

  • Apply the leaflet attribute directive (see the example below) to an existing DOM element.
  • Style the map DOM element with a height. Otherwise, it'll render with a 0 pixel height.
  • Provide an initial zoom/center and set of layers either via leafletOptions or by binding to leafletZoom, leafletCenter, and leafletLayers.

Template:

<div style="height: 300px;"
     leaflet 
     [leafletOptions]="options">
</div>

Example leafletOptions object:

options = {
	layers: [
		tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', { maxZoom: 18, attribution: '...' })
	],
	zoom: 5,
	center: latLng(46.879966, -121.726909)
};

Changes to leafletOptions are ignored after they are initially set. This is because these options are passed into the map constructor, so they can't be changed anyways. So, make sure the object exists before the map is created. You'll want to create the object in ngOnInit or hide the map DOM element with *ngIf until you can create the options object.

Add a Layers Control

The [leafletLayersControl] input bindings give you the ability to add the layers control to the map. The layers control lets the user toggle layers and overlays on and off.

Template:

<div style="height: 300px;"
     leaflet 
     [leafletOptions]="options"
     [leafletLayersControl]="layersControl">
</div>

Example layersControl object:

layersControl = {
	baseLayers: {
		'Open Street Map': tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', { maxZoom: 18, attribution: '...' }),
		'Open Cycle Map': tileLayer('https://{s}.tile.opencyclemap.org/cycle/{z}/{x}/{y}.png', { maxZoom: 18, attribution: '...' })
	},
	overlays: {
		'Big Circle': circle([ 46.95, -122 ], { radius: 5000 }),
		'Big Square': polygon([[ 46.8, -121.55 ], [ 46.9, -121.55 ], [ 46.9, -121.7 ], [ 46.8, -121.7 ]])
	}
}

You can add any kind of Leaflet layer you want to the overlays map. This includes markers, shapes, geojson, custom layers from other libraries, etc.

Add Custom Layers (base layers, markers, shapes, etc.)

There are several different ways to add layers to the map. You can add layers (baselayers, markers, or custom layers) to the map without showing them in the layer control using the [leafletLayers] directive.

Template:

<div style="height: 300px;"
     leaflet
     [leafletOptions]="options"
     [leafletLayers]="layers">
</div>

Layers array:

layers = [
	circle([ 46.95, -122 ], { radius: 5000 }),
	polygon([[ 46.8, -121.85 ], [ 46.92, -121.92 ], [ 46.87, -121.8 ]]),
	marker([ 46.879966, -121.726909 ])
];

You can also add an individual layer to the map using the [leafletLayer] directive. Using this approach allows you to use *ngFor and *ngIf to control whether individual layers are added to or removed from the map.

Template:

<div style="height: 300px;"
     leaflet
     [leafletOptions]="options">
     <div *ngIf="showLayer" [leafletLayer]="layer"></div>
</div>

Layer:

layer = circle([ 46.95, -122 ], { radius: 5000 });

Dynamically Change Map Layers using [leafletLayers]

Layer inputs (arrays and maps) are mutable Previous versions of this plugin treated layers arrays and layer control objects as immutable data structures. We've changed that behavior. Now, mutable changes to the leafletLayers, leafletBaseLayers, and leafletLayersControl inputs are detected.

The plugin is now using internal ngx iterable and key/value differs to detect and track changes to mutable data structures. This approach requires a deep compare of the contents of the data structure (which can be slow when the contents are really big). For immutable data structures, all that is needed is a top-level instance equality check (which is way faster). This change is backwards compatible and was motivated by feedback and confusion. While there is a performance impact for some use cases, this approach is more intuitive.

There are at least two good approaches to improving performance when there are a lot of layers bound to the map. First, you can use the OnPush change detection strategy. There's an example of this in the demo. Second, 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.

Working with Leaflet Events

Often, you'll want to make changes based on a map click or other Leaflet interaction. The ngx-leaflet plugin supports several map events and layer events as documented in the API section.

You may occasionally need to handle events that aren't exposed through the plugin, however. When that happens, you will need to be aware of how Zones and change detection work to ensure your event handling works as expected. Take a look at A Note About Change Detection for more details. This is by design and a common thing to deal with when using third party libraries and Angular.

API

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

Advanced Map Configuration

There are several input bindings available for configuring the map.

<div leaflet style="height: 300px;"
     [leafletOptions]="options"
     [leafletPanOptions]="panOptions"
     [leafletZoomOptions]="zoomOptions"
     [leafletZoomPanOptions]="zoomPanOptions"
     [leafletFitBoundsOptions]="fitBoundsOptions">
</div>

[leafletOptions]

Input binding for the initial leaflet map options (see Leaflet's docs). These options can only be set initially because they are used to create the map. Later changes are ignored.

[leafletPanOptions]

Input binding for pan options (see Leaflet's docs). These options are stored and used whenever pan operations are invoked.

[leafletZoomOptions]

Input binding for zoom options (see Leaflet's docs). These options are stored and used whenever zoom operations are invoked.

[leafletZoomPanOptions]

Input binding for zoom/pan options (see Leaflet's docs). These options are stored and used whenever zoom/pan operations are invoked.

[leafletFitBoundsOptions]

Input binding for FitBounds options (see Leaflet's docs). These options are stored and used whenever FitBounds operations are invoked.

Dynamically changing zoom level, center, fitBounds, etc.

<div leaflet style="height: 300px;"
     [leafletOptions]="options"
     [(leafletZoom)]="zoom"
     [(leafletCenter)]="center"
     [leafletFitBounds]="fitBounds">
</div>

[(leafletZoom)]: number

Input and Output binding for the map zoom level.

[leafletMaxZoom]: number

Input binding for the maximum zoom level for the map.

[leafletMinZoom]: number

Input binding for the minimum zoom level for the map.

[(leafletCenter)]: LatLng

Input and Output binding for the map center position.

Note: center/zoom operations may interfere with each other

Zoom/Center operations that are applied in rapid succession may interfere with or cancel each other. If both changes are picked up at the same time, the component applies the changes as a map.setView() operation to ensure both are processed. Additionally, 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.

[leafletFitBounds]: LatLngBounds

Input bind a LatLngBounds value that will be applied to the map using Map.setFitBounds(). This operation has no output binding because the input fitBounds usually results in a slightly different map bounds.

[leafletMaxBounds]: LatLngBounds

Input bind a LatLngBounds value that will be applied to the map using Map.setMaxBounds().

Simple Layer Management: Setting Baselayers

There is a convenience input binding for setting the baselayers on the map called [leafletBaseLayers]. You can also provide [leafletLayersControlOptions] if you want to show the control on the map that allows you to switch between baselayers. If you plan to show more than just baselayers, you should use the more advanced layers controls described in Advanced Layer Management below.

For an example of the basic map setup, you should check out the Simple Base Layers demo.

<div leaflet style="height: 300px;"
     [leafletOptions]="options"
     [leafletBaseLayers]="baseLayers"
     [leafletLayersControlOptions]="layersControlOptions">
</div>

[leafletBaseLayers]: Control.LayersObject

Input bind an Control.LayersObject to be synced to the map.

baseLayers: {
	'layer1': Layer,
	'layer2': Layer
}

On changes, the component syncs the baseLayers on the map with the layers in this object. Syncing 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. If it finds a baselayer that is still added to the map, it will assume that is still the baselayer and leave it. If 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. Layers are compared using instance equality.

If you use this directive, you can still manually use the [leafletLayers] directive, but you will not be able to use the [leafletLayersControl] directive. This directive internally uses the layers control, so if you add both, they'll interfere with each other. Because it uses control.layers under the hood, you can still provide options for the layers control.

[leafletLayersControlOptions]

Input binding for Control.Layers options (see Leaflet's docs). These options are passed into the layers control constructor on creation.

Advanced Layer Management: Layers, and Layers Control

The [leafletLayers] and [leafletLayersControl] input bindings give you direct access to manipulate layers and the layers control. When the array bound to [leafletLayers] is changed, the directive will synchronize the layers on the map to the layers in the array. This includes tile layers and any added shapes.

The [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. When 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.

So, use [leafletLayers] to add a collection of layers to the map. And, use [leafletLayersControl] to allow users to optionally turn layers/overlays on and off.

For an example of using the layers controls, you should check out the Layers and Layer Controls demo.

<div leaflet style="height: 300px;"
     [leafletOptions]="options"
     [leafletLayers]="layers"
     [leafletLayersControl]="layersControl"
     [leafletLayersControlOptions]="layersControlOptions">
</div>

[leafletLayers]: Layer[]

Input bind an array of all layers to be synced (and made visible) in the map.

On changes, the component syncs the layers on the map with the layers in this array. Syncing is performed by selectively adding or removing layers. Layers are compared using instance equality. As a result of how the map is synced, the order of layers is not guaranteed to be consistent as changes are made.

[leafletLayersControl]: Control.Layers

Input bind a Control.Layers specification. The object contains properties for each of the two constructor arguments for the Control.Layers constructor.

layersControl: {
	baseLayers: {
		'layerName': Layer
	},
	overlays: {
		'overlayName': Layer
	}
}

[leafletLayersControlOptions]

Input binding for Control.Layers options (see Leaflet's docs). These options are passed into the constructor on creation.

Advanced Layer Management: Individual Layers and *ngFor / *ngIf

The [leafletLayer] input bindings gives you the ability to add a single layer to the map. While this may seem limiting, you can nest elements inside the map element, each with a [leafletLayer] input. The result of this is that each layer will be added to the map. If you add a structural directive - *ngFor or *ngIf - you can get some added flexibility when controlling layers.

<div leaflet style="height: 300px;"
     [leafletOptions]="options">
	<div *ngFor="let l of layers" [leafletLayer]="l"></div>
</div>

In this example, each layer in the layers array will create a new child div element. Each element will have a [leafletLayer] input binding, which will result in the layer being added to the map. For more details, you should check out the Layers and ngFor demo.

There are several layer events that are available when you are using this approach to controlling layers.

Layer Events

When you are using the [leafletLayer] directive to add a layer, you can also access output bindings for layer events. Two events that are currently exposed include: (leafletLayerAdd) and (leafletLayerRemove). Each of these emits a LeafletEvent object.

Map Events

Leaflet exposes a lot of map events including map zoom, map move, and mouse interactions. The plugin exposes several of the most common events. For 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. For a working example, check out the events section of the demo.

Mouse Interactions: LeafletMouseEvent

The following events are provided:

  • (leafletClick)
  • (leafletDoubleClick)
  • (leafletMouseDown)
  • (leafletMouseUp)
  • (leafletMouseMove)
  • (leafletMouseOver)
  • (leafletMouseOut)

Map Zoom and Move: LeafletEvent

The following events are provided:

  • (leafletMapMove)
  • (leafletMapMoveStart)
  • (leafletMapMoveEnd)
  • (leafletMapZoom)
  • (leafletMapZoomStart)
  • (leafletMapZoomEnd)

Getting a Reference to the Map

Occasionally, you may need to directly access the Leaflet map instance. For example, to call invalidateSize() when the map div changes size or is shown/hidden. There are a couple of different ways to achieve this depending on what you're trying to do.

The easiest and most flexible way is to use the output binding leafletMapReady. This output is invoked after the map is created, the argument of the event being the Map instance.

The second is to get a reference to the leaflet directive itself - and there are a couple of ways to do this. With a reference to the directive, you can invoke the getMap() function to get a reference to the Map instance.

(leafletMapReady): Map

This output is emitted when once when the map is initially created inside of the Leaflet directive. The event will only fire when the map exists and is ready for manipulation.

<div leaflet
     [leafletOptions]="options"
     (leafletMapReady)="onMapReady($event)">
</div>
onMapReady(map: Map) {
	// Do stuff with map
}

This method of getting the map makes the most sense if you are using the Leaflet directive inside your own component and just need to add some limited functionality or register some event handlers.

Inject LeafletDirective into your Component

This is the more advanced technique and it won't always work depending on your setup. In particular, this will likely not work unless you are writing your own third-party library that extends the functionality of ngx-leaflet. If this approach does not work for you, try using the leafletMapReady event described above.

In Angular.io, directives are injectable the same way that Services are. This means that you can create your own component or directive and inject the LeafletDirective into it. 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.

<!-- On the same DOM element -->
<div leaflet myCustomDirective>
</div>

<!-- On a child DOM element -->
<div leaflet>
	<div myCustomDirective></div>
</div>
@Directive({
	selector: '[myCustomDirective]'
})
export class MyCustomDirective {
	leafletDirective: LeafletDirective;

	constructor(leafletDirective: LeafletDirective) {
		this.leafletDirective = leafletDirective;
	}

	someFunction() {
		if (null != this.leafletDirective.getMap()) {
			// Do stuff with the map
		}
	}
}

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. As mentioned above, it might not work depending on how you are packaging your component. This is how the @bluehalo/ngx-leaflet-draw and @bluehalo/ngx-leaflet-d3 packages work, so you can use them as references.

A Note About Change Detection

Change detection is at the core of how Angular works. Angular.io uses Zone.js to scope how and when (events, actions, etc.) to trigger change detection. It's important to scope it carefully because change detection can be fairly expensive, so you don't want it to happen constantly.

Libraries like ngx-leaflet have to decide what to do inside and outside of the Angular zone, balancing convenience and performance. Leaflet registers handlers for a lot of mouse events. To 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. The impact of this is that Angular won't automatically detect changes that you make inside of a Leaflet event callback.

The 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.

Running Inside of Angular's Zone

Leaflet event handlers run outside of Angular's zone, where changes to input bound fields will not be detected automatically. To ensure your changes are detected and applied, you need to make those changed inside of Angular's zone. Fortunately, this is extremely easy.

fitBounds: any = null;
circle = circle([ 46.95, -122 ], { radius: 5000 });

// Inject the Change Detector into your component
constructor(private zone: NgZone) {}

ngOnInit() {

	// The 'add' event callback handler happens outside of the Angular zone
	this.circle.on('add', () => {

		// But, we can run stuff inside of Angular's zone by calling NgZone.run()
		// everything inside the arrow function body happens inside of Angular's zone, where changes will be detected
		this.zone.run(() => {
			this.fitBounds = this.circle.getBounds();
		});

	});
}

Manually Triggering Change Detection

Another option is to manually tell the change detector to detect changes. The drawback to this option is that it is less precise. This will trigger change detection for this component and all of its children.

fitBounds: any = null;
circle = circle([ 46.95, -122 ], { radius: 5000 });

// Inject the Change Detector into your component
constructor(private changeDetector: ChangeDetectorRef) {}

ngOnInit() {

	// The 'add' event callback happens outside of the Angular zone
	this.circle.on('add', () => {

		// Because we're outside of Angular's zone, this change won't be detected
		this.fitBounds = this.circle.getBounds();

		// But, it will if we tell Angular to detect changes 
		this.changeDetector.detectChanges();

	});
}

A Note About Markers

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. The issue is related to how Leaflet manipulates the image URLs used to render markers when you are using the default marker images. 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). The demo contained in this project demonstrates how to get around this problem (at least in a Webpack environment). But, here is a rough overview of the steps taken to get them working.

Webpack Marker Workaround

  1. Import the marker images in your vendor file to get Webpack to process the images in the asset pipeline

    import 'leaflet/dist/images/marker-shadow.png';
    import 'leaflet/dist/images/marker-icon.png';
  2. Either host the images statically or use the file-loader Webpack plugin to generate the images.

  3. 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.

  4. Configure Leaflet to use the correct URLs as customer marker images

    let layer = marker([ 46.879966, -121.726909 ], {
    	icon: icon({
    		...Icon.Default.prototype.options,
    		iconUrl: '2b3e1faf89f94a4835397e7a43b4f77d.png',
    		iconRetinaUrl: '680f69f3c2e6b90c1812a813edf67fd7.png',
    		shadowUrl: 'a0c6cc1401c107b501efee6477816891.png'
    	})
    });

Angular CLI Marker Workaround

If you build your project using the Angular CLI, you can make the default leaflet marker assets available by doing the following:

  1. Configure the CLI (by editing angular.json)to include leaflet assets as below. Detailed instructions can be found in the asset-configuration documentation.

    {
    	...
    	"assets": [
    		"assets",
    		"favicon.ico",
    		{
    			"glob": "**/*",
    			"input": "./node_modules/leaflet/dist/images",
    			"output": "assets/"
    		}
    	],
    	...
    }
  2. Configure Leaflet to use the correct URLs as customer marker images

    let layer = marker([ 46.879966, -121.726909 ], {
    	icon: icon({
    		...Icon.Default.prototype.options,
    		iconUrl: 'assets/marker-icon.png',
    		iconRetinaUrl: 'assets/marker-icon-2x.png',
    		shadowUrl: 'assets/marker-shadow.png'
    	})
    });

Extensions

There are several libraries that extend the core functionality of ngx-leaflet:

Here's a list of articles, tutorials, guides, and help resources:

Contribute

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

License

See LICENSE in repository for details.

Credits

Leaflet Is an awesome mapping package.

ngx-leaflet's People

Contributors

androbin avatar aprilmay0 avatar atgoogat avatar behroozbc avatar bradoyler avatar chakti avatar colinfergusir avatar essentin avatar gabomgp avatar gavilanch avatar ikbenignace avatar luan-dev avatar luketherrien avatar lundev avatar mcurtis22 avatar quentinbt avatar reblace avatar sblaauw avatar ssmale avatar tiangolo avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

ngx-leaflet's Issues

Marker and HTML

Hello,

I have a question:
Is it possible to access marker HTML or apply CSS classes to a marker? I want to be sure, before I would rewrite all my gmaps code to leaflet. Thanks!

Missing installation step

Your installation instructions are missing the following instructions:

Modify app.module.ts

  1. Add the following import:
    import { LeafletModule } from '@asymmetrik/angular2-leaflet';

  2. Add the following to @NgModule:
    imports: [
    ...
    LeafletModule,

Issues when using typings

I was using this library just fine, now I updated and I'm having problems with the typings. When I compile or do ng serve I get this:

ERROR in /Users/facundomedica/Documents/Proyectos/Angular/apperto-admin-v3/node_modules/@types/leaflet/index.d.ts (583,56): ',' expected.
ERROR in /Users/facundomedica/Documents/Proyectos/Angular/apperto-admin-v3/node_modules/@types/leaflet/index.d.ts (583,65): ',' expected.
ERROR in /Users/facundomedica/Documents/Proyectos/Angular/apperto-admin-v3/node_modules/@types/leaflet/index.d.ts (583,77): ',' expected.
ERROR in /Users/facundomedica/Documents/Proyectos/Angular/apperto-admin-v3/node_modules/@types/leaflet/index.d.ts (583,104): Expression expected.
ERROR in /Users/facundomedica/Documents/Proyectos/Angular/apperto-admin-v3/node_modules/@types/leaflet/index.d.ts (583,117): ';' expected.
ERROR in /Users/facundomedica/Documents/Proyectos/Angular/apperto-admin-v3/node_modules/@types/leaflet/index.d.ts (584,24): ',' expected.
ERROR in /Users/facundomedica/Documents/Proyectos/Angular/apperto-admin-v3/node_modules/@types/leaflet/index.d.ts (584,54): Expression expected.
ERROR in /Users/facundomedica/Documents/Proyectos/Angular/apperto-admin-v3/node_modules/@types/leaflet/index.d.ts (585,16): ';' expected.
ERROR in /Users/facundomedica/Documents/Proyectos/Angular/apperto-admin-v3/node_modules/@types/leaflet/index.d.ts (585,36): '(' expected.
ERROR in /Users/facundomedica/Documents/Proyectos/Angular/apperto-admin-v3/node_modules/@types/leaflet/index.d.ts (586,17): ';' expected.
ERROR in /Users/facundomedica/Documents/Proyectos/Angular/apperto-admin-v3/node_modules/@types/leaflet/index.d.ts (587,23): ',' expected.
ERROR in /Users/facundomedica/Documents/Proyectos/Angular/apperto-admin-v3/node_modules/@types/leaflet/index.d.ts (587,44): ';' expected.
ERROR in /Users/facundomedica/Documents/Proyectos/Angular/apperto-admin-v3/node_modules/@types/leaflet/index.d.ts (588,14): ';' expected.
ERROR in /Users/facundomedica/Documents/Proyectos/Angular/apperto-admin-v3/node_modules/@types/leaflet/index.d.ts (589,16): ';' expected.
ERROR in /Users/facundomedica/Documents/Proyectos/Angular/apperto-admin-v3/node_modules/@types/leaflet/index.d.ts (590,16): ';' expected.
ERROR in /Users/facundomedica/Documents/Proyectos/Angular/apperto-admin-v3/node_modules/@types/leaflet/index.d.ts (591,21): ',' expected.
ERROR in /Users/facundomedica/Documents/Proyectos/Angular/apperto-admin-v3/node_modules/@types/leaflet/index.d.ts (591,61): ';' expected.
ERROR in /Users/facundomedica/Documents/Proyectos/Angular/apperto-admin-v3/node_modules/@types/leaflet/index.d.ts (593,13): Expression expected.
ERROR in /Users/facundomedica/Documents/Proyectos/Angular/apperto-admin-v3/node_modules/@types/leaflet/index.d.ts (593,33): '(' expected.
ERROR in /Users/facundomedica/Documents/Proyectos/Angular/apperto-admin-v3/node_modules/@types/leaflet/index.d.ts (1409,45): ',' expected.
ERROR in /Users/facundomedica/Documents/Proyectos/Angular/apperto-admin-v3/node_modules/@types/leaflet/index.d.ts (594,5): Unused label.
ERROR in /Users/facundomedica/Documents/Proyectos/Angular/apperto-admin-v3/node_modules/@types/leaflet/index.d.ts (583,79): The right-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type.
ERROR in /Users/facundomedica/Documents/Proyectos/Angular/apperto-admin-v3/node_modules/@types/leaflet/index.d.ts (583,87): Property 'MultiLineString' does not exist on type 'typeof "/Users/facundomedica/Documents/Proyectos/Angular/apperto-admin-v3/node_modules/@types/geo...'.
ERROR in /Users/facundomedica/Documents/Proyectos/Angular/apperto-admin-v3/node_modules/@types/leaflet/index.d.ts (584,5): Cannot find name 'constructor'.
ERROR in /Users/facundomedica/Documents/Proyectos/Angular/apperto-admin-v3/node_modules/@types/leaflet/index.d.ts (584,17): Cannot find name 'latlngs'.
ERROR in /Users/facundomedica/Documents/Proyectos/Angular/apperto-admin-v3/node_modules/@types/leaflet/index.d.ts (584,26): 'LatLngExpression' only refers to a type, but is being used as a value here.
ERROR in /Users/facundomedica/Documents/Proyectos/Angular/apperto-admin-v3/node_modules/@types/leaflet/index.d.ts (584,46): Cannot find name 'options'.
ERROR in /Users/facundomedica/Documents/Proyectos/Angular/apperto-admin-v3/node_modules/@types/leaflet/index.d.ts (584,56): 'PolylineOptions' only refers to a type, but is being used as a value here.
ERROR in /Users/facundomedica/Documents/Proyectos/Angular/apperto-admin-v3/node_modules/@types/leaflet/index.d.ts (585,5): Cannot find name 'toGeoJSON'.
ERROR in /Users/facundomedica/Documents/Proyectos/Angular/apperto-admin-v3/node_modules/@types/leaflet/index.d.ts (585,26): Property 'Feature' does not exist on type 'typeof "/Users/facundomedica/Documents/Proyectos/Angular/apperto-admin-v3/node_modules/@types/geo...'.
ERROR in /Users/facundomedica/Documents/Proyectos/Angular/apperto-admin-v3/node_modules/@types/leaflet/index.d.ts (586,5): Cannot find name 'getLatLngs'.
ERROR in /Users/facundomedica/Documents/Proyectos/Angular/apperto-admin-v3/node_modules/@types/leaflet/index.d.ts (587,5): Cannot find name 'setLatLngs'.
ERROR in /Users/facundomedica/Documents/Proyectos/Angular/apperto-admin-v3/node_modules/@types/leaflet/index.d.ts (587,16): Cannot find name 'latlngs'.
ERROR in /Users/facundomedica/Documents/Proyectos/Angular/apperto-admin-v3/node_modules/@types/leaflet/index.d.ts (587,25): 'LatLngExpression' only refers to a type, but is being used as a value here.
ERROR in /Users/facundomedica/Documents/Proyectos/Angular/apperto-admin-v3/node_modules/@types/leaflet/index.d.ts (588,5): Cannot find name 'isEmpty'.
ERROR in /Users/facundomedica/Documents/Proyectos/Angular/apperto-admin-v3/node_modules/@types/leaflet/index.d.ts (588,16): Cannot find name 'boolean'.
ERROR in /Users/facundomedica/Documents/Proyectos/Angular/apperto-admin-v3/node_modules/@types/leaflet/index.d.ts (589,5): Cannot find name 'getCenter'.
ERROR in /Users/facundomedica/Documents/Proyectos/Angular/apperto-admin-v3/node_modules/@types/leaflet/index.d.ts (590,5): Cannot find name 'getBounds'.
ERROR in /Users/facundomedica/Documents/Proyectos/Angular/apperto-admin-v3/node_modules/@types/leaflet/index.d.ts (591,5): Cannot find name 'addLatLng'.
ERROR in /Users/facundomedica/Documents/Proyectos/Angular/apperto-admin-v3/node_modules/@types/leaflet/index.d.ts (591,15): Cannot find name 'latlng'.
ERROR in /Users/facundomedica/Documents/Proyectos/Angular/apperto-admin-v3/node_modules/@types/leaflet/index.d.ts (591,23): 'LatLngExpression' only refers to a type, but is being used as a value here.
ERROR in /Users/facundomedica/Documents/Proyectos/Angular/apperto-admin-v3/node_modules/@types/leaflet/index.d.ts (591,42): 'LatLngExpression' only refers to a type, but is being used as a value here.
ERROR in /Users/facundomedica/Documents/Proyectos/Angular/apperto-admin-v3/node_modules/@types/leaflet/index.d.ts (593,5): Cannot find name 'feature'.
ERROR in /Users/facundomedica/Documents/Proyectos/Angular/apperto-admin-v3/node_modules/@types/leaflet/index.d.ts (593,23): Property 'Feature' does not exist on type 'typeof "/Users/facundomedica/Documents/Proyectos/Angular/apperto-admin-v3/node_modules/@types/geo...'.
ERROR in /Users/facundomedica/Documents/Proyectos/Angular/apperto-admin-v3/node_modules/@types/leaflet/index.d.ts (594,14): 'PolylineOptions' only refers to a type, but is being used as a value here.
ERROR in /Users/facundomedica/Documents/Proyectos/Angular/apperto-admin-v3/node_modules/@types/leaflet/index.d.ts (597,83): Generic type 'Polyline<T, geojson, LineString>' requires 3 type argument(s).
ERROR in /Users/facundomedica/Documents/Proyectos/Angular/apperto-admin-v3/node_modules/@types/leaflet/index.d.ts (599,30): Generic type 'Polyline<T, geojson, LineString>' requires 3 type argument(s).
ERROR in /Users/facundomedica/Documents/Proyectos/Angular/apperto-admin-v3/node_modules/@types/leaflet/index.d.ts (1422,27): Generic type 'Icon<T, IconOptions>' requires 2 type argument(s).
ERROR in /Users/facundomedica/Documents/Proyectos/Angular/apperto-admin-v3/node_modules/@types/leaflet/index.d.ts (1428,45): Generic type 'Icon<T, IconOptions>' requires 2 type argument(s).
ERROR in /Users/facundomedica/Documents/Proyectos/Angular/apperto-admin-v3/node_modules/@types/leaflet/index.d.ts (1439,30): Generic type 'Icon<T, IconOptions>' requires 2 type argument(s).
ERROR in /Users/facundomedica/Documents/Proyectos/Angular/apperto-admin-v3/node_modules/@types/leaflet/index.d.ts (1446,12): Generic type 'Icon<T, IconOptions>' requires 2 type argument(s).
ERROR in /Users/facundomedica/Documents/Proyectos/Angular/apperto-admin-v3/node_modules/@types/leaflet/index.d.ts (1463,19): Generic type 'Icon<T, IconOptions>' requires 2 type argument(s).
ERROR in /Users/facundomedica/Documents/Proyectos/Angular/apperto-admin-v3/node_modules/@asymmetrik/ngx-leaflet-draw/dist/leaflet-draw/core/leaflet-draw.directive.d.ts (7,28): Namespace '"/Users/facundomedica/Documents/Proyectos/Angular/apperto-admin-v3/node_modules/@types/leaflet/index".Control' has no exported member 'Draw'.
ERROR in /Users/facundomedica/Documents/Proyectos/Angular/apperto-admin-v3/node_modules/@asymmetrik/ngx-leaflet-draw/dist/leaflet-draw/core/leaflet-draw.directive.d.ts (9,28): Namespace '"/Users/facundomedica/Documents/Proyectos/Angular/apperto-admin-v3/node_modules/@types/leaflet/index".Control' has no exported member 'DrawConstructorOptions'.
ERROR in /Users/facundomedica/Documents/Proyectos/Angular/apperto-admin-v3/node_modules/@asymmetrik/ngx-leaflet-draw/dist/leaflet-draw/core/leaflet-draw.directive.d.ts (16,46): Namespace '"/Users/facundomedica/Documents/Proyectos/Angular/apperto-admin-v3/node_modules/@types/leaflet/index".Control' has no exported member 'DrawConstructorOptions'.
ERROR in /Users/facundomedica/Documents/Proyectos/Angular/apperto-admin-v3/node_modules/@asymmetrik/ngx-leaflet-draw/dist/leaflet-draw/core/leaflet-draw.directive.d.ts (16,81): Namespace '"/Users/facundomedica/Documents/Proyectos/Angular/apperto-admin-v3/node_modules/@types/leaflet/index".Control' has no exported member 'DrawConstructorOptions'.

In my package.json I have this:

    "@asymmetrik/ngx-leaflet": "^2.4.0",
    "@asymmetrik/ngx-leaflet-draw": "^2.6.0",
    "@types/leaflet": "^1.2.0",
    "@types/leaflet-draw": "^0.4.8",
    "leaflet": "^1.2.0",
    "leaflet-draw": "^0.4.12",

How to create a pie chart marker ?

I would like to replace my circle marker to pie chart. I made a google search and found something like leaflet.minicharts, cluster markers, etc.Any suggestions?

How we can use dragend event ?

Please have a look below code :

import { Component } from '@angular/core';
import * as L from 'leaflet';

@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.scss']
})
export class AppComponent {
  title = 'app';
  // baseLayers = [ L.tileLayer('http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', { maxZoom: 18 }) ];
  // center = L.latLng([ 46.879966, -121.726909 ]);
  // fitBounds = L.latLngBounds([ [20.5937,78.9629], [40.774, -74.125] ]);
  // layers = [
  //   marker = 
  // ]

  getDefaultMapPosition(){
    return { lat: -33.868699, lng: 151.209147 }; //canberra,Australia ->   -35.281979, 149.128814
  }

  options = {
    layers: [
      L.tileLayer('http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', { maxZoom: 18, attribution: '...' })
    ],
    zoom: 13,
    center: L.latLng(this.getDefaultMapPosition().lat, this.getDefaultMapPosition().lng)
  };
  layersControl = {
    baseLayers: {
      'Open Street Map': L.tileLayer('http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', { maxZoom: 18, attribution: '...' }),
      'Open Cycle Map': L.tileLayer('http://{s}.tile.opencyclemap.org/{z}/{x}/{y}.png', { maxZoom: 18, attribution: '...' })
    },
    overlays: {
      'Big Circle': L.circle([46.95, -122], { radius: 5000 }),
      'Big Square': L.polygon([[46.8, -121.55], [46.9, -121.55], [46.9, -121.7], [46.8, -121.7]])
    }
  }
  defaultMarkericon = L.icon({
    iconUrl: '/assets/fevicon/map-icon.png',
    iconSize: [23, 23], // size of the icon   
  });
  layers = [
    L.circle([46.95, -122], { radius: 5000 }),
    L.polygon([[46.8, -121.85], [46.92, -121.92], [46.87, -121.8]]),
    L.marker([46.879966, -121.726909],{ icon: this.defaultMarkericon,draggable:true }),
  ];

  
}

It would be appreciate if you help me asap.

Lack of documentation for markers section

Hi,

It's unclear in the current version of the package and README how to add a marker to the map.

You state

  1. Configure Leaflet to use the correct URLs as customer marker images
let layer= L.marker([ 46.879966, -121.726909 ], {
 	icon: L.icon({
 		iconSize: [ 25, 41 ],
 		iconAnchor: [ 13, 0 ],
 		iconUrl: '2273e3d8ad9264b7daa5bdbf8e6b47f8.png',
 		shadowUrl: '44a526eed258222515aa21eaffd14a96.png'
 	})
 });

but where do i add this layer in the directive parameters?

I tryed everything, but nothing works, and I went in the demo forlder but the example of marker is too much complicated for a starting point.

Leaflet way was to do something like L.marker([50.5, 30.5]).addTo(map); and it's added.

Can you please clarify this in the documentation or make an example with marker, popup and tooltip as they are widely used around?

Thank you

How to add GeoJSON layer to a map using [leafletLayers] in a directive?

I'm trying to add a GeoJSON layer, but not work?

in component.html
...
leaflet style="height: 400px;"
[leafletOptions]="options"
[leafletPanOptions]="panOptions"
[leafletZoomOptions]="zoomOptions"
[leafletZoomPanOptions]="zoomPanOptions"
[leafletFitBoundsOptions]="fitBoundsOptions"
[leafletZoom]="zoom"
[leafletCenter]="center"
[leafletBaseLayers]="baseLayers"
[leafletLayersControlOptions]="layersControlOptions"
[leafletLayers]="layers"
(leafletMapReady)="initMap($event)">

in component.ts
...
this.layers = [L.geoJSON(this.geodata)];

Thanks.

Angular4 Typescript SystemJS Integration Problem

Hello,

I tried installing your component following the documentation steps.
Did the three npm installs:
npm install leaflet npm install @asymmetrik/ngx-leaflet npm install @types/leaflet

After importing the module in the app module I get the following error :
node_modules/@asymmetrik/ngx-leaflet/dist/leaflet/core/leafl‌​et.directive.d.ts (2,37): Module '"leaflet"' has no exported member 'MapOptions'

I tried editing the leafl‌​et.directive.d.ts changing the options attribute to :any just to see if it would work but I got other errors afterwards

Is there a specific step I'm missing ? Or a specific Angular Version to use ?
I'm using Angular 4.2.5 with AOT but no webpack

Trying to integrate angular2-leaflet into existing application

Hi, I've built an application using ng-cli
Ive followed the directions on the README and am trying to drop your demo module into my existing app
Im getting the following error:
ERROR in [default] //trunk/node_modules/@asymmetrik/angular2-leaflet/dist/leaflet/core/leaflet.directive.d.ts:1:0
Cannot find type definition file for 'leaflet'.

Any suggestions.

issue on running the demo in Windows

PS C:\Users\xxxx\Documents\angular2-leaflet> gulp dev
[11:45:27] Using gulpfile ~\Documents\angular2-leaflet\gulpfile.js
[11:45:27] Starting 'dev'...
[11:45:27] Starting 'validate-ts'...
[11:45:28] Finished 'validate-ts' after 847 ms
[11:45:28] Starting 'webpack-dev-server'...
[11:45:28] Starting 'watch-ts'...
[11:45:28] Finished 'watch-ts' after 27 ms
[11:45:28] [webpack] http://localhost:9000/webpack-dev-server/index.html
ts-loader: Using [email protected]
ts-loader: Using [email protected]
Hash: 3c13ce2d5cf40dab683c
Version: webpack 2.3.2
Time: 205ms
Asset Size Chunks Chunk Names
application.js 360 bytes 0 [emitted] application
vendor.js 6.28 kB 1 [emitted] vendor

ERROR in error TS18002: The 'files' list in config file 'tsconfig.json' is empty.

ERROR in ./src/demo/main.ts
Module build failed: error while parsing tsconfig.json

ERROR in error TS18002: The 'files' list in config file 'tsconfig.json' is empty.

ERROR in ./src/demo/vendor.ts
Module build failed: error while parsing tsconfig.json
webpack: Failed to compile.

LeafletModule is not an NgModule

app.module.ts
import {LeafletModule} from "@asymmetrik/angular2-leaflet";
@NgModule({
providers: [],
imports: [NgxChartsModule, BrowserModule, FormsModule, LeafletModule],
declarations: [AppComponent, LeafletMapComponent],
bootstrap: [AppComponent]
})
export class AppModule { }

ERROR in LeafletModule is not an NgModule

reload map

Hello! How can I change leaflet options and reload map?
My code
public options = {
layers: [
//L.tileLayer('http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', { maxZoom: 18, attribution: '...' })
L.tileLayer('assets/img/{z}/'+this.floor+' [www.imagesplitter.net]-{y}-{x}.jpeg', { maxZoom: 3, attribution: '...' })
],
zoom: 1,
center: L.latLng([ 46.879966, -121.726909 ]),
crs: L.CRS.Simple
};

Button
<button (click)="next()" style="position: absolute; right: 50px;">Next

Button event
public next(){
this.floor += 1;
this.options.layers = [
//L.tileLayer('http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', { maxZoom: 18, attribution: '...' })
L.tileLayer('assets/img/{z}/'+this.floor+' [www.imagesplitter.net]-{y}-{x}.jpeg', { maxZoom: 3, attribution: '...' })
];
}
Can you help, please?

Quickstart issue

Hello.

When trying to use this component in angular project, there appears following problem: map is shown as separated square pieces covering random screen space (as st the screenshot below).

screenshot

The LeafletModule is imported in the work module as it is described in README. The component itself has been taken from the Basic Map Setup as is.

The markup of the app is built on the Bootstrap grid base. Leaflet is located within a col-md-.. div, but goes out of its scope.

So, what can cause such a problem?

Thank you

How do I Fly to a point?

Hi,

I am new to using leaflet and ngx plugin. How can I get the map to fly to a particular location on a button click, which is outside the map. I see the leaflet has a method called "flyTo". How do I do this using this plugin. I am using this in typescript with typings project. Thanks!

Error while ng build with AOT

Hi,

I am using ngx-leaflet and it builds up somehow when I dont using AOT flag. But as soon as I use AOT flag it is showing me this error.

My module file:

import { LeafletModule } from '@asymmetrik/ngx-leaflet';
...

@Pipe({ name: 'safeHtml' })
export class SafeHtmlPipe implements PipeTransform {
    constructor(private sanitized: DomSanitizer) { }
    transform(value) {
        return this.sanitized.bypassSecurityTrustHtml(value);
    }
}

@NgModule({
    ...
    imports: [
       ...,
        LeafletModule.forRoot()
    ],
...
})

export class TaskModule { }

ERROR in Error encountered resolving symbol values statically. Could not resolve @asymmetrik/ngx-leaflet relative to /builds/vernuso/trust/src/app/task/task.module.ts., resolving symbol TaskModule in /builds/vernuso/trust/src/app/task/task.module.ts, resolving symbol TaskModule in /builds/vernuso/trust/src/app/task/task.module.ts, resolving symbol TaskModule in /builds/vernuso/trust/src/app/task/task.module.ts

ERROR in multi ./src/styles.css ./src/css/mapping.css .//quill/dist/quill.core.css .//quill/dist/quill.snow.css .//leaflet/dist/leaflet.css
Module not found: Error: Can't resolve '/builds/vernuso/trust/node_modules/leaflet/dist/leaflet.css' in '/builds/vernuso/trust'
@ multi ./src/styles.css ./src/css/mapping.css ./
/quill/dist/quill.core.css .//quill/dist/quill.snow.css .//leaflet/dist/leaflet.css

Am I missing anything here? Please help.

Uncaught Error: Leaflet must be loaded first

When trying to use external non-typed library (leaflet-contextmenu) i get this error:

Uncaught Error: Leaflet must be loaded first
at eval (eval at webpackJsonp.../../../../script-loader/addScript.js.module.exports (addScript.js:9), :21:10)
at eval (eval at webpackJsonp.../../../../script-loader/addScript.js.module.exports (addScript.js:9), :25:3)
at eval ()
at webpackJsonp.../../../../script-loader/addScript.js.module.exports (addScript.js:9)
at Object.../../../../script-loader/index.js!../../../../leaflet-contextmenu/dist/leaflet.contextmenu.js (leaflet.contextmenu.js?f1d1:1)
at webpack_require (bootstrap 4e7a92c…:54)
at Object.5 (scripts.bundle.js:37)
at webpack_require (bootstrap 4e7a92c…:54)
at webpackJsonpCallback (bootstrap 4e7a92c…:25)
at scripts.bundle.js:1

How to access the map instance ?

I want to get coordinates from the map based on the mouse position. I don't see a way to do this in the docs, is there a way I could achieve this ?

click inside marker popup

I build my popup text for single marker through a loop. I need to bind click event for each line of my popup text to a function and I've coded something like this lines

uris = uris.concat('<a (click)="showSelected("' + uri.s.value + '")" href="#" >' + uri.s.value + '</a><br>'); 
 L.marker([long, lat], {
                  icon: L.icon({ iconUrl: 'assets/marker-icon.png', shadowUrl: 'assets/marker-shadow.png' })
                }).bindPopup(uris).addTo(this.map);

but showSelected isn't call in any way. Can I perform this or I need to change my logic?

Using leaflet.markercluster

I have tried to use leaflet.markercluster with angular2-leaflet and @angular/cli.

I have tried this:

import * as L from 'leaflet';

import 'leaflet.markercluster';

but using any of the markercluster extensions produce a "ng build" compile error saying they are not found on type "typeof L". Any suggestions?

Add the global css import step to setup documentation

This looks really great so far, and the instructions are so nice and clean, but they exclude the fact that anyone starting with this project (especially using the angular cli), will also need to add that final step of including the global css in their .angular-cli.json

"styles": [
        "styles.css",
        "../node_modules/leaflet/dist/leaflet.css"
      ],

How can I integrate with Leaflet Routing Machine? {question}

I am trying to add the Leaflet Routing Machine control in my Angular 4 project but I am not sure how to do it. I tried declaring the route I wanted in the template and then binding to the "[leafletLayersControl]" but that didn't seem to work.

Module '"leaflet"' has no exported member 'MapOptions'.

In app.module.ts I've impored LeafletModule.

import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';

import { AppComponent } from './app.component';

import { LeafletModule } from '@asymmetrik/ngx-leaflet';

@NgModule({
  declarations: [
    AppComponent
  ],
  imports: [
    BrowserModule,
    LeafletModule.forRoot()
  ],
  providers: [],
  bootstrap: [AppComponent]
})
export class AppModule { }

But when I run the app I get this error:

ERROR in /Users/matija/Documents/Projects/truewether/frontend/node_modules/@asymmetrik/ngx-leaflet/dist/leaflet/core/leaflet.directive.d.ts (2,37): Module '"leaflet"' has no exported member 'MapOptions'.

webpack: Failed to compile.

It's Angular 4 project. Created with CLI.
Any other info I should provide?

need help on @types extension

Hi,

I know it's not the best place to ask, but I have an issue when trying to use an existing library in angular.io

I am using @types/leaflet that defines a type

export namespace Icon {
    interface DefaultIconOptions extends BaseIconOptions {
        imagePath?: string;
    }

    class Default extends Icon<DefaultIconOptions> {
        static imagePath?: string;
        constructor(options?: DefaultIconOptions);
    }
}

Now, I would like to use the following library which extends the Icon behavior: https://www.npmjs.com/package/leaflet-fa-markers
The issue is that it's plain JS and the type is not defined in @types...
node_modules/leaflet-fa-markers/L.Icon.FontAwesome.js

L.Icon.FontAwesome = L.Icon.extend({

	options: {
		popupAnchor: [0, -50]
	},

	createIcon: function () {

		var div = document.createElement('div');
...

So far, I've imported js and css in .angular-cli.json, but can't figure out how to import it in my service... So far I've imported the js lib

import 'leaflet-fa-markers';
//...
        let marker = new L.Marker([ lat, lng], {
          icon: L.icon.fontAwesome({
            iconClasses: 'fa fa-info-circle', // you _could_ add other icon classes, not tested.
            markerColor: '#00a9ce',
            iconColor: '#FFF'
          }),
          draggable: true});

But I get the error:

src/app/_services/canimap.service.ts (99,24): Property 'fontAwesome' does not exist on type '(options: IconOptions) => Icon<IconOptions>'.

Fails on rollup build

I'm geting these following erorrs on rollup aot build.

dist/tmp/app/home/demo/leaflet-d3/ping/ping-demo.component.js (23:21) 'tile
Layer' is not exported by 'node_modules/leaflet/dist/leaflet-src.js'
dist/tmp/app/home/demo/leaflet-d3/ping/ping-demo.component.js (41:22) 'latL
ng' is not exported by 'node_modules/leaflet/dist/leaflet-src.js'
dist/tmp/app/home/demo/leaflet-d3/ping/ping-demo.component.js (68:31) 'circ
le' is not exported by 'node_modules/leaflet/dist/leaflet-src.js'
node_modules/@asymmetrik/angular2-leaflet/dist/leaflet/core/leaflet.directive.js (6:32)
'latLng' is not exported by 'node_modules/leaflet/dist/leaflet-src.js'
node_modules/@asymmetrik/angular2-leaflet/dist/leaflet/core/leaflet.directive.js (20:21)
 'map' is not exported by 'node_modules/leaflet/dist/leaflet-src.js'
node_modules/@asymmetrik/angular2-leaflet/dist/leaflet/layers/control/leaflet-control-la
yers.wrapper.js (13:31) 'control' is not exported by 'node_modules/leaflet/dist/leaflet-
src.js'

Angular 2 Leaflet rendering issue

I have used Angular Cli to generate a new project. I have also used quite a few node_modules for my application such as angularfire2, bootstrap, jQuery.

I tried to add leaflet according to the documentation, but unfortunately I don't get the map rendered:
2017-05-28_11-01-08

In my project, I have created a folder in src/app called 'map' and have created a module under that called 'leaflet'. In my leaflet.component.ts, I have the below codes:

import { Component, OnInit } from '@angular/core';
import { GlobalService } from '../shared-service/global.service';

@Component({
selector: 'app-leaflet',
templateUrl: './leaflet.component.html',
styleUrls: ['./leaflet.component.css']
})
export class LeafletComponent implements OnInit {
zoom: number;
center: L.LatLng;
fitBounds: L.LatLngBounds;
constructor() {
}
ngOnInit() {
}
}
In the leaflet.component.html, I have the below code:
<div leaflet style="height: 300px;"
[leafletCenter]="center"
[leafletFitBounds]="fitBounds">
</div>

Also in my app.module.ts, I have imported the LeafletModule.

Am I missing something?

Error 404

Hi

i have this error if anyoine can help me

localhost:3000/@asymmetrik/angular2-leaflet Failed to load resource: the server responded with a status of 404 (Not Found)
localhost/:30 Error: Fetch error: 404 Not Found
Instantiating http://localhost:3000/@asymmetrik/angular2-leaflet
Loading http://localhost:3000/app/mobile-content/mobile-content.module.js
Loading http://localhost:3000/app/app.module.js
Loading http://localhost:3000/app/main.js
Loading app
at fetch.js:37
at ZoneDelegate.invoke (zone.js:391)
at Zone.run (zone.js:141)
at zone.js:818
at ZoneDelegate.invokeTask (zone.js:424)
at Zone.runTask (zone.js:191)
at drainMicroTaskQueue (zone.js:584)

Using with esri-leaflet

I've been trying to use esri-leaflet with angular2-leaflet and Angular CLI but without success.

I've installed esri-leaflet 2.0.8 and types/esri-leaflet 2.0.0 packages.
I added
import 'esri-leaflet';
to my map component and in the onMapReady function added
L.esri.basemapLayer("Topographic").addTo(map);

ng build compiles without any errors, but during runtime L.esri is undefined.

Any ideas?

/node_modules/@types/leaflet/index.d.ts gives errors on compile

I've added this module to my Angular v4.3.6 application.
When I add LeafletModule.forRoot() to my imports in app.modules.ts and recompile I get lots of errors in /node_modules/@types/leaflet/index.d.ts
The first few are:

  • /node_modules/@types/leaflet/index.d.ts (583,56): ',' expected.
  • /node_modules/@types/leaflet/index.d.ts (583,104): Expression expected.
  • /node_modules/@types/leaflet/index.d.ts (585,36): '(' expected.

When I open this file in my IDE (WebStorm v2017.2.3) it also reports these errors.
Mostly TS1005 and TS1109.

I also downloaded the zip from github of the dev and master branch and I can run the demos.
In my application, I don't use gulp, so I assume I need to reconfigure something.
I run ng serve to compile and run my application.

I tried Googling but couldn't find a solution.
I already excluded my node_modules in my tsconfig.json
Other specs:

  • Window10
  • nmp v4.3.0
  • node v6.9.5
  • tsc v1.0.3.0

Any help is much appreciated.

Leaflet popup actions

Is there any possibility to render with the html content of a popup? For example to implement data binding (ngFor ,ngIf,ngmodel). I want to implement a form for every marker popup,and I don't know how to take the values of the form

Reload Map and multiple maps in the same page

I'm creating a dashboard with draggable maps. The fact is that when i drag a new map, the dashboard refreshes and the old map dissapears, i just can see the markers in the first map, and the recently created map doesn't loads anything. The first map works when i refresh the page (F5) but the second doesn't appears... and something that i noticed is that when I zoom in the second map, the zoom affects the first map... Do you have any Idea on what's going on?? how can I use multiple maps in the same page? How can I reload the coordinates from options or my entire map??

I'm uploading some pictures to clarify

screen shot 2017-09-05 at 9 20 23 am
In this picture, you can see my map working correctly

screen shot 2017-09-05 at 9 20 38 am
This is what happens when I add another map, both maps seems not to be present

screen shot 2017-09-05 at 9 20 51 am
When I refresh the entire page, the first map loads, please check the map markers, they are correctly positioned in this picture

screen shot 2017-09-05 at 9 21 14 am
I zoomed a bit in the second map and guess what? The first map got zoom and my markers changed their location...

TypeError: Cannot read property 'off' of null when navigate out of map with [leafletLayersControl]

Environment:
"@asymmetrik/ngx-leaflet": "^2.5.0",
"@types/leaflet": "^1.2.1",
"leaflet": "^1.2.0"

When navigate out of a map, en error is rising :

ERROR Error: Uncaught (in promise): TypeError: Cannot read property 'off' of null
TypeError: Cannot read property 'off' of null
at NewClass.removeLayer (leaflet-src.js:4855)
at leaflet-control-layers.wrapper.js:39
at DefaultKeyValueDiffer.webpackJsonp.../../../core/@angular/core.es5.js.DefaultKeyValueDiffer.forEachRemovedItem (core.es5.js:7642)
at LeafletControlLayersWrapper.webpackJsonp.../../../../@asymmetrik/ngx-leaflet/dist/leaflet/layers/control/leaflet-control-layers.wrapper.js.LeafletControlLayersWrapper.applyChanges (leaflet-control-layers.wrapper.js:38)
at LeafletControlLayersWrapper.webpackJsonp.../../../../@asymmetrik/ngx-leaflet/dist/leaflet/layers/control/leaflet-control-layers.wrapper.js.LeafletControlLayersWrapper.applyBaseLayerChanges (leaflet-control-layers.wrapper.js:18)
at LeafletLayersControlDirective.webpackJsonp.../../../../@asymmetrik/ngx-leaflet/dist/leaflet/layers/control/leaflet-control-layers.directive.js.LeafletLayersControlDirective.updateLayers (leaflet-control-layers.directive.js:71)
at LeafletLayersControlDirective.set [as layersControlConfig] (leaflet-control-layers.directive.js:43)
at LeafletLayersControlDirective.webpackJsonp.../../../../@asymmetrik/ngx-leaflet/dist/leaflet/layers/control/leaflet-control-layers.directive.js.LeafletLayersControlDirective.ngOnDestroy (leaflet-control-layers.directive.js:58)
at callProviderLifecycles (core.es5.js:11208)
at callElementProvidersLifecycles (core.es5.js:11177)
at NewClass.removeLayer (leaflet-src.js:4855)
at leaflet-control-layers.wrapper.js:39
at DefaultKeyValueDiffer.webpackJsonp.../../../core/@angular/core.es5.js.DefaultKeyValueDiffer.forEachRemovedItem (core.es5.js:7642)
at LeafletControlLayersWrapper.webpackJsonp.../../../../@asymmetrik/ngx-leaflet/dist/leaflet/layers/control/leaflet-control-layers.wrapper.js.LeafletControlLayersWrapper.applyChanges (leaflet-control-layers.wrapper.js:38)
at LeafletControlLayersWrapper.webpackJsonp.../../../../@asymmetrik/ngx-leaflet/dist/leaflet/layers/control/leaflet-control-layers.wrapper.js.LeafletControlLayersWrapper.applyBaseLayerChanges (leaflet-control-layers.wrapper.js:18)
at LeafletLayersControlDirective.webpackJsonp.../../../../@asymmetrik/ngx-leaflet/dist/leaflet/layers/control/leaflet-control-layers.directive.js.LeafletLayersControlDirective.updateLayers (leaflet-control-layers.directive.js:71)
at LeafletLayersControlDirective.set [as layersControlConfig] (leaflet-control-layers.directive.js:43)
at LeafletLayersControlDirective.webpackJsonp.../../../../@asymmetrik/ngx-leaflet/dist/leaflet/layers/control/leaflet-control-layers.directive.js.LeafletLayersControlDirective.ngOnDestroy (leaflet-control-layers.directive.js:58)
at callProviderLifecycles (core.es5.js:11208)
at callElementProvidersLifecycles (core.es5.js:11177)
at resolvePromise (zone.js:824)
at resolvePromise (zone.js:795)
at zone.js:873
at ZoneDelegate.webpackJsonp.../../../../zone.js/dist/zone.js.ZoneDelegate.invokeTask (zone.js:425)
at Object.onInvokeTask (core.es5.js:3881)
at ZoneDelegate.webpackJsonp.../../../../zone.js/dist/zone.js.ZoneDelegate.invokeTask (zone.js:424)
at Zone.webpackJsonp.../../../../zone.js/dist/zone.js.Zone.runTask (zone.js:192)
at drainMicroTaskQueue (zone.js:602)
at ZoneTask.webpackJsonp.../../../../zone.js/dist/zone.js.ZoneTask.invokeTask [as invoke] (zone.js:503)
at invokeTask (zone.js:1540)

From debugging, it reproduced only when I got [leafletLayersControl].
leaflet-control-layers.wrapper.js is trying to remove layer with currentValue = null... (line 39)

Is there any workaround or its a bug to fix?

Thanks

Using Leaflet.Path.Transform Plugin with ngx-leaflet

Hey there!

Great work you are putting into this! It's very appreciated!

I wanted to ask if somone can give me some directions on how I would be able to use the Leaflet.Path.Transform plugin together with ngx-leaflet.

I know from the readme, that I can get a reference to the L.Map instance. However, the Leaflet.Path.Transform extends the functionality for the Polyline type (Polyline_options in specific) to make it dragable and scalable. I am not sure how I would be able to extend this type provided by ngx-leaflet.

Any help is appreciated.

Kindly, Matthias

map projection: need advise

I want to use several base layers which have different projections.
So when I switch a base layer the map projection should change and the vector layer should re-get its data sending the new map projection.
Is this possible? How can I add the projection to the base layer object and is a change event emitted when the base layer is changed and will it also broadcast the projection?

Cannot find module '@asymmetrik/ngx-leaflet.module'

I have an Angular 4+ project setted up with angular cli. I installed the modules with yarn but importing '@asymmetrik/ngx-leaflet.module in my app.module is not working.

I see that the name of the module has been changed recently, maybe something is wrong there?

onEachFeature

Thank you so much for putting this out there. I was hoping you had some guidance on how to implement onEachFeature. I cannot seem to get a click event on each feature of the layer. Any advice?

Move to leaflet 1.1 and start using es6 imports?

Hi,

My understanding is that with leaflet's recent move to es6 imports (http://leafletjs.com/2017/06/27/leaflet-1.1.0.html), that we could potentially not have to include the entire leaflet library in our builds. I have confirmed that I can indeed now do :

import { Map } from 'leaflet';

But I haven't confirmed yet that if I update everything, I would get a more compact leaflet build. And obviously I then want to use this wonderful library, and my understanding is that if any lib does a :

import * as L from 'leaflet';

we won't see any of those size reductions. Thoughts?

why the picture is Not joined together

## Issue: I add the leaflet into angualr2 from the official tutorial and I change the coordinate to Melbourne.after i initiate the angular2, the map is not joined together
## Environment
Ubuntu:14.04,angular2,

screenshot from 2017-08-20 09 51 06
It is what happen?Who can tell me

ReferenceError: window is not defined

Hello.

I would like to use this module with angular universal.
However, the following error occurred.

> node dist/server.js

/Users/cse_t_kutsuna/git/study/blah-map/node_modules/leaflet/dist/leaflet-src.js:226
var requestFn = window.requestAnimationFrame || getPrefixed('RequestAnimationFrame') || timeoutDefer;
                                                                                     ^

ReferenceError: window is not defined
    at /Users/me/git/study/blah-map/node_modules/leaflet/dist/leaflet-src.js:226:86
    at version (/Users/me/git/study/blah-map/node_modules/leaflet/dist/leaflet-src.js:6:65)
    at Object.<anonymous> (/Users/me/git/study/blah-map/node_modules/leaflet/dist/leaflet-src.js:9:2)
    at Module._compile (module.js:570:32)
    at Object.Module._extensions..js (module.js:579:10)
    at Module.load (module.js:487:32)
    at tryModuleLoad (module.js:446:12)
    at Function.Module._load (module.js:438:3)
    at Module.require (module.js:497:17)
    at require (internal/module.js:20:19)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! [email protected] start: `node dist/server.js`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the [email protected] start script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     /Users/me/.npm/_logs/2017-07-25T06_32_11_130Z-debug.log

I tried using isPlatformBrowser with client only but leafletOptions parse error appears

Is there any good solution?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.