传单标记组 [英] leaflet markerclusterGroup
问题描述
我想创建传单标记簇组,并想添加我写了下面提到的代码的所有标记.但是我收到错误TypeError: L.markerClusterGroup is not a constructor
I want to create leaflet marker cluster group and want to add the all markers for that I have written below-mentioned code. But I am getting the error TypeError: L.markerClusterGroup is not a constructor
我没有发现脚本或我编写的代码有错误
I am not getting that there is an error in the scripting or in the code that I have written
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/leaflet/0.7.7/leaflet.css">
<script src="https://cdnjs.cloudflare.com/ajax/libs/leaflet/0.7.7/leaflet.js"></script>
<link rel="stylesheet" href="https://unpkg.com/leaflet.markercluster@1.0.3/dist/MarkerCluster.css">
<script src="https://unpkg.com/leaflet.markercluster@1.3.0/dist/leaflet.markercluster.js"></script>
<script src='https://unpkg.com/leaflet.markercluster@1.3.0/dist/leaflet.markercluster-src.js'></script>
var markers = L.markerClusterGroup();
markers.addLayer(L.marker(getRandomLatLng(map)));
map.addLayer(markers);
推荐答案
您无需同时包含leaflet.markercluster.js
和leaflet.markercluster-src.js
;您只需要其中之一.
You do not need to include both leaflet.markercluster.js
and leaflet.markercluster-src.js
; you just need one of them.
在HTML的head
部分中,包括以下内容:
In the head
section of your HTML, include the following:
<head>
<link rel="stylesheet" href="https://unpkg.com/leaflet@1.3.1/dist/leaflet.css" integrity="sha512-Rksm5RenBEKSKFjgI3a41vrjkw4EVPlJ3+OiI65vTjIdo9brlAacEuKOiQ5OFh7cOI1bkDwLqdLw3Zg0cRJAAQ==" crossorigin="" />
<link rel="stylesheet" href="https://unpkg.com/leaflet.markercluster@1.3.0/dist/MarkerCluster.css" />
<link rel="stylesheet" href="https://unpkg.com/leaflet.markercluster@1.3.0/dist/MarkerCluster.Default.css" />
<script src="https://unpkg.com/leaflet@1.3.1/dist/leaflet.js" integrity="sha512-/Nsx9X4HebavoBvEBuyp3I7od5tA0UzAxs+j83KgC8PU0kgB4XiK4Lfe4y4cgBtaRJQEIFCW+oC506aPT2L1zw==" crossorigin=""></script>
<script src="https://unpkg.com/leaflet.markercluster@1.3.0/dist/leaflet.markercluster.js"></script>
</head>
然后,在您的JavaScript中,创建标记集群组:
Then, in your JavaScript, create a marker cluster group:
var markers = L.markerClusterGroup();
创建一些标记:
var marker = L.marker(new L.LatLng(0, 0));
将标记添加到群集组:
markers.addLayer(marker);
最后将集群组添加到地图:
and finally add the cluster group to the map:
map.addLayer(markers);
看看此JSBin ,以查看工作示例.
Take a look at this JSBin to see a working example.
这篇关于传单标记组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!