首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >将BeautifyMarker插件添加到ngx-传单项目中

将BeautifyMarker插件添加到ngx-传单项目中
EN

Stack Overflow用户
提问于 2018-08-03 19:32:41
回答 1查看 1.5K关注 0票数 4

我目前无法集成BeautifyMarker插件与ngx-leaflet角2软件包。

我一直跟随着BeautifyMarker安装说明ngx-传单插件说明一起走,没有运气。

我用npm install来抓取BeautifyMarker,字体太棒了,并且已经安装了引导带。根据ngx-leaflet官方教程,传单也已被适当添加和配置。

我编辑了我的angular-cli.json文件以包含BeautyMarker .css和.js文件,如下所示:

代码语言:javascript
复制
"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,如下所示:

代码语言:javascript
复制
import * as L from 'leaflet';
import 'beautifymarker';

那不管用,所以我也试了一下:

代码语言:javascript
复制
import * as L from 'leaflet';
import '../../node_modules/beautifymarker/leaflet-beautify-marker-icon.js';

还试着完全省略导入,一个la的heatmap.js插件。所有这些都不允许我访问L.BeautifyIcon

有小费吗?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2018-08-06 08:51:41

我花了些时间调查你的问题。

我所做的是:

  1. 已安装的单张,@asymmetrik/ngx-单张及@类型/单张
  2. 安装了引导程序,字体-令人敬畏,漂亮标记&将它们添加到angular.json中
  3. 重新启动服务器,因为监视程序只用于src文件夹,对于呈现字体的更改,没有观察到角-cli.json。

angular.json

代码语言:javascript
复制
"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

代码语言:javascript
复制
import { LeafletModule } from '@asymmetrik/ngx-leaflet';
..
imports: [
   ..,
   LeafletModule.forRoot()
],

app.component.ts

代码语言:javascript
复制
// 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)
    })
];

模板

代码语言:javascript
复制
<div style="height: 500px;"
    leaflet 
    [leafletOptions]="options"
    [leafletLayers]="layers">
</div>

演示

票数 5
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/51679056

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档