高德地图API 之行政区+范围+平移+经纬度+鼠标样式

高德地图API 之行政区+范围+平移+经纬度+鼠标样式,第1张

概述获取当前地图的行政区 getCity() <!DOCTYPE html> <html lang="en"> <head> <meta ch

获取当前地图的行政区 getCity()

<!DOCTYPE HTML><HTML lang="en"head>    Meta charset="UTF-8"Title>map</script type="text/JavaScript" src="https://webAPI.amap.com/maps?v=1.4.15&key=ce3b1a3a7e67fc75810ce1ba1f83c01a"></script>     style>        *{margin:0;padding}        #container wIDth100% height 100%topleftposition absolute;           #setZoomNode300pxheight100pxbackground-color #fffborder1px solIDBox-shadow0 0 5px #00020pxright}    bodydiv ID="container"div="setZoomNode">    >        var map=new AMap.Map("container);            map.on(moveend,function(){            //获取行政区            map.getCity((info){                console.log(info);                setZoomNode.INNERHTMLinfo.province+info.cityinfo.district;            })        })            >    HTML>

 

 注意:默认只能获取中国的行政区

 

设置行政区 setCity()

>        input ="text" ID="city"button ="btn">设置行政区buttoninfo.district;            })        })        设置行政区        map.setCity(宁波);        通过事件设置行政区        btn.onclick(){            map.setCity(city.value);        }            >

 

 

获取地图的范围 getBounds()

c对象

northeast 右上

southwest 左下

400pxspan ="ne"span><br="sw"获取范围            console.log(map.getBounds());            ne.INNERHTMLmap.getBounds().northeast.toString();            sw.INNERHTMLmap.getBounds().southwest.toString();        })            >

 

 

设置地图的显示范围 setBounds()

);            先左下角,再右上角         myBounds AMap.Bounds([122.24080129.401671],[123.53993430.261788]);        map.setBounds(myBounds);        设置的范围并不一定完全贴合获取到的范围,只能是尽可能匹配        console.log(map.getBounds().northeast.toString());        console.log(map.getBounds().southwest.toString());            >

 

 

限制显示范围 setlimitBounds()

限制显示范围         boundsmap.getBounds();        map.setlimitBounds(bounds);            >

限制在当前范围内不可查看其它范围的

 

解除范围限制 clearlimitBounds()

map.getBounds();        map.setlimitBounds(bounds);        解除范围限制        map.clearlimitBounds();            >

 

控制单个坐标值的限制

map.getBounds();        console.log(bounds);        单独限制右上角的水平坐标不能超过123        bounds.northeast.R123;                map.setlimitBounds(bounds);        >

以上实现右上角的水平范围不会超过123

 

 

一个关于显示和解除地图范围的demo

>        右边水平限制:="x2"        左边水平限制="x1">确定="clear">解除限制限制显示范围map.getBounds();            input输入的文本是string,需要转为number            bounds.northeast.RNumber(x2.value);            bounds.southwest.RNumber(x1.value);            map.setlimitBounds(bounds);        }        解除显示范围        clear.onclick(){            map.clearlimitBounds();        }        map.on((){            console.log(map.getBounds().northeast.R);            console.log(map.getBounds().southwest.R);        })            >

 

 

地图的平移,以像素为单位

panBy(左右像素,上下像素) 左正右负,上正下负

);            setTimeout(向左平移50像素,向上平移30像素            map.panBy(5030);        },1)">2000);            >

 

 

随机移动

每3秒随机移动        setInterval(向左上方向随机移动            map.panBy(30*Math.random(),30*Math.random());            不确定方向的随机移动*Math.random()-153000>

 

panTo() 移动到指定位置

);            console.log(map.getCenter().toString());        setTimeout( 宁波移动到了绍兴            map.panTo([120.54979229.868388]);        },1)">>

 

通过事件设置平移

="x"="y">移动);            console.log(map.getCenter().toString());                通过事件设置(){            map.panTo([x.value,y.value]);        }    >

 

获取鼠标的经纬度

longitude  经度

latitude 纬度

        鼠标点击的经纬度:="xy"        map.on(click(e){            console.log(e.lnglat);            xy.INNERHTMLe.lnglat.lnge.lnglat.lat;            同时将鼠标点击位置设置为中心点            map.setCenter([e.lnglat.lng,e.lnglat.lat]);        })    >

 以上代码实现鼠标点击的位置作为地图的中心点

 

设置鼠标样式 setDefaultCursor() 

>            只要是CSS的cursor中能设置的属性值,都可以        map.setDefaultCursor(pointer);    >

 

 

总结

以上是内存溢出为你收集整理的高德地图API 之行政区+范围+平移+经纬度+鼠标样式全部内容,希望文章能够帮你解决高德地图API 之行政区+范围+平移+经纬度+鼠标样式所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/web/1026695.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-23
下一篇 2022-05-23

发表评论

登录后才能评论

评论列表(0条)

保存