2015-09-04 122 views
0

我需要从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); 
+0

这里缺少一些代码,'getTableData'方法做了什么?你能补充一点吗? “feature.properties.NAME”中包含什么?也许你可以发布一个功能的例子? – iH8

+0

@ iH8更新后的问题 – user1015711

回答

0

你试图匹配COUNTRY1country1,这是行不通的。 Javascript切换是区分大小写的。

+0

无错我需要保持我的贴子匿名,所以当更改这些名称为通用信息我没有维护命名约定 – user1015711