我在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" }
]
}
]
我应该可以在我的地图中使用它,但是有人可以告诉我如何使用这个片段吗?我在谷歌地图V3的API中找不到任何相关内容。
答案 0 :(得分:37)
作为@ceejayoz suggested in the other answer,您正尝试使用Styled Map features的新v3 Maps API。以下是如何在简单地图中使用上述样式的一个非常基本的示例:
<!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,以便以图形方式编辑样式。
答案 1 :(得分:5)
我知道这已经有5年了,但我偶然发现了这个问题,并且我认为接受的解决方案比我需要的要复杂得多。鉴于原始帖子中的JSON,您可以将样式应用于现有地图:
var mapStyle = [
{
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" }
]
}
]
//create map
var map = new google.maps.Map(...); //This assumes you already have a working map
//set style
map.set('styles', mapStyle);
答案 2 :(得分:0)
您关联的网页包含指向the Google Maps API documentation for this feature的链接。