如何安装离子2的Leaflet插件 [英] How to Install Leaflet plugin for ionic 2
问题描述
任何人都可以帮忙吗?我正在尝试导入传单插件( https://github.com/Leaflet/Leaflet.markercluster)for ionic 2
Anyone can help this? I am trying to import a leaflet plugin (https://github.com/Leaflet/Leaflet.markercluster) for ionic 2
这是我做的一步:
npm install leaflet.markercluster --save
我添加了这样的传单:
从'传单'导入*为L;从'leaflet.markercluster'导入*作为LL;
并像这样使用它:
var markers = LL.markerClusterGroup();
我收到错误TypeError:
i got an error TypeError:
WEBPACK_IMPORTED_MODULE_2_leaflet_markercluster.markerClusterGroup是
不是函数
WEBPACK_IMPORTED_MODULE_2_leaflet_markercluster.markerClusterGroup is not a function
有没有办法自定义webpack加载插件库?谢谢
Are there any ways to custom webpack to load plugin lib? Thanks
推荐答案
Leaflet.markercluster插件不会以标准/ UMD方式导出自己。
Leaflet.markercluster plugin does not export itself the "standard" / UMD way.
导入时,它只执行副作用,即它将自身附加到 L
(Leaflet)全局命名空间。它不会将任何内容返回到您的默认导入,也不会返回 LL
变量。
When you import it, it only performs a side effect, i.e. it attaches itself to the L
(Leaflet) global namespace. It does not return anything into your default import nor LL
variable.
但您应该可以将其用作如果你把它包括在旧学校的方式(即通过< script>
标签):
But you should be able to use it as if you had included it the "old school" way (i.e. through a <script>
tag):
var mcg = L.markerClusterGroup();
BTW,Leaflet和Leaflet.markercluster都会执行副作用,所以你只需要将它们导入方式:
BTW, both Leaflet and Leaflet.markercluster perform side effects, so you would just need to import them this way:
import 'leaflet'; // Creates a global L namespace.
import 'leaflet.markercluster'; // Attaches L.markerClusterGroup to global L.
这篇关于如何安装离子2的Leaflet插件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!