作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试仅使用波士顿地铁线路、土地和水来制作风格化的谷歌地图。我将所有内容的可见性设置为关闭,但仍有一些建筑物出现,而且它看起来像是唯一带有室内地图的建筑物。
这是我的代码:
<html>
<head>
<script type="text/javascript" src="https://maps.googleapis.com/maps/api/js?sensor=false"></script>
<script type="text/javascript">
var lat = 42.3581;
var long = -71.0636;
google.maps.visualRefresh = true;
function initialize()
{
var mapStyle =
[
{
featureType: 'administrative',
elementType: 'all',
stylers:
[
{ visibility: 'off' }
]
},
{
featureType: 'landscape',
elementType: 'all',
stylers:
[
{ visibility: 'off' }
]
},
{
featureType: 'poi',
elementType: 'all',
stylers:
[
{ visibility: 'off' }
]
},
{
featureType: 'road',
elementType: 'all',
stylers:
[
{ visibility: 'off' }
]
},
{
featureType: 'transit',
elementType: 'all',
stylers:
[
{ visibility: 'off' }
]
},
{
featureType: 'water',
elementType: 'all',
stylers:
[
{ visibility: 'off' }
]
},
{
featureType: 'landscape',
elementType: 'geometry',
stylers:
[
{ color: '#ffffff' },
{ visibility: 'on' }
]
},
{
featureType: 'water',
elementType: 'geometry',
stylers:
[
{ color: '#e5e5e5' },
{ visibility: 'on' }
]
}
];
var mapOptions =
{
center: new google.maps.LatLng(lat, long),
mapTypeId: google.maps.MapTypeId.ROADMAP,
zoom: 16,
backgroundColor: '#ffffff',
streetViewControl: false,
mapTypeControl: false,
panControl: false,
zoomControl: false,
scrollwheel: true,
draggable: true
};
var map = new google.maps.Map(document.getElementById("map-canvas"), mapOptions);
var transitLayer = new google.maps.TransitLayer();
transitLayer.setMap(map);
var styledMapOptions = {name: 'Map'};
var newMapType = new google.maps.StyledMapType(mapStyle, styledMapOptions);
map.mapTypes.set('stylized', newMapType);
map.setMapTypeId('stylized');
onResize();
}
google.maps.event.addDomListener(window, 'load', initialize);
function onResize()
{
document.getElementById("map-canvas").style.height = window.innerHeight - document.getElementById("map-canvas").getBoundingClientRect().top + 24 +"px";
}
</script>
</head>
<body onResize="onResize()">
<div id="map-canvas"/>
</body>
</html>
featureType: 'all',
elementType: 'all',
stylers:
[
{ visibility: 'off' }
]
最佳答案
我发现实现这一点的唯一方法是禁用所有内容,然后在样式 json 中将每个主要样式部分放回可见。
您可以使用以下内容作为重置样式 json 来删除室内地图
[
{"stylers": [ {"visibility": "off" } ] },
{"featureType": "water","stylers": [{"visibility": "on"} ] },
{"featureType": "poi","stylers": [ {"visibility": "on"} ]},
{"featureType": "transit","stylers": [{ "visibility": "on"}] },
{ "featureType": "landscape","stylers": [ { "visibility": "on" } ] },
{ "featureType": "road", "stylers": [{ "visibility": "on" } ] },
{ "featureType": "administrative", "stylers": [{ "visibility": "on" } ] },
/* followed by your style if you have specific styles
, otherwise remove the last comma */
]
关于google-maps - 从风格化的 Google map 中删除室内地图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21416261/
leaflet:一个开源并且对移动端友好的交互式地图 JavaScript 库 中文文档: https://leafletjs.cn/reference.html 官网(英文): ht
我是一名优秀的程序员,十分优秀!