Reputation: 23
angular verison: 8
version in package.json:
"leaflet": "1.5.1",
"leaflet-draw": "1.0.4",
"leaflet-sidebar-v2": "3.0.3",
"esri-leaflet": "2.3.2",
"leaflet-control-geocoder": "1.10.0"
I have import leaflet and other like this:
import * as L from 'leaflet';
import 'leaflet-draw';
import * as esri from 'esri-leaflet';
import 'leaflet-sidebar-v2';
import 'leaflet-control-geocoder';
Now i have to use or leaflet-control-geocoder to implement this function but if i write this:
L.control.geocoder().addTo(map);
angular crash.(Property 'geocoder' does not exist on type 'typeof Control') I try also with esri-leaflet-geocoder, but it's crash too.
any solution?
Upvotes: 2
Views: 2509
Reputation: 86
I had the same problem. I fixed it by doing so
import * as L from 'leaflet';
import Geocoder from 'leaflet-control-geocoder';
...
this.map = L.map('map', {
center: [staticLatLng.lat, staticLatLng.lng],
zoom: zoomLevel
});
const GeocoderControl = new Geocoder();
GeocoderControl.addTo(this.map);
GeocoderControl.on('markgeocode', function (e) {
console.log(e);
});
...
Upvotes: 3
Reputation: 1
I had the same problem. I added the geocoder inside L.Routing.control, and it works! (actually, VS Code still says Property 'Geocoder' does not exist on type 'typeof Control'
) but it works!:
L.Routing.control({
waypoints: [L.latLng(57.74, 11.94), L.latLng(57.6792, 11.949)],
showAlternatives: true,
geocoder: L.Control.Geocoder.nominatim()
}).addTo(this.map);
I'm working with Angular 8, leaftlet-routing-machine plugin.
Upvotes: 0
Reputation: 11348
Pls try with uppercase "C" L.Control.geocoder().addTo(map)
or (but that should have the same effect)
var geocoder = new L.Control.geocoder();
map.addControl(geocoder);
Upvotes: 0