请老师检查!

来源:3-12 自由编程

小仙女要好好学习

2019-09-24 20:21:18

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>111</title>
    <script type="text/javascript" src="https://webapi.amap.com/maps?v=1.4.11&key=a29a2eee0ee2be00b070f0f26f7b39a5"></script> 
    <style>
        *{
            margin: 0;
            padding: 0;
        }
        #container{
            width: 100%;
            height: 100%;
            position: absolute;
            left: 0;
            top: 0;
        }
        #box{
            width: 300px;
            height: 300px;
            position: absolute;
            left: 20px;
            top: 30px;
            background: #fff;
            border: 1px solid #eee;
            box-shadow: 0 0 5px #000;
        }
        .caption{
            width: 100%;
            height: 30px;
            font-weight: bold;
            font-size: 16px;
            text-align: center;
            line-height: 30px;
        }
        .form{
            width: 260px;
            margin: 0 auto;
        }
        #city,#level{
            width: 100px;
            height: 20px;
        }
        .form div{
            margin-top: 10px;
            float: right;
        }
        .btn{
            width: 40px;
            height: 22px;
            background: rgb(89, 151, 221);
            color: #fff;
            border: none;
            line-height: 22px;
            cursor: pointer;
        }
        .clear{
            width: 90px;
            height: 30px;
            background: rgb(173, 171, 171);
            color: #000;
            border: none;
            cursor: pointer;
            margin-top: 10px;
            margin-left: 110px;
        }
        .now{
            position: absolute;
            right: 50px;
            bottom: 10px;
            font-size: 14px;
        }
    </style>
</head>
<body>
    <div id="container"></div> 
    <div id="box">
        <div class="caption">工具栏</div>
        <div class="form">
            <div>
                <label for="city">搜索城市</label>:
                <input type="text" id="city">
                <input type="button" value="确定" class="btn" id="btnCity">
            </div>
            <div>
                <label for="city">设置显示级别</label>:
                <input type="text" id="level">
                <input type="button" value="确定" class="btn" id="btnLevel">
            </div>
            <input type="button" value="解除范围限制" class="clear" id="clear">
        </div>
        <div class="now">当前所在省/直辖市:<span id="province"></span></div>
    </div>
    <script>
        var box=document.getElementById("box");
        var city=document.getElementById("city");
        var btnLevel=document.getElementById("btnLevel");
        var btnCity=document.getElementById("btnCity");
        var level=document.getElementById("level");
        var clear=document.getElementById("clear");
        var province=document.getElementById("province");
        var clearbln=true; //默认限制范围

        var map=new AMap.Map("container");
        var myBounds=new AMap.Bounds([116.22422,39.813285],[116.567542,39.997639]);
        map.setBounds(myBounds); //设置界限
        map.setLimitBounds(myBounds); //设置限制范围

        btnCity.onclick=function(){
            map.setCity(city.value)
        }
        btnLevel.onclick=function(){
            map.setZoom(level.value)
        }
        clear.onclick=function(){
            if(clearbln==true){
                map.clearLimitBounds();
                clear.value="已解除范围限制";
                clearbln=false;
            }else{
                map.setLimitBounds(myBounds);
                clear.value="解除范围限制";
                clearbln=true;
            }   
        }
        //获取经纬度设置为当前的中心点
        map.on("click",function(e){
            map.setCenter([e.lnglat.lng,e.lnglat.lat]);
        });

        
        
        map.on("moveend",function(){
            map.getCity(function(info){
                province.innerHTML=info.province
            })
        })
    </script>
</body>
</html>


写回答

1回答

好帮手慕夭夭

2019-09-25

你好同学,实现的正确。表扬一下哦。继续加油,祝学习愉快!

0

0 学习 · 6815 问题

查看课程