2015-01-07 4 views
5

geoJSONファイルをGoogleマップにデータレイヤとして読み込むとき、データレイヤ自体のプロパティにどのようにアクセスしますか?GoogleマップV3のGeoJSONデータレイヤのプロパティの取得

私は、以下の例のposts_hereのように、access the individual propertiesの方法を知っています。取得しようとしているのは、レイヤー自体のプロパティです。この例では、maxPostsです。 grid.json私はロードてるの

$.getJSON("http://example.com/posts/grid.json" + location.search, function (data) { 
     grid = map_canvas.data.addGeoJson(data); 
     map_canvas.data.setStyle(function(feature) { 
     return /** @type {google.maps.Data.StyleOptions} */({ 
      strokeWeight: Math.log(feature.getProperty('posts_here')), 
     }); 
    }) 
}); 

例:

{ 
    "type": "FeatureCollection", 
    "features": [ 
     { 
      "type": "Feature", 
      "geometry": { 
       "type": "Polygon", 
       "coordinates": [ 
        [ 
         [-58,-35], 
         [-58,-34], 
         [-57,-34], 
         [-57,-35], 
         [-58,-35] 
        ] 
       ] 
      }, 
      "properties": { 
       "posts_here": "177" 
      } 
     } 
    ], 
    "properties": { 
     "maxPosts": "177" 
    } 
} 

答えて

4

APIは、FeatureCollectionのfeatures配列を解析するだけです。追加のプロパティにアクセスするには、独自に実装する必要があります。

にGeoJSONは$.getJSON -callback内dataを経由してオブジェクトとしてアクセス可能であるので、それは、複雑ではありません与えられたコードに基づいて、あなたは単にあなたがそれを持っている

data.properties.maxPosts 
+0

を経由してプロパティにアクセスすることができます。自己への教訓:console.log()EVERYTHING。 – schnauss

0

は、私はあなたがあなたにGeoJSONから追加した情報にアクセスするためにgetFeatureById(id:number|string)を使用することができるはずと信じています。

関連する問題