我在我的打字稿类中遇到以下错误,无法理解原因。我正在做的就是尝试调用一个传递令牌的辅助函数。
错误:发布错误:map.downloadExport不是函数
这是我的代码
example.com
这是我的JS文件
import {Component, ViewEncapsulation} from '@angular/core';
import {MapService} from "../../../shared/leaflet/map.service";
import {GeocodingService} from "../../../shared/leaflet/geocoding.service";
import "leaflet-easybutton";
var leafletImage = require("leaflet-image/leaflet-image")
declare var downloadExport: any;
// import '../../../../leaflet_export.js';
@Component({
encapsulation: ViewEncapsulation.None,
selector: 'Home',
templateUrl: './app/components/tools/sketch/sketch.component.html',
styleUrls: [ './app/components/tools/sketch/sketch.component.css' ],
providers: [MapService, GeocodingService]
})
export class SketchComponent {
public vtLayer:any;
constructor(private mapService: MapService, private geocoder: GeocodingService) {}
ngOnInit(): void {
console.log('tools component');
}
ngAfterViewInit() {
let map = L.map("map", {
zoomControl: false,
center: L.latLng(4.418294, 108.224145),
zoom: 6,
minZoom: 4,
maxZoom:22,
layers: [this.mapService.baseMaps.OpenStreetMap]
}).setView([3.1466, 101.6958], 6);
L.control.zoom({ position: "topright" }).addTo(map);
L.control.scale().addTo(map);
var customControl = L.Control.extend({
options: {
position: 'bottomright'
},
map.addControl(new customControl());
this.mapService.map = map;
this.geocoder.getCurrentLocation()
.subscribe(
location => map.panTo([location.latitude, location.longitude]),
err => console.error(err)
);
toolbar
var drawnItems = L.featureGroup();
map.addLayer(drawnItems);
var drawControl = new L.Control.Draw(options);
map.addControl(drawControl);
map.on(L.Draw.Event.CREATED, function(e:any) {
var layer = e.layer;
drawnItems.addLayer(layer);
});
function afterRender(result:any) {
return result;
}
function afterExport(result:any) {
return result;
}
function downloadMap(caption:any) {
var downloadOptions = {
caption: {
text: caption,
font: '30px Arial',
fillStyle: 'black',
position: [100,200]
},
exclude: ['.leaflet-control-zoom', '.leaflet-control-attribution'],
format: 'image/jpeg',
fileName: 'Map.jpg',
afterRender: afterRender,
afterExport: afterExport
};
var promise = map.downloadExport(downloadOptions);
var data = promise.then(function(result:any){
return result;
});
console.log(data)
}
}
}