gpt4 book ai didi

html - 如何更改我网站上 google mp 的样式

转载 作者:太空宇宙 更新时间:2023-11-03 22:33:12 25 4
gpt4 key购买 nike

我正在尝试在我的网站上实现谷歌地图,这就是它的样子

enter image description here

但是,它的颜色影响了我的用户界面。我访问了一个带有谷歌地图的网站,看起来像这样。 enter image description here

如何将我的谷歌地图更改为灰色样式?感谢任何帮助。如果需要,这里还有我的代码。

function markers(position, zoom) {
if (typeof zoom === "undefined") {
zoom = 12;
}
var center = new google.maps.LatLng(position.coords.latitude, position.coords.longitude);
var map = new google.maps.Map(document.getElementById('map'), {
zoom: zoom,
scrollwheel: false,
center: center,
mapTypeId: google.maps.MapTypeId.ROADMAP
});

var markers = [];
var flag;
var group = [];
....
}
var markerCluster = new MarkerClusterer(map, markers);
}

最佳答案

您可以为自己制作自定义样式或使用来自 snazzymaps 的预制样式只需将您想要的样式复制/粘贴到我在您的代码中添加的样式部分

function markers(position, zoom) {
if (typeof zoom === "undefined") {
zoom = 12;
}
var center = new google.maps.LatLng(position.coords.latitude, position.coords.longitude);
var map = new google.maps.Map(document.getElementById('map'), {
zoom: zoom,
scrollwheel: false,
center: center,
styles: [
{
"featureType": "all",
"elementType": "all",
"stylers": [
{
"visibility": "on"
}
]
},
{
"featureType": "all",
"elementType": "labels",
"stylers": [
{
"visibility": "off"
},
{
"saturation": "-100"
}
]
},
{
"featureType": "all",
"elementType": "labels.text.fill",
"stylers": [
{
"saturation": 36
},
{
"color": "#000000"
},
{
"lightness": 40
},
{
"visibility": "off"
}
]
},
{
"featureType": "all",
"elementType": "labels.text.stroke",
"stylers": [
{
"visibility": "off"
},
{
"color": "#000000"
},
{
"lightness": 16
}
]
},
{
"featureType": "all",
"elementType": "labels.icon",
"stylers": [
{
"visibility": "off"
}
]
},
{
"featureType": "administrative",
"elementType": "geometry.fill",
"stylers": [
{
"color": "#000000"
},
{
"lightness": 20
}
]
},
{
"featureType": "administrative",
"elementType": "geometry.stroke",
"stylers": [
{
"color": "#000000"
},
{
"lightness": 17
},
{
"weight": 1.2
}
]
},
{
"featureType": "landscape",
"elementType": "geometry",
"stylers": [
{
"color": "#000000"
},
{
"lightness": 20
}
]
},
{
"featureType": "landscape",
"elementType": "geometry.fill",
"stylers": [
{
"color": "#4d6059"
}
]
},
{
"featureType": "landscape",
"elementType": "geometry.stroke",
"stylers": [
{
"color": "#4d6059"
}
]
},
{
"featureType": "landscape.natural",
"elementType": "geometry.fill",
"stylers": [
{
"color": "#4d6059"
}
]
},
{
"featureType": "poi",
"elementType": "geometry",
"stylers": [
{
"lightness": 21
}
]
},
{
"featureType": "poi",
"elementType": "geometry.fill",
"stylers": [
{
"color": "#4d6059"
}
]
},
{
"featureType": "poi",
"elementType": "geometry.stroke",
"stylers": [
{
"color": "#4d6059"
}
]
},
{
"featureType": "road",
"elementType": "geometry",
"stylers": [
{
"visibility": "on"
},
{
"color": "#7f8d89"
}
]
},
{
"featureType": "road",
"elementType": "geometry.fill",
"stylers": [
{
"color": "#7f8d89"
}
]
},
{
"featureType": "road.highway",
"elementType": "geometry.fill",
"stylers": [
{
"color": "#7f8d89"
},
{
"lightness": 17
}
]
},
{
"featureType": "road.highway",
"elementType": "geometry.stroke",
"stylers": [
{
"color": "#7f8d89"
},
{
"lightness": 29
},
{
"weight": 0.2
}
]
},
{
"featureType": "road.arterial",
"elementType": "geometry",
"stylers": [
{
"color": "#000000"
},
{
"lightness": 18
}
]
},
{
"featureType": "road.arterial",
"elementType": "geometry.fill",
"stylers": [
{
"color": "#7f8d89"
}
]
},
{
"featureType": "road.arterial",
"elementType": "geometry.stroke",
"stylers": [
{
"color": "#7f8d89"
}
]
},
{
"featureType": "road.local",
"elementType": "geometry",
"stylers": [
{
"color": "#000000"
},
{
"lightness": 16
}
]
},
{
"featureType": "road.local",
"elementType": "geometry.fill",
"stylers": [
{
"color": "#7f8d89"
}
]
},
{
"featureType": "road.local",
"elementType": "geometry.stroke",
"stylers": [
{
"color": "#7f8d89"
}
]
},
{
"featureType": "transit",
"elementType": "geometry",
"stylers": [
{
"color": "#000000"
},
{
"lightness": 19
}
]
},
{
"featureType": "water",
"elementType": "all",
"stylers": [
{
"color": "#2b3638"
},
{
"visibility": "on"
}
]
},
{
"featureType": "water",
"elementType": "geometry",
"stylers": [
{
"color": "#2b3638"
},
{
"lightness": 17
}
]
},
{
"featureType": "water",
"elementType": "geometry.fill",
"stylers": [
{
"color": "#24282b"
}
]
},
{
"featureType": "water",
"elementType": "geometry.stroke",
"stylers": [
{
"color": "#24282b"
}
]
},
{
"featureType": "water",
"elementType": "labels",
"stylers": [
{
"visibility": "off"
}
]
},
{
"featureType": "water",
"elementType": "labels.text",
"stylers": [
{
"visibility": "off"
}
]
},
{
"featureType": "water",
"elementType": "labels.text.fill",
"stylers": [
{
"visibility": "off"
}
]
},
{
"featureType": "water",
"elementType": "labels.text.stroke",
"stylers": [
{
"visibility": "off"
}
]
},
{
"featureType": "water",
"elementType": "labels.icon",
"stylers": [
{
"visibility": "off"
}
]
}
],
mapTypeId: google.maps.MapTypeId.ROADMAP
});

var markers = [];
var flag;
var group = [];
....
}
var markerCluster = new MarkerClusterer(map, markers);
}

如何为您的 map 实现样式: Google Map API

P.S:我是色盲所以我只是为你的 map 选择了一种随机颜色样式而不是灰色样式(我假设)

关于html - 如何更改我网站上 google mp 的样式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47757359/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com