Getting GeoJSON Data Layer Properties in Google Maps V3

When loading a geoJSON file into a Google map as a data layer, how can I access the properties of the data layer itself?

I know how to access individual properties like posts_here in the example below. What I'm looking for is the properties of the layer itself - in this example maxPosts .

 $.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')), }); }) }); 

grid.json example Download:

 { "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" } } 
+5
source share
2 answers

The API only performs analysis of features -array FeatureCollection when you want to access additional properties that you must implement yourself.

Based on this code, this is not difficult, because geoJson is available as an object through data inside $.getJSON -callback, you can simply access the property through

 data.properties.maxPosts 
+4
source

I believe that you should use getFeatureById (id: number | string) to access the information you added from your geoJSON.

0
source

Source: https://habr.com/ru/post/1210521/


All Articles