请老师检查,谢谢
来源:3-12 自由编程
qq_慕移动3101913
2020-02-10 13:53:40
<!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>Document</title> <script type="text/javascript" src="https://webapi.amap.com/maps?v=1.4.15&key=48259e2fd01bb69855450c5b97b5ea81"></script> <style type="text/css"> *{margin: 0;padding: 0;} #container {width:100%; height: 100%; position: absolute;left: 0;top: 0;} #toolbar{ width:300px; height: 250px; background-color: #fff; position: absolute; z-index: 99; left: 10px; top: 10px; box-shadow: 1px 1px 5px black; background: white; } .title{ width: 300px; height: 30px; text-align: center; line-height: 30px; font-weight: bold; margin-top: 20px; font-size: 16px; } .city{ font-size: 13px; position: absolute; right: 37px; top: 53px; } .rank{ font-size: 13px; position: absolute; right: 37px; top: 92px; } #btn1{ width: 45px; height: 30px; color: #fff; font-size: 13px; background-color: #4169E1; border:none; } #btn2{ width: 45px; height: 30px; color: #fff; font-size: 13px; background-color:#4169E1; border:none; } #clear{ width: 100px; height: 30px; font-size: 13px; background-color: #C0C0C0; position: absolute; left: 110px; top: 131px; border:none; } .kuang{ width: 100px; height: 25px; padding-left: 5px; } .newest{ position: absolute; right: 10px; bottom: 10px; font-size: 13px; } </style> </head> <body> <!-- 地图 --> <div id="container"></div> <!-- 工具栏 --> <div id='toolbar'> <p class="title">工具栏</p> <div class="city">搜索城市: <input class="kuang" type="text" name="" id='city2'> <button id='btn1'>确定</button> </div> <div class="rank">设置显示级别: <input class="kuang" type="text" name="" id='zoomVal'> <button id='btn2'>确定</button> </div> <button id='clear'>解除范围限制</button> <p class="newest">当前所在省/直辖市:<span id='ne'></span></p> </div>B <script type="text/javascript"> //创建一个地图 var map = new AMap.Map('container'); //设置地图显示范围为北京 var myBounds = new AMap.Bounds([116.22422,39.813285],[116.567542,39.997639]); //限制地图显示在北京 map.setLimitBounds(myBounds); //点击按钮搜索城市 btn1.onclick = function(){ map.setCity(city2.value); }; //点击按钮搜索地图级别 btn2.onclick = function(){ map.setZoom(zoomVal.value); }; //通过事件来给予中心点 map.on('click',function(e){ map.setCenter([e.lnglat.lng,e.lnglat.lat]) }); //通过事件解除显示限制 clear.onclick = function(){ if(clear.innerHTML === '解除范围限制'){ map.clearLimitBounds(); clear.innerHTML = '已解除范围限制' }else if(clear.innerHTML === '已解除范围限制'){ map.setLimitBounds(map.getBounds()); clear.innerHTML = '解除范围限制' } map.setCity(Ctiy2.value); }; //为鼠标绑定moveend事件 ,当鼠标在地图上移动时 ,让工具栏的右下角显示当前省/直辖市。 map.on('moveend',function(){ map.getCity(function(info){ ne.innerHTML=info.province; }) }); </script> </body> </html>
1回答
好帮手慕慕子
2020-02-10
同学你好,如下所示city单词拼写错误,建议修改:
修改后的代码效果实现是对的,继续加油
如果我的回答帮助到了你,欢迎采纳,祝学习愉快~
相似问题