gpt4 book ai didi

javascript - 不止一张 "oneachfeature"传单

转载 作者:行者123 更新时间:2023-11-29 22:05:49 25 4
gpt4 key购买 nike

我正在尝试将两个功能组合到一个图层上,但无法同时使用它们。一个是突出显示光标悬停的区域,另一个是在弹出窗口中获取信息。我使用本指南来突出显示:http://leafletjs.com/examples/choropleth.html (添加交互部分,试图将其合并到工作信息弹出层)。此外,目前它在悬停时突出显示,但如果它在单击时突出显示会很好。代码:

    function style(feature) {
return {
fillColor: 'blue',
weight: 2,
opacity: 1,
color: 'grey',
dashArray: '3',
fillOpacity: 0.7
};
}

L.geoJson(piirid, {style: style});

function highlightFeature(e) {
var layer = e.target;

layer.setStyle({
weight: 5,
color: '#666',
dashArray: '',
fillOpacity: 0.7
});

if (!L.Browser.ie && !L.Browser.opera) {
layer.bringToFront();
}
}

function resetHighlight(e) {
geojson.resetStyle(e.target);
}

var geojson;
// ... our listeners
geojson = L.geoJson(piirid);

function zoomToFeature(e) {
map.fitBounds(e.target.getBounds());
}

function onEachFeature3(feature, layer) {
layer.on({
mouseover: highlightFeature,
mouseout: resetHighlight,
//click: zoomToFeature
});
}

geojson = L.geoJson(piirid, {
style: style,
onEachFeature: onEachFeature,
onEachFeature: onEachFeature3
});

function onEachFeature(feature, layer) {
if (feature.properties) {
layer.bindPopup("<br><b><big><u>Aadresss: " + feature.properties.L_AADRESS + "</br></b></big></u><br> <b>Maakond:&nbsp;</b>" + feature.properties.MK_NIMI
+ " <br><br>", {"offset": [200, -50]});
}

}

谢谢,克里斯蒂安

最佳答案

将两个函数结合起来,它们使用相同的参数还不如作为一个函数来完成。

 function style(feature) {
return {
fillColor: 'blue',
weight: 2,
opacity: 1,
color: 'grey',
dashArray: '3',
fillOpacity: 0.7
};
}

L.geoJson(piirid, {style: style});

function highlightFeature(e) {
var layer = e.target;

layer.setStyle({
weight: 5,
color: '#666',
dashArray: '',
fillOpacity: 0.7
});

if (!L.Browser.ie && !L.Browser.opera) {
layer.bringToFront();
}
}

function resetHighlight(e) {
geojson.resetStyle(e.target);
}

var geojson;
// ... our listeners
geojson = L.geoJson(piirid);

function zoomToFeature(e) {
map.fitBounds(e.target.getBounds());
}

function onEachFeature3(feature, layer) {
layer.on({
mouseover: highlightFeature,
mouseout: resetHighlight,
//click: zoomToFeature
});
if (feature.properties) {
layer.bindPopup("<br><b><big><u>Aadresss: " + feature.properties.L_AADRESS + "</br></b></big></u><br> <b>Maakond:&nbsp;</b>" + feature.properties.MK_NIMI
+ " <br><br>", {"offset": [200, -50]});
}
}

geojson = L.geoJson(piirid, {
style: style,
onEachFeature: onEachFeature3
});

关于javascript - 不止一张 "oneachfeature"传单,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21039243/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com