cai*_*lin 5 javascript jquery google-maps google-maps-api-3
将geoJSON文件作为数据层加载到Google Map时,如何访问数据层本身的属性?
我知道如何访问各个属性,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')),
});
})
});
Run Code Online (Sandbox Code Playgroud)
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"
}
}
Run Code Online (Sandbox Code Playgroud)
API仅解析features
FeatureCollection的-array,当您想要访问其他属性时,您必须自己实现它.
根据给定的代码,它并不复杂,因为geoJson可以通过-callback data
内部作为对象$.getJSON
访问,您可以通过
data.properties.maxPosts
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
4979 次 |
最近记录: |