<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>百度地图API测试</title>
</head>
<style>
html{height:100%}
body{height:100%;margin:0px;padding:0px}
#container{
margin:auto;
height:500px;
width:700px;
}
.info {
z-index: 999;
width: auto;
padding: 10px;
margin-left: 10px;
position: fixed;
top: 10px;
background-color: #fff;
border-radius: 5px;
font-size: 14px;
color: #666;
box-shadow: 0 2px 6px 0 rgba(27, 142, 236, 0.5);
}
ul li {
list-style: none;
}
.btn-wrap {
z-index: 999;
width: 226px;
position: fixed;
bottom: 30px;
left: 10px;
padding: 10px;
border-radius: 5px;
background-color: rgba(265, 265, 265, 0.9);
box-shadow: 0 2px 6px 0 rgba(27, 142, 236, 0.5);
}
.btn {
width: 100px;
height: 30px;
float: left;
background-color: #fff;
color: rgba(27, 142, 236, 1);
font-size: 14px;
border:1px solid rgba(27, 142, 236, 1);
border-radius: 5px;
margin: 0 5px 6px;
text-align: center;
line-height: 30px;
}
.btn:hover {
background-color: rgba(27, 142, 236, 0.8);
color: #fff;
cursor: pointer;
}
</style>
<!-- 在线载入百度地图API -->
<script type="text/javascript" src="jquery.min.js"></script>
<script type="text/javascript" src="https://api.map.baidu.com/api?v=1.0&type=webgl&ak=lvLi2NM0XiSt308lTcHBVB3QYZeuXNq3">
</script>
<body>
<div id="container"></div>
<ul class="btn-wrap" style="z-index: 99;">
<!-- poi Point of Interest 直译兴趣点,在地理系统中可以理解为地标信息点 -->
<li class = "btn" onclick = "showText()">显示POI文字</li>
<li class = "btn" onclick = "hideText()">隐藏POI文字</li>
<li class = "btn" onclick = "showIcon()">显示POI的图标</li>
<li class = "btn" onclick = "hideIcon()">隐藏POI的图标</li>
<li class = "btn" onclick = "show3Dbuild()">显示3D建筑物</li>
<li class = "btn" onclick = "hide3Dbuild()">隐藏3D建筑物</li>
</ul>
<script>
var map = new BMapGL.Map("container",{
// enableRotate: false, //可以在创建地图时禁止旋转和倾斜
// enableTilt: false
}
); //创建地图实例
map.centerAndZoom('荆州', 15); //初始化地图,15为展示级别,直接以城市为中心点坐标
map.enableScrollWheelZoom(true); //开启鼠标滚轮缩放
// map.setHeading(64.5);
// map.setTilt(73);
//控件
var scaleCtrl = new BMapGL.ScaleControl(); // 添加比例尺控件
map.addControl(scaleCtrl);
var zoomCtrl = new BMapGL.ZoomControl(); // 添加缩放控件
map.addControl(zoomCtrl);
var cityCtrl = new BMapGL.CityListControl(); // 添加城市列表控件
map.addControl(cityCtrl);
var navi3DCtrl = new BMapGL.NavigationControl3D(); // 添加3D控件
map.addControl(navi3DCtrl);
//百度地图提供了两种方法来设置地图元素,本次demo选择第二种
// map.setOptions({displayOptions: yourDisplayOptions})
// map.setDisplayOptions(yourDisplayOptions)
//本次demo使用第二种,可以直接设置poi属性
//设置地图显示元素
map.setDisplayOptions({
poi: true //初始化设置显示POI信息
})
function showText() {
map.setDisplayOptions({
poiText: true //显示POI
})
}
function hideText() {
map.setDisplayOptions({
poiText: false //关闭POI
})
}
function showIcon() {
map.setDisplayOptions({
poiIcon: true //显示图标
})
}
function hideIcon() {
map.setDisplayOptions({
poiIcon: false //关闭图标
})
}
function show3Dbuild() {
map.setDisplayOptions({
building: true
})
}
function hide3Dbuild() {
map.setDisplayOptions({
building: false
})
}
</script>
</body>
</html>
评论0