我需要从geojson文件中拉出不同的每个功能。然而,这个匿名样式函数只会改变它遇到和停止的第一个功能的样式。我是新手册。已经看过几个演示,但无法找到一个原因,为什么这个匿名风格的功能只改变了第一个功能的风格,而不是其他的功能。 getTableData函数从页面加载时生成的表格返回颜色。传单geojson样式函数功能只有颜色1 geojson功能
功能实例
var countyData = {
"type": "FeatureCollection",
"features": [
{ "type": "Feature", "id": 0, "properties": { "ENTITYYR": 2010.0, "NAME": "COUNTY1", "FIPS": 25.0, "FIPS_STR": "49025", "COLOR4": 4 }, "geometry": { "type": "Polygon", "coordinates": [ [ Long List Of Coordinates here ] ] } }
, etc
geojson = L.geoJson(countyData, {
style: function(feature) {
switch (feature.properties.NAME) {
case 'COUNTY1': return {color: '#' + getTableData(feature.properties.NAME)};
break;
case 'COUNTY2': return {color: '#' + getTableData(feature.properties.NAME)};
break;
case 'COUNTY3': return {color: '#' + getTableData(feature.properties.NAME)};
break;
case 'COUNTY4': return {color: '#' + getTableData(feature.properties.NAME)};
break;
case 'COUNTY5': return {color: '#' + getTableData(feature.properties.NAME)};
break;
}
},
onEachFeature: onEachFeature
}).addTo(map);
这里缺少一些代码,'getTableData'方法做了什么?你能补充一点吗? “feature.properties.NAME”中包含什么?也许你可以发布一个功能的例子? – iH8
@ iH8更新后的问题 – user1015711