传单标记组 [英] leaflet markerclusterGroup

查看:102
本文介绍了传单标记组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想创建传单标记簇组,并想添加我写了下面提到的代码的所有标记.但是我收到错误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.jsleaflet.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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆