admin管理员组文章数量:1316376
When loading a geoJSON file into a Google Map as a data layer, how does one access the properties of the data layer itself?
I know how to access the individual properties, like posts_here
in the below example. What I'm looking to get is the properties for the layer itself- in this example, maxPosts
.
$.getJSON(".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')),
});
})
});
Example of the grid.json
I'm loading:
{
"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"
}
}
When loading a geoJSON file into a Google Map as a data layer, how does one access the properties of the data layer itself?
I know how to access the individual properties, like posts_here
in the below example. What I'm looking to get is the properties for the layer itself- in this example, maxPosts
.
$.getJSON("http://example./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')),
});
})
});
Example of the grid.json
I'm loading:
{
"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"
}
}
Share
Improve this question
edited Jan 7, 2015 at 2:47
caitlin
asked Jan 7, 2015 at 2:38
caitlincaitlin
2,8294 gold badges31 silver badges65 bronze badges
2 Answers
Reset to default 6The API does only parse the features
-array of a FeatureCollection, when you want to access additional properties you must implement it on your own.
Based on the given code it isn't plicated, because the geoJson is accessible as object via data
inside the $.getJSON
-callback, you may simply access the property via
data.properties.maxPosts
I believe you should be able to use getFeatureById(id:number|string) to access information you've added from your geoJSON.
本文标签: javascriptGetting the properties of a GeoJSON data layer in Google Maps V3Stack Overflow
版权声明:本文标题:javascript - Getting the properties of a GeoJSON data layer in Google Maps V3 - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742002562a2411310.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论