0
我试图在互动地图上重新归一化的象征符号成正比原始比例符号调用一个函数(传单)重:象征符号比例由单张
//Step 2: Import GeoJSON data
function getData(map){
//load the data
$.ajax("data/PropRaw2001_2013.geojson", {
dataType: "json",
success: function(response){
//create an attributes array
var attributes = processData(response);
var rawAttributes = processRawData(response);
function processData(data){
//empty array to hold attributes
var attributes = [];
//properties of the first feature in the dataset
var properties = data.features[0].properties;
//push each attribute name into attributes array
for (var attribute in properties){
//only take attributes with population values
if (attribute.indexOf("Prop") > -1){
attributes.push(attribute);
};
};
//check result
console.log("these are the attributes")
console.log(attributes);
return attributes;
};
function processRawData(data){
console.log("Raw data")
//empty array to hold attributes
var rawAttributes = [];
console.log(rawAttributes)
//properties of the first feature in the dataset
var properties = data.features[0].properties;
//push each attribute name into attributes array
for (var rawAttribute in properties){
//only take attributes with population values
if (rawAttribute.indexOf("Raw") > -1){
rawAttributes.push(rawAttribute);
console.log(rawAttributes)
};
};
这里,是函数,将更新我的比例符号大小:
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)
});
};
});
};
我添加了两个按钮为div的“归”和“生”,我希望用户能够使用标准化的原始,使用以下功能之间切换:
$("#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);
//}
});
但它没有传递属性数据。看起来我无法用rawAttribute或attribute(这是规范化的)调用updatePropSymbols。谁能帮我吗?对不起,这么长的代码!