I've installed leaflet in angular 12 using the following commands:
npm install leaflet
npm install @asymmetrik/ngx-leaflet
npm install --save-dev @types/leaflet
I included the styles: ./node_modules/leaflet/dist/leaflet.css on the angular.json file and the LeafletModule no my app.module.ts.
The map works fine, however, I'm trying to add the search input control from geocoder, for that I've included the link and script for geocoder links to my index.html, found here.
And this is my ts file:
import { Component, AfterViewInit } from '@angular/core';
import * as L from 'leaflet';
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css'],
})
export class AppComponent implements AfterViewInit {
title = 'leaf-let';
private map: any;
constructor() {}
ngAfterViewInit(): void {
this.initMap();
}
private initMap(): void {
this.map = L.map('map').setView([14.094167, -87.206667], 15);
const tiles = L.tileLayer(
'https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png',
{
maxZoom: 19,
attribution:'© <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> `
`contributors',
}
);
tiles.addTo(this.map);
//L.Control.geocoder().addTo(this.map);
}
But when I do L.Control.geocoder().addTo(this.map); it gives me the error:
property 'geocoder' does not exist on type 'typeof control'