Dan*_*lev 3 css google-maps geojson
我试图在每个多边形上设置样式,特别是填充颜色。我知道我可以这样做:
map.data.loadGeoJson('http://localhost:8080/my.json');
map.data.setStyle({
fillColor: 'red'
});
Run Code Online (Sandbox Code Playgroud)
但我想分别在多边形上设置填充颜色。我尝试在 GIS Stack 上按照这个答案进行设置,但它不起作用:
{
"type": "FeatureCollection",
"features": [
{
"type": "Feature",
"properties": {
},
"geometry": {
"type": "Polygon",
"coordinates": [
[
[
-80.4545,
43.5061
]
]
]
},
"style":{
"fill":"red",
"stroke-weight": "1",
"stroke-width":"3",
"fill-opacity":"0.6"
}
}
]
}
Run Code Online (Sandbox Code Playgroud)
我希望可以在单个多边形而不是整个数据上设置样式。
事实证明,可以使用函数来分配样式:
// Color Capital letters blue, and lower case letters red.
// Capital letters are represented in ascii by values less than 91
map.data.setStyle(function(feature) {
var ascii = feature.getProperty('ascii');
var color = ascii > 91 ? 'red' : 'blue';
return {
fillColor: color,
strokeWeight: 1
};
});
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2923 次 |
| 最近记录: |