Javascript 通过调用传单中的函数重新象征比例符号
我试图在交互式地图(传单)上将标准化比例符号重新符号化为原始比例符号 以下是更新比例符号大小的函数:Javascript 通过调用传单中的函数重新象征比例符号,javascript,leaflet,Javascript,Leaflet,我试图在交互式地图(传单)上将标准化比例符号重新符号化为原始比例符号 以下是更新比例符号大小的函数: function updatePropSymbols(map, attribute){ map.eachLayer(function(layer){ //Example 3.16 line 4 if (layer.feature && layer.feature.properties[attribute]){ //acc
function updatePropSymbols(map, attribute){
map.eachLayer(function(layer){
//Example 3.16 line 4
if (layer.feature && layer.feature.properties[attribute]){
//access feature properties
var props = layer.feature.properties;
//update each feature's radius based on new attribute values
var radius = calcPropRadius(props[attribute]);
layer.setRadius(radius);
//add city to popup content string
var popupContent = "<p><b>City:</b> " + props.City + "</p>";
//add formatted attribute to panel content string
var year = attribute.split("_")[1];
popupContent += "<p><b>Population in " + year + ":</b> " + props[attribute] + " million</p>";
//replace the layer popup
layer.bindPopup(popupContent, {
offset: new L.Point(0,-radius)
});
};
});
};
但是,它不会传递属性数据。似乎我无法使用rawtattribute或attribute调用updatePropSymbols(这是规范化的)。有人能帮我吗?抱歉这么长的代码 通过使用
attribute
和rawtattribute
作为单击处理程序函数的参数,您实际上是在创建新的局部变量(在本例中,它们是描述click
事件的jQuery),而不是原始的attribute
和rawtattribute
变量。假设您已经在其他地方定义了这些变量,您需要的是:
$("#Normalized").click(function(){
updatePropSymbols(map, attribute);
});
$("#Raw").click(function(){
updatePropSymbols(map, rawAttribute);
});
下面是一个简单的例子来说明这一点:
$("#Normalized").click(function(attribute){
console.log("normalize function")
//normalize = true
//if (normalize = true) {
updatePropSymbols(map, attribute);
//}
});
//
$("#Raw").click(function(rawAttribute){
//normalize = false
//if (normalize = false){
updatePropSymbols(map, rawAttribute);
//}
});
$("#Normalized").click(function(){
updatePropSymbols(map, attribute);
});
$("#Raw").click(function(){
updatePropSymbols(map, rawAttribute);
});