无法解决如何设置某些Google Map元素的样式

欧文·戴维(Owen Davey)

我正在尝试设计Google Map的样式,但我已经快到想要的地方了,但是我在一些元素上遇到了一些问题。

您可以在屏幕抓图中看到,有些元素仍然是较浅的颜色,我想将其设为深色,但是我无法弄清楚应该更改的JSON内容。

JSFiddle在这里:https ://jsfiddle.net/ojdavey/84ewc0jx/20/

JSON样式:

[{"featureType":"all","elementType":"labels.text.fill","stylers":[{"saturation":36},{"color":"#707070"},{"lightness":40}]},{"featureType":"all","elementType":"labels.text.stroke","stylers":[{"visibility":"on"},{"color":"#000000"},{"lightness":16}]},{"featureType":"all","elementType":"labels.icon","stylers":[{"visibility":"off"}]},{"featureType":"administrative","elementType":"all","stylers":[{"gamma":"0.82"},{"visibility":"off"}]},{"featureType":"administrative","elementType":"geometry.fill","stylers":[{"lightness":"7"},{"visibility":"on"}]},{"featureType":"administrative","elementType":"geometry.stroke","stylers":[{"color":"#000000"},{"lightness":17},{"weight":1.2}]},{"featureType":"administrative","elementType":"labels.text","stylers":[{"visibility":"off"}]},{"featureType":"landscape","elementType":"geometry","stylers":[{"color":"#2f2f2f"}]},{"featureType":"poi","elementType":"geometry","stylers":[{"color":"#000000"},{"lightness":21}]},{"featureType":"poi","elementType":"labels","stylers":[{"visibility":"on"}]},{"featureType":"poi","elementType":"labels.icon","stylers":[{"visibility":"off"}]},{"featureType":"road","elementType":"geometry","stylers":[{"lightness":"-100"}]},{"featureType":"road","elementType":"labels.text.fill","stylers":[{"gamma":"0.77"}]},{"featureType":"road","elementType":"labels.text.stroke","stylers":[{"lightness":"-100"},{"color":"#181818"}]},{"featureType":"road.highway","elementType":"geometry.fill","stylers":[{"lightness":"-100"},{"color":"#181818"},{"visibility":"on"}]},{"featureType":"road.highway","elementType":"geometry.stroke","stylers":[{"lightness":29},{"weight":0.2},{"color":"#ff0000"},{"visibility":"off"}]},{"featureType":"road.arterial","elementType":"geometry","stylers":[{"color":"#000000"},{"lightness":18}]},{"featureType":"road.arterial","elementType":"geometry.fill","stylers":[{"visibility":"on"},{"lightness":"-100"},{"color":"#181818"}]},{"featureType":"road.local","elementType":"geometry","stylers":[{"color":"#000000"},{"lightness":16}]},{"featureType":"road.local","elementType":"geometry.fill","stylers":[{"visibility":"on"},{"lightness":"-100"},{"color":"#181818"}]},{"featureType":"transit","elementType":"geometry","stylers":[{"color":"#000000"},{"lightness":19},{"visibility":"on"},{"gamma":"0.00"}]},{"featureType":"transit.station","elementType":"all","stylers":[{"gamma":"0.00"},{"visibility":"off"}]},{"featureType":"transit.station","elementType":"labels.text","stylers":[{"visibility":"off"}]},{"featureType":"transit.station.rail","elementType":"all","stylers":[{"visibility":"off"}]},{"featureType":"water","elementType":"geometry","stylers":[{"color":"#000000"},{"lightness":17}]}]

任何帮助将是巨大的!

在此处输入图片说明

在此处输入图片说明

在此处输入图片说明

雷博特先生

我想我知道您问题的解决方案。

这是我用于测试的变量样式:

var styleArray = [{
featureType : "administrative",
elementType : "geometry",
stylers: [
{ color: '#000000' },
{"lightness":50}
]
},
{
featureType : "poi",
elementType : "geometry",
stylers: [
{ color: '#000000' },
{"lightness":21}
]
},
{
featureType : "landscape",
elementType : "geometry",
stylers: [
{ color: '#000000' },
{"lightness":21}
]
},
{
featureType : "road",
elementType : "geometry",
stylers: [
{ color: '#000000' },
{"lightness":2}
]
},
{
featureType : "transit",
elementType : "geometry",
stylers: [
{ color: '#000000' },
{"lightness":21}
]
}
];

结果如下:

在此处输入图片说明

经过一些测试之后,我得出了以下结论:

var styleArray = [

{
featureType : "all",
elementType : "geometry",
stylers: [
{ color: '#000000' },
{"lightness":30}
]
},
{
featureType : "administrative",
elementType : "geometry",
stylers: [
{ color: '#000000' },
{"lightness":50}
]
},
{
featureType : "poi",
elementType : "geometry",
stylers: [
{ color: '#000000' },
{"lightness":21}
]
},
{
featureType : "landscape",
elementType : "geometry",
stylers: [
{ color: '#000000' },
{"lightness":21}
]
},
{
featureType : "road",
elementType : "geometry",
stylers: [
{ color: '#000000' },
{"lightness":2}
]
},
{
featureType : "transit",
elementType : "geometry",
stylers: [
{ color: '#000000' },
{"lightness":21}
]
},
{
featureType : "water",
elementType : "geometry",
stylers: [
{ color: '#000000' }
]
}
]; 

结果如下:

在此处输入图片说明

只需将要素类型“全部”设置为深色样式,然后会将规则应用于所有选择器类型。不幸的是,颜色较浅的第一张图像似乎不是特定的常量,例如“ pio,administrative,landscape”,而是包含在“ all” featureType中

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

TOP 榜单

热门标签

归档