错误TypeError:无法读取未定义的属性“basemapLayer”
我已经建立了一个非常基本的应用程序使用角CLI。当我使用ng serve -o构建和运行应用程序时,一切都成功地构建了。但是,当我在Chrome中查看应用程序时,map部分不会加载。进一步检查页面,我在控制台中看到了这个错误。
ERROR TypeError: Cannot read property 'basemapLayer' of undefined
设置
重现错误的步骤:
这些步骤假设您已经安装了角CLI。
步骤1-6和10是在终端/cmd提示窗口中完成的。
ng new esriLeafletAppcd esriLeafletAppnpm install --save leafletnpm install --save esri-leafletnpm install --save @types/esri-leafletnpm install --save @types/leaflet
import { Component, OnInit } from '@angular/core';
import * as L from 'leaflet';
import 'esri-leaflet';
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css']
})
export class AppComponent implements OnInit {
title = 'app';
constructor() { }
ngOnInit () {
const map = L.map('map').setView([51.505, -0.09], 13);
L.esri.basemapLayer('Streets').addTo(map);
}
}
<div style="text-align:center">
<h1>
Welcome to {{title}}!
</h1>
</div>
<div id="map"></div>
ng serve -o请帮帮忙
有谁知道为什么esri在代码块L.esri.basemapLayer('Streets').addTo(map);中是undefined,以及我如何修复它?
发布于 2017-09-19 18:20:19
问题似乎在于埃斯里-传单(@types/esri-传单)的类型文件,而不是esri-传单本身。我已经在问题 github上打开了一个DefinitelyTyped。
解决办法:
import * as esri from 'esri-leaflet';
import { Component, OnInit } from '@angular/core';
import * as L from 'leaflet';
import * as esri from 'esri-leaflet';
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css']
})
export class AppComponent implements OnInit {
title = 'app';
constructor() { }
ngOnInit () {
const map = L.map('map', {
maxZoom: 18,
minZoom: 0
}).setView([51.505, -0.09], 15);
const esriLayer = esri.basemapLayer('Imagery');
map.addLayer(esriLayer);
}
}
https://stackoverflow.com/questions/46304492
复制相似问题