简体   繁体   English

传单:未捕获的类型错误:L.markerClusterGroup 不是函数

[英]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.

相关问题 小册子:未被捕获的TypeError:尝试使用群集插件时L.markerClusterGroup不是函数 - Leaflet: Uncaught TypeError: L.markerClusterGroup is not a function when trying to use Cluster plug-in 未捕获的类型错误:L.minichart 不是 function(传单饼图) - Uncaught TypeError: L.minichart is not a function (Leaflet Piechart) 未捕获的类型错误:L.GeometryField 不是构造函数 django-leaflet - Uncaught TypeError: L.GeometryField is not a constructor django-leaflet React-Leaflet:未捕获的TypeError:pointToLayer不是一个函数 - React-Leaflet: Uncaught TypeError: pointToLayer is not a function 传单:未捕获的TypeError:map._getNewTopLeftPoint不是函数 - Leaflet: Uncaught TypeError: map._getNewTopLeftPoint is not a function 传单未捕获的类型错误:map.addLayer 不是函数 - leaflet Uncaught TypeError: map.addLayer is not a function 如何使用传单markerclusterGroup? - How to use leaflet markerclusterGroup? 未捕获的TypeError:events.forEach不是功能Leaflet和VueJS - Uncaught TypeError: events.forEach is not a function Leaflet and VueJS leaflet markercluster 错误:未捕获类型错误:this.callInitHooks 不是 function - leaflet markercluster error: Uncaught TypeError: this.callInitHooks is not a function Leaflet:TypeError:L.Shapefile不是构造函数 - Leaflet : TypeError: L.Shapefile is not a constructor
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM