将 BeautifyMarker 插件添加到 ngx-leaflet 项目中
Add BeautifyMarker plugin to ngx-leaflet project
我目前无法将 BeautifyMarker 插件与 ngx-leaflet
Angular 2 包集成。
我已经关注了 install instructions for BeautifyMarker alongside the ngx-leaflet plugin instructions,但没有成功。
我使用 npm install
获取 BeautifyMarker、Font Awesome,并且已经安装了 Bootstrap。 Leaflet 也已根据 ngx-leaflet
官方教程正确添加和配置。
我编辑了 angular-cli.json
文件以包含 BeautyMarker .css 和 .js 文件,如下所示:
"styles": [
"styles.css",
"../node_modules/leaflet/dist/leaflet.css",
"../node_modules/font-awesome/css/font-awesome.css",
"../node_modules/bootstrap/dist/css/bootstrap.css",
"../node_modules/beautifymarker/leaflet-beautify-marker-icon.css"
],
"scripts": [
"../node_modules/leaflet/dist/leaflet.js",
"../node_modules/beautifymarker/leaflet-beautify-marker-icon.js",
], ...
我还完全导入了包,因为它扩展了 L
,像这样:
import * as L from 'leaflet';
import 'beautifymarker';
那不行,所以我也试了:
import * as L from 'leaflet';
import '../../node_modules/beautifymarker/leaflet-beautify-marker-icon.js';
还尝试完全省略导入,就像 heatmap.js
插件一样。 None 个允许我访问 L.BeautifyIcon
。
有什么建议吗?
我花了一些时间来调查您的问题。
我所做的是:
- 已安装传单,@asymmetrik/ngx-leaflet & @types/leaflet
- 已安装 bootstrap、font-awesome、beautifymarker 并将它们添加到 angular.json
- 重新启动服务器,因为观察者仅针对 src 文件夹,angular-cli.json 未观察到渲染 font-awesome
的更改
angular.json
"styles": [
"node_modules/leaflet/dist/leaflet.css",
"node_modules/bootstrap/dist/css/bootstrap.css",
"node_modules/font-awesome/css/font-awesome.css",
"node_modules/beautifymarker/leaflet-beautify-marker-icon.css",
"src/styles.css"
],
"scripts": [
"node_modules/leaflet/dist/leaflet.js",
"node_modules/beautifymarker/leaflet-beautify-marker-icon.js"
]
app.module.ts
import { LeafletModule } from '@asymmetrik/ngx-leaflet';
..
imports: [
..,
LeafletModule.forRoot()
],
app.component.ts
// import * as L from 'leaflet';
// import 'beautifymarker';
// instead of the above try
import 'leaflet';
import 'beautifymarker';
declare let L;
options = {
layers: [
L.tileLayer('http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
maxZoom: 18, attribution: '...' }
)
],
zoom: 12,
center: L.latLng(46.879966, -121.726909)
};
beautifyOptions = {
icon: 'plane',
borderColor: '#8D208B',
textColor: '#8D208B',
backgroundColor: 'transparent'
};
layers = [
L.marker([ 46.879966, -121.726909 ], {
icon: L.BeautifyIcon.icon(this.beautifyOptions)
})
];
模板
<div style="height: 500px;"
leaflet
[leafletOptions]="options"
[leafletLayers]="layers">
</div>
我目前无法将 BeautifyMarker 插件与 ngx-leaflet
Angular 2 包集成。
我已经关注了 install instructions for BeautifyMarker alongside the ngx-leaflet plugin instructions,但没有成功。
我使用 npm install
获取 BeautifyMarker、Font Awesome,并且已经安装了 Bootstrap。 Leaflet 也已根据 ngx-leaflet
官方教程正确添加和配置。
我编辑了 angular-cli.json
文件以包含 BeautyMarker .css 和 .js 文件,如下所示:
"styles": [
"styles.css",
"../node_modules/leaflet/dist/leaflet.css",
"../node_modules/font-awesome/css/font-awesome.css",
"../node_modules/bootstrap/dist/css/bootstrap.css",
"../node_modules/beautifymarker/leaflet-beautify-marker-icon.css"
],
"scripts": [
"../node_modules/leaflet/dist/leaflet.js",
"../node_modules/beautifymarker/leaflet-beautify-marker-icon.js",
], ...
我还完全导入了包,因为它扩展了 L
,像这样:
import * as L from 'leaflet';
import 'beautifymarker';
那不行,所以我也试了:
import * as L from 'leaflet';
import '../../node_modules/beautifymarker/leaflet-beautify-marker-icon.js';
还尝试完全省略导入,就像 heatmap.js
插件一样。 None 个允许我访问 L.BeautifyIcon
。
有什么建议吗?
我花了一些时间来调查您的问题。
我所做的是:
- 已安装传单,@asymmetrik/ngx-leaflet & @types/leaflet
- 已安装 bootstrap、font-awesome、beautifymarker 并将它们添加到 angular.json
- 重新启动服务器,因为观察者仅针对 src 文件夹,angular-cli.json 未观察到渲染 font-awesome 的更改
angular.json
"styles": [
"node_modules/leaflet/dist/leaflet.css",
"node_modules/bootstrap/dist/css/bootstrap.css",
"node_modules/font-awesome/css/font-awesome.css",
"node_modules/beautifymarker/leaflet-beautify-marker-icon.css",
"src/styles.css"
],
"scripts": [
"node_modules/leaflet/dist/leaflet.js",
"node_modules/beautifymarker/leaflet-beautify-marker-icon.js"
]
app.module.ts
import { LeafletModule } from '@asymmetrik/ngx-leaflet';
..
imports: [
..,
LeafletModule.forRoot()
],
app.component.ts
// import * as L from 'leaflet';
// import 'beautifymarker';
// instead of the above try
import 'leaflet';
import 'beautifymarker';
declare let L;
options = {
layers: [
L.tileLayer('http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
maxZoom: 18, attribution: '...' }
)
],
zoom: 12,
center: L.latLng(46.879966, -121.726909)
};
beautifyOptions = {
icon: 'plane',
borderColor: '#8D208B',
textColor: '#8D208B',
backgroundColor: 'transparent'
};
layers = [
L.marker([ 46.879966, -121.726909 ], {
icon: L.BeautifyIcon.icon(this.beautifyOptions)
})
];
模板
<div style="height: 500px;"
leaflet
[leafletOptions]="options"
[leafletLayers]="layers">
</div>