简体   繁体   中英

leaflet geojson style function feature only colors 1 geojson feature

I need to style every feature differently that I pull from a geojson file. However this anonymous style function only changes the style on the first feature it comes across and stops. I am new to leaflet. Have seen several demos but cant find a reason why this anonymous style function only changes the style of the first feature and not the rest? The getTableData function returns a color from table generated on page load.

feature Example

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);

You're trying to match COUNTRY1 with country1 , that won't work. Javascript switch is casesensitive.

调用的其他函数之一出错

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM