【发布时间】:2021-02-24 22:58:40
【问题描述】:
我试图在我的 Angular10 项目中使用 leaflet Awesome Markers 在我的标准传单标记中使用字体真棒图标。但是,我在尝试创建 L.AwesomeMarker 时遇到以下错误。
同时,在使用 ng serve 或在 VScode 编译期间,我没有收到任何导入错误或类似错误。 导致错误的代码:
// leaflet-map.component.ts
import * as L from "node_modules/leaflet";
import * as awesome from "node_modules/leaflet.awesome-markers";
...
export class LeafletMapComponent implements OnInit, OnDestroy, AfterViewInit{
...
createDefaultMarker(mapMarker: MapMarker): Marker{
const awesomeIcon = this.fontAwesomeIcon(mapMarker.icon, mapMarker.color);
return L.marker([mapMarker.latitude, mapMarker.longitude], {icon: awesomeIcon})
.bindPopup(this.getPopupText(mapMarker))
.bindTooltip(mapMarker.location_details.name);
}
fontAwesomeIcon(){
return L.AwesomeMarkers.icon({ //This is leaflet-map.component.ts:70
icon: 'diamond',
markerColor: 'blue'
})
}
它们肯定至少在项目中,因为它们在我的package.json 文件中的“依赖项”下列出。 Leaflet 本身已经可以工作了,只是这个插件导致了问题。
我不完全确定这里出了什么问题,所以我已经尝试了以下方法:
- 在我的项目的
index.html中直接包含leaflet 和leaflet-awesome-marker js 和css。 - 从各种不同的文件夹中导入传单和传单真棒标记
- 在我的 angular.json 文件中包含传单和传单真棒标记 js 和 css
- 使用
import * as L from "node_modules/leaflet.awesome-markers"导入很棒的标记而不导入传单
它没有改变错误,可能是因为它没有解决我在leaflet-map.copmonent.ts 打字稿中错误地导入某些内容的问题。我需要解决什么问题?
【问题讨论】:
标签: javascript angular configuration leaflet