Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/79.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_Jquery - Fatal编程技术网

Javascript 如何在geojson中定位对象属性?

Javascript 如何在geojson中定位对象属性?,javascript,jquery,Javascript,Jquery,假设我们有一个geojSon文件,其结构如下: "type":"Feature", "id":"AFG", "properties":{ "name":"Afghanistan" }, "geometry":{ "type":"Polygon", "coordinates":[ [ [ 61.210817, 它有所

假设我们有一个geojSon文件,其结构如下:

     "type":"Feature",
     "id":"AFG",
     "properties":{
        "name":"Afghanistan"
     },
     "geometry":{
        "type":"Polygon",
        "coordinates":[
           [
              [
                 61.210817,
它有所有的国家,所以文件相当大。我如何瞄准一个匹配的对象,比如说“
France
”?我需要能够添加一个特殊的类到我想要的目标对象

注意: 事实上,如果我们能为一些国家添加类,这样就不会有一个对象了,那就太好了。此外,这些属性中的每一个都是
svg多边形
,因此根据名称,我们需要向该多边形添加一个类。

通过:Switch case找到它

var geojson = L.geoJson(statesData, {
    style: function(feature) {
        switch (feature.properties.name) {
            case 'Italia': return {fillColor: randomColor({hue: 'pink'})};
            case 'Russia':   return {fillColor: randomColor({hue: 'pink'})};
        }
    },
    onEachFeature: onEachFeature
}).addTo(map);
更新


实际上答案在

注释中,如果两个值的逻辑相同,您可以让其通过,
案例“Italia”:案例“Russia”:返回{fillColor:randomColor({hue:'pink'});
@RoryMcCrossan谢谢,您是对的,我也更新了答案
var obj={"type":"Feature",
     "id":"AFG",
     "properties":{"name":"Afghanistan"},
     "geometry":{"type":"Polygon","coordinates":[[[61.210817,]]]}};

if(obj.properties.name == "France")
{
//Enter the code here.
}

And Followiing is for checking "Polygon".
obj.geometry.type  //Gives "Polygon" in this case