【发布时间】:2015-03-04 19:51:07
【问题描述】:
将 geoJSON 文件作为数据层加载到 Google 地图中时,如何访问数据层本身的属性?
我知道如何access the individual properties,就像下面例子中的posts_here。我想要得到的是图层本身的属性——在这个例子中,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"
}
}
【问题讨论】:
标签: javascript jquery google-maps google-maps-api-3