<!doctype html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="initial-scale=1.0, user-scalable=no, width=device-width">
<title>带功能控件的地图</title>
<link rel="stylesheet" href="https://a.amap.com/jsapi_demos/static/demo-center/css/demo-center.css" />
<script src="https://cache.amap.com/lbs/static/es5.min.js"></script>
<script src="https://webapi.amap.com/maps?v=1.4.15&key=您申请的key值&&plugin=AMap.Scale,AMap.OverView,AMap.ToolBar"></script>
<style>
html, body {
height: 100%;
}
#container {
height: 100%;
}
.input-card {
width: 150px;
top: 10px;
bottom: auto;
}
</style>
</head>
<body>
<div id="container"></div>
<div class='input-card'>
<div class="input-item">
<input type="checkbox" onclick="toggleScale(this)"/>比例尺
</div>
<div class="input-item">
<input type="checkbox" id="toolbar" onclick="toggleToolBar(this)"/>工具条
</div>
<div class="input-item">
<input type="checkbox" id="toolbarDirection" disabled onclick="toggleToolBarDirection(this)"/>工具条方向盘
</div>
<div class="input-item">
<input type="checkbox" id="toolbarRuler" disabled onclick="toggleToolBarRuler(this)"/>工具条标尺
</div>
<div class="input-item">
<input type="checkbox" id="overview" onclick="toggleOverViewShow(this)"/>显示鹰眼
</div>
<div class="input-item">
<input type="checkbox" id="overviewOpen" disabled onclick="toggleOverViewOpen(this)"/>展开鹰眼
</div>
</div>
<script>
var scale = new AMap.Scale({
visible: false
}),
toolBar = new AMap.ToolBar({
visible: false
}),
overView = new AMap.OverView({
visible: false
}),
map = new AMap.Map("container", {
resizeEnable: true
});
map.addControl(scale);
map.addControl(toolBar);
map.addControl(overView);
function toggleScale(checkbox) {
if (checkbox.checked) {
scale.show();
} else {
scale.hide();
}
}
function toggleToolBar(checkbox) {
if (checkbox.checked) {
showToolBar();
showToolBarDirection();
showToolBarRuler();
} else {
hideToolBar();
hideToolBarDirection();
hideToolBarRuler();
}
}
function toggleToolBarDirection(checkbox) {
if (checkbox.checked) {
toolBar.showDirection()
} else {
toolBar.hideDirection()
}
}
function toggleToolBarRuler(checkbox) {
if (checkbox.checked) {
toolBar.showRuler();
} else {
toolBar.hideRuler();
}
}
function toggleOverViewShow(checkbox) {
if (checkbox.checked) {
overView.show();
document.getElementById('overviewOpen').disabled = false;
} else {
overView.hide();
document.getElementById('overviewOpen').disabled = true;
}
}
function toggleOverViewOpen(checkbox) {
if (checkbox.checked) {
overView.open();
}
else {
overView.close();
}
}
function showToolBar() {
document.getElementById('toolbar').checked = true;
document.getElementById('toolbarDirection').disabled = false;
document.getElementById('toolbarRuler').disabled = false;
toolBar.show();
}
function hideToolBar() {
document.getElementById('toolbar').checked = false;
document.getElementById('toolbarDirection').disabled = true;
document.getElementById('toolbarRuler').disabled = true;
toolBar.hide();
}
function showToolBarDirection() {
document.getElementById('toolbarDirection').checked = true;
toolBar.showDirection();
}
function hideToolBarDirection() {
document.getElementById('toolbarDirection').checked = false;
toolBar.hideDirection();
}
function showToolBarRuler() {
document.getElementById('toolbarRuler').checked = true;
toolBar.showRuler();
}
function hideToolBarRuler() {
document.getElementById('toolbarRuler').checked = false;
toolBar.hideRuler();
}
</script>
</body>
</html>
订阅评论
0 评论