我刚开始了解我即将开展的项目的Leaflet.js。Leaflet通过外部元素在集群标记上触发事件
什么,我试图完成: 我需要它显示在地图上标记的列表,并在列表项正在徘徊(或鼠标悬停)它会显示在那里的位置地图(为单标记,应该改变其颜色。对于集群标记,它应该显示覆盖率线就像当我们再次在它是如何工作..也许改变它的颜色太多,如果可能的话) 。 不应该改变地图以及缩放级别,简单地说,我需要突出显示地图上的标记/聚类。
我超级沮丧:我没能找到一个方法来做到这一点上集群标记。
我使用全局变量对象来存储任何创建的标记。
function updateMapMarkerResult(data) {
markers.clearLayers();
for (var i = 0; i < data.length; i++) {
var a = data[i];
var myIcon = L.divIcon({
className: 'prop-div-icon',
html: a.Description
});
var marker = L.marker(new L.LatLng(a.Latitude, a.Longitude), {
icon: myIcon
}, {
title: a.Name
});
marker.bindPopup('<div><div class="row"><h5>Name : ' + a.Name + '</h5></div><div class="row">Lat : ' + a.Latitude + '</div><div class="row">Lng : ' + a.Longitude + '</div>' + '</div>');
marker.on('mouseover', function(e) {
if (this._icon != null) {
this._icon.classList.remove("prop-div-icon");
this._icon.classList.add("prop-div-icon-shadow");
}
});
marker.on('mouseout', function(e) {
if (this._icon != null) {
this._icon.classList.remove("prop-div-icon-shadow");
this._icon.classList.add("prop-div-icon");
}
});
markersRef[a.LocId] = marker; // <-- Store Reference
markers.addLayer(marker);
updateMapListResult(a, i + 1);
}
map.addLayer(markers);
}
但我不知道哪个对象或属性获取聚集标记引用。 而我通过我的全局变量(仅适用于单个标记)触发标记事件。
...
li.addEventListener("mouseover", function(e) {
jQuery(this).addClass("btn-info");
markersRef[this.getAttribute('marker')].fire('mouseover'); // --> Trigger Marker Event "mouseover"
// TODO : Trigger ClusteredMarker Event "mouseover"
});
...
这是我目前的https://jsfiddle.net/oryza_anggara/2gze75L6/,任何潜在客户都可以得到很大的帮助。谢谢。
注:只有JS LIB我熟悉是JQuery的,我有其他如Angular.js
它的作品!绝对是我在找什么。而Spiderfy的功能真的很棒!会考虑使用它,需要考虑更多的标记。但你真的已经钉上了它,甚至更多..谢谢,你只需保存我头痛的一周。 – OAN