0
我想突出顯示從頁面上其他位置的代碼使用JavaScript的整個圖層組。我的羣設置如下:Leafet.js我如何使用外部代碼突出顯示整個圖層組
var annexa_building = new L.Polygon([
[68.23682, -47.46094],[68.3668, -40.07812]...
], {'label': popup_annexa, 'popup': content_annexa}).addTo(map);
var annexb_building = new L.Polygon([
[68.82387, -29.729],[69.24837, -22.41211]...
], {'label': popup_annexb, 'popup': content_annexb}).addTo(map);
var academics_group = new L.LayerGroup([
annexa_building,
annexb_building
]);
我試圖找到調用與引用的一組文件的效果,但不能。我需要的是能夠呼籲兩層的高亮度代碼的同時,這樣的:(每次調用單獨的層之一)
setHighlight(academics_group);
我也試着做這樣的事情:
<img src="images/1.png" class="img-swap" onclick="setHighlight('annexa_building')" />
這:
jQuery(function(){
$(".img-swap").on('click', function() {
if ($(this).attr("class") == "img-swap") {
this.src = this.src.replace("_off","_on");
setHighlight("annexa_building");
} else {
this.src = this.src.replace("_on","_off");
}
$(this).toggleClass("on");
});
});
但回報指layer.setStyle是不是一個函數。
函數setHighlight(layer)在地圖中確實工作正常。
function setHighlight (layer) {
if (highlight) {
unsetHighlight(highlight);
}
layer.setStyle(style.highlight);
highlight = layer;
}
對此解決方案的想法?謝謝!