vue-amap 基本使用 html快速预览

此示例展示了如何在高德地图中添加并控制比例尺、工具条、鹰眼等地图控件的显示与隐藏,包括比例尺的开关、工具条的显示及方向和标尺功能、鹰眼的显示及展开状态的切换。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

在这里插入图片描述

<!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>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值