<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="chrome=1">
<meta name="viewport" content="initial-scale=1.0, user-scalable=no, width=device-width">
<link rel="stylesheet" href="https://a.amap.com/jsapi_demos/static/demo-center/css/demo-center.css" type="text/css">
<style>
html,body,#container{
height: 100%
}
.btn{
width: 6rem;
margin: 0 1rem 0 4.5rem;
}
</style>
<title>鼠标工具-拉框缩放</title>
</head>
<body>
<div id='container'></div>
<div class='info'>操作说明:在地图上拖拽</div>
<div class="input-card" style='width: 18rem;'>
<div class="input-item">
<input type="radio" name='func' checked="" value='zoomIn'><span class="input-text">拉框放大</span>
<input type="radio" name='func' value='zoomOut'><span class="input-text">拉框缩小</span>
</div>
<div class="input-item">
<input id="close" type="button" class="btn" value="关闭" />
</div>
</div>
<script src="https://webapi.amap.com/maps?v=1.4.15&key=您申请的key值&plugin=AMap.MouseTool"></script>
<script type="text/javascript">
var map = new AMap.Map('container',{
zoom:3
});
var mouseTool = new AMap.MouseTool(map);
function draw(type){
switch(type){
case 'zoomIn':{
mouseTool.rectZoomIn({
strokeColor:'#80d8ff',
fillColor:'#80d8ff',
fillOpacity:0.3
//同 Polygon 的 Option 设置
});
break;
}
case 'zoomOut':{
mouseTool.rectZoomOut({
strokeColor:'#80d8ff',
fillColor:'#80d8ff',
fillOpacity:0.3
//同 Polygon 的 Option 设置
});
break;
}
}
}
var radios = document.getElementsByName('func');
for(var i=0;i<radios.length;i+=1){
radios[i].onchange = function(e){
draw(e.target.value)
}
}
draw('zoomIn')
document.getElementById('close').onclick = function(){
mouseTool.close(true)//关闭,并清除覆盖物
for(var i=0;i<radios.length;i+=1){
radios[i].checked = false;
}
}
</script>
</body>
</html>