我在 http://www.41latitude.com/post/1268734799/google-styled-maps 上找到了一个代码片段:
[
{
featureType: "administrative",
elementType: "labels",
stylers: [
{ visibility: "off" }
]
},{
featureType: "poi",
elementType: "labels",
stylers: [
{ visibility: "off" }
]
},{
featureType: "water",
elementType: "labels",
stylers: [
{ visibility: "off" }
]
},{
featureType: "road",
elementType: "labels",
stylers: [
{ visibility: "off" }
]
}
]
我应该能够在我的 map 中使用它,但是有人可以告诉我如何使用这个片段吗?我在 Google Maps V3 的 API 中找不到任何相关信息。
最佳答案
如@ceejayoz suggested in the other answer ,您正在尝试使用新的 Styled Map features v3 Maps API的。这是一个非常基本的示例,说明如何在简单的 map 中使用上述样式:
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8"/>
<title>Google Maps Dark Water Style Demo</title>
<script src="http://maps.google.com/maps/api/js?sensor=false" type="text/javascript"></script>
</head>
<body>
<div id="map" style="width: 550px; height: 300px;"></div>
<script type="text/javascript">
var myStyle = [
{
featureType: "administrative",
elementType: "labels",
stylers: [
{ visibility: "off" }
]
},{
featureType: "poi",
elementType: "labels",
stylers: [
{ visibility: "off" }
]
},{
featureType: "water",
elementType: "labels",
stylers: [
{ visibility: "off" }
]
},{
featureType: "road",
elementType: "labels",
stylers: [
{ visibility: "off" }
]
}
];
var map = new google.maps.Map(document.getElementById('map'), {
mapTypeControlOptions: {
mapTypeIds: ['mystyle', google.maps.MapTypeId.ROADMAP, google.maps.MapTypeId.TERRAIN]
},
center: new google.maps.LatLng(30, 0),
zoom: 3,
mapTypeId: 'mystyle'
});
map.mapTypes.set('mystyle', new google.maps.StyledMapType(myStyle, { name: 'My Style' }));
</script>
</body>
</html>
屏幕截图:
您可能还想查看Google Maps APIs Styling Wizard这将允许您以图形方式编辑样式。
关于javascript - Google map v3 隐藏元素(道路、路标等),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4024672/