Javascript 在Google Maps V3中获取GeoJSON数据层的属性
将geoJSON文件作为数据层加载到Google地图时,如何访问数据层本身的属性 我知道如何在下面的示例中发布。我希望得到的是图层本身的属性——在本例中,Javascript 在Google Maps V3中获取GeoJSON数据层的属性,javascript,jquery,google-maps,google-maps-api-3,Javascript,Jquery,Google Maps,Google Maps Api 3,将geoJSON文件作为数据层加载到Google地图时,如何访问数据层本身的属性 我知道如何在下面的示例中发布。我希望得到的是图层本身的属性——在本例中,maxPosts $.getJSON("http://example.com/posts/grid.json" + location.search, function (data) { grid = map_canvas.data.addGeoJson(data); map_canvas.data.setStyl
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
示例:
{
"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"
}
}
我相信您应该能够使用访问您从geoJSON添加的信息。API只解析FeatureCollection的
功能
-数组,当您想要访问其他属性时,您必须自己实现它
基于给定的代码,它并不复杂,因为geoJson可以通过$内的数据
作为对象访问。getJSON
-回调,您可以通过
data.properties.maxPosts
你明白了。给self的教训:console.log()所有内容。