[英]Leaflet: Uncaught TypeError: L.markerClusterGroup is not a function
I am trying to add markercluster into leaflet.我正在尝试将标记簇添加到传单中。
var markers = L.markerClusterGroup();
My header file include:我的头文件包括:
script(src='https://unpkg.com/leaflet@1.0.1/dist/leaflet.js')
link(type='text/css', rel='stylesheet', href='/stylesheets/MarkerCluster.css')
link(type='text/css', rel='stylesheet', href='/stylesheets/MarkerCluster.Default.css')
script(src=/javascripts/leaflet.markercluster-src.js')
But I keep getting the error of : L.markerClusterGroup is not a function但我不断收到以下错误:L.markerClusterGroup 不是函数
I am not sure why I get that error.我不确定为什么会出现该错误。
This was a simple import mistake with angular, changing imports to the following, resolves this issue:这是 angular 的一个简单导入错误,将导入更改为以下内容,解决了此问题:
import * as L from 'leaflet';
import 'leaflet.markercluster';
// Compile & run = OK
private myClusterGroup = L.markerClusterGroup();
Tested using Angular 7, leaflet 1.6.0 and leaflet.markercluster 1.4.1使用 Angular 7、leaflet 1.6.0 和 Leaflet.markercluster 1.4.1 进行测试
我想你错过了声明中的引用
script(src='/javascripts/leaflet.markercluster-src.js')
Try试试
var markers = new L.markerClusterGroup();
instead of而不是
var markers = L.markerClusterGroup();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.