import * as L from 'leaflet';
import * as LM from 'leaflet.markercluster';
import 'leaflet-draw';
import 'leaflet-control-geocoder/dist/Control.Geocoder.js';
declare var AMap: any;
<div #mapsearchmap id="mapsearchcontainer" [ngClass]="{ draw: isdrawing }" style="z-index:0">
// 离线搜索
markers1 = [];
//离线地图初始化后调用地图:
autoLHandle() {
var that = this;
var myIcon = L.icon({
iconUrl: 'static/water/assets/img/map/marker-icon-2x.png',
iconSize: [24, 32]
});
L.Control.geocoder({
defaultMarkGeocode: false,
})
.on('markgeocode', function (e) {
if (that.markers1?.length) {
that.markers1.forEach(it => {
that.map.removeLayer(it);
});
that.markers1 = [];
}
var latlng = e.geocode.center;
var marker = L.marker(latlng, { icon: myIcon }).addTo(that.map);
that.map.fitBounds(e.geocode.bbox);
that.markers1.push(marker);
})
.addTo(that.map);
}