Javascript 动态选择传单中GeoJSON对象的属性
我正试图以友好的方式更改我在传单地图上显示的属性。这是我的密码:Javascript 动态选择传单中GeoJSON对象的属性,javascript,html,leaflet,mapping,Javascript,Html,Leaflet,Mapping,我正试图以友好的方式更改我在传单地图上显示的属性。这是我的密码: $("#button_thermal").click(function(){ $.getJSON("physicalProperties.geojson", function(data) { var geojson2 = L.geoJson(data, { style: { color: 'black', fill: true , opacity: 0.1, fillOpacity:1}, onEa
$("#button_thermal").click(function(){
$.getJSON("physicalProperties.geojson", function(data) {
var geojson2 = L.geoJson(data, {
style: { color: 'black', fill: true , opacity: 0.1, fillOpacity:1},
onEachFeature: function (feature,layer){
if (layer.feature.properties.Thermal_Admittance <= 528){
layer.setStyle({fillColor :'#edf8fb'})
}
else if (layer.feature.properties.Thermal_Admittance <= 866){
layer.setStyle({fillColor :'#bfd3e6'})
}
else if (layer.feature.properties.Thermal_Admittance <= 1205){
layer.setStyle({fillColor :'#9ebcda'})
}
else if (layer.feature.properties.Thermal_Admittance <= 1543){
layer.setStyle({fillColor :'#8c96c6'})
}
else if (layer.feature.properties.Thermal_Admittance <= 1881){
layer.setStyle({fillColor :'#8c6bb1'})
}
else if (layer.feature.properties.Thermal_Admittance <= 2200){
layer.setStyle({fillColor :'#88419d'})
}
else if (layer.feature.properties.Thermal_Admittance <= 2500){
layer.setStyle({fillColor :'#6e016b'})
}
}
});
geojson2.addTo(map)
$("#button_clear").click(function(){map.removeLayer(geojson2)})
});
});
$(“#按钮_热”)。单击(函数(){
$.getJSON(“physicalProperties.geojson”,函数(数据){
var geojson2=L.geoJson(数据,{
样式:{color:'black',fill:true,不透明度:0.1,fillOpacity:1},
onEachFeature:功能(功能,图层){
if(layer.feature.properties.Thermal_-conductance欢迎使用SO
对于您的案例,您有两种可能的解决方案:
- 制作一个函数生成器
- 绑定函数
第一种解决方案只是创建一个返回另一个函数的函数,从构建函数时起,将属性保留在范围内:
函数buildOnEachFeatureFn(prop){
返回函数(特征、图层){
if(feature.properties[prop]欢迎来到SO
对于您的案例,您有两种可能的解决方案:
- 制作一个函数生成器
- 绑定函数
第一种解决方案只是创建一个返回另一个函数的函数,从构建函数时起,将属性保留在范围内:
函数buildOnEachFeatureFn(prop){
返回函数(特征、图层){
如果(功能属性[prop]