Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/422.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 在映射框/传单中为geojson属性定义填充颜色时出现问题_Javascript_Leaflet_Frontend_Mapbox - Fatal编程技术网

Javascript 在映射框/传单中为geojson属性定义填充颜色时出现问题

Javascript 在映射框/传单中为geojson属性定义填充颜色时出现问题,javascript,leaflet,frontend,mapbox,Javascript,Leaflet,Frontend,Mapbox,我已经在Mapbox地图上加载了geojson,使用 var featureLayer = L.mapbox.featureLayer() .loadURL('gmo_counties.geojson') .addTo(map) geojson与my index.html位于同一目录中 我想根据一个名为“H_Sum_lbs”的属性来设计这个geojson中的多边形。我尝试了几种方法,但没有取得任何进展。如何根据多边形的“H_Sum_lbs”属性

我已经在Mapbox地图上加载了geojson,使用

var featureLayer = L.mapbox.featureLayer()
            .loadURL('gmo_counties.geojson') 
            .addTo(map)
geojson与my index.html位于同一目录中


我想根据一个名为“H_Sum_lbs”的属性来设计这个geojson中的多边形。我尝试了几种方法,但没有取得任何进展。如何根据多边形的“H_Sum_lbs”属性值对这些多边形应用条件着色?

您可以从
L.mapbox.featureLayer
切换到
L.GeoJSON
。它接受一个
style
函数作为一个选项,您可以在其中访问功能,以便根据功能的属性有条件地返回样式对象:

var featureCollection = {
    "type": "FeatureCollection",
    "features": [{
        "type": "Feature",
        "properties": {
            "valid": false
        },
        "geometry": {
            "type": "LineString",
            "coordinates": [[-25, -25], [25, -25]]
        }
    }, {
        "type": "Feature",
        "properties": {
            "valid": true
        },
        "geometry": {
            "type": "LineString",
            "coordinates": [[25, 25], [-25, 25]]
        }
    }]
}

L.mapbox.accessToken = yourAccessToken;
var map = L.mapbox.map('mapbox').setView([0, 0], 0);

L.geoJson(featureCollection, {
    style: function (feature) {
        return {
            color: (feature.properties.valid) ? 'green' : 'red'
        }
    }
}).addTo(map);
L.GeoJSON
参考:

L.Path
选项:

您可以从
L.mapbox.featureLayer
切换到
L.GeoJSON
。它接受一个
style
函数作为一个选项,您可以在其中访问功能,以便根据功能的属性有条件地返回样式对象:

var featureCollection = {
    "type": "FeatureCollection",
    "features": [{
        "type": "Feature",
        "properties": {
            "valid": false
        },
        "geometry": {
            "type": "LineString",
            "coordinates": [[-25, -25], [25, -25]]
        }
    }, {
        "type": "Feature",
        "properties": {
            "valid": true
        },
        "geometry": {
            "type": "LineString",
            "coordinates": [[25, 25], [-25, 25]]
        }
    }]
}

L.mapbox.accessToken = yourAccessToken;
var map = L.mapbox.map('mapbox').setView([0, 0], 0);

L.geoJson(featureCollection, {
    style: function (feature) {
        return {
            color: (feature.properties.valid) ? 'green' : 'red'
        }
    }
}).addTo(map);
L.GeoJSON
参考:

L.Path
选项: