[align=center]
<!--这里只是部分代码,全部都在map.rar里面,可以下载测试-->
[/align]
<!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%;overflow: hidden;margin:0;}
#allmap {height: 100%;overflow: hidden;}
#result {border-left:1px dotted #999;height:100%;width:295px;position:absolute;top:0px;right:0px;font-size:12px; border:1px double red; display:none;}
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="http://api.map.baidu.com/api?v=1.4"></script>
<!--加载鼠标绘制工具-->
<script type="text/javascript" src="DrawingManager_min.js"></script>
<link rel="stylesheet" href="DrawingManager_min.css" />
<!--加载检索信息窗口-->
<script type="text/javascript" src="SearchInfoWindow_min.js"></script>
<link rel="stylesheet" href="SearchInfoWindow_min.css" />
<!--根据新浪得到地址。
//<script language="javascript" type="text/javascript" src="http://int.dpool.sina.com.cn/iplookup/iplookup.php?format=js"></script>
-->
<script type="text/javascript" src="Mask.js"></script>
<title>Map_API</title>
</head>
<body>
<div id="allmap" style="overflow:hidden;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 id="panelWrap" style="width:0px;position:absolute;top:0px;right:0px;height:100%;overflow:auto;-webkit-transition: all 0.5s ease-in-out;transition: all 0.5s ease-in-out;">
<div style="width:20px;height:200px;margin:-100px 0 0 -10px;color:#999;position:absolute;opacity:0.5;top:50%;left:50%;" id="showOverlayInfo">此处用于展示覆盖物信息</div>
<div id="panel" style="position:absolute;"></div>
</div>
</div>
<div id="result">
<dl>
<dt>绘制工具功能</dt>
- <label><input type="radio" name="openClose1" onclick="drawingManager.open()"/>打开</label> <label><input type="radio" name="openClose1" onclick="drawingManager.close()" checked="checked"/>关闭</label>
</dd>
<dt>是否进行线或面积的计算(单位米)</dt>
- <label><input type="radio" name="openClose" onclick="drawingManager.enableCalculate()"/>打开</label> <label><input type="radio" name="openClose" onclick="drawingManager.disableCalculate()" checked="checked"/>关闭</label>
</dd>
<dt>绘制功能</dt>
<dd>
<li>
<label><input type="radio" name="drawmode" onclick="drawingManager.setDrawingMode(BMAP_DRAWING_MARKER)" checked="checked"/>画点</label>
<input type="checkbox" id="isInfowindow"/> 是否带信息窗口
</li>
<li>
<label><input type="radio" name="drawmode" onclick="drawingManager.setDrawingMode(BMAP_DRAWING_CIRCLE)"/>画圆</label>
</li>
<li>
<label><input type="radio" name="drawmode" onclick="drawingManager.setDrawingMode(BMAP_DRAWING_POLYLINE)"/>画线</label>
</li>
<li>
<label><input type="radio" name="drawmode" onclick="drawingManager.setDrawingMode(BMAP_DRAWING_POLYGON)"/>画多边形</label>
</li>
<li>
<label><input type="radio" name="drawmode" onclick="drawingManager.setDrawingMode(BMAP_DRAWING_RECTANGLE)"/>画矩形</label>
</li>
</dd>
<dt>覆盖物操作</dt>
<dd>
<li>
<input type="button" value="获取绘制的覆盖物个数" onclick="alert(overlays.length)"/>
<input type="button" value="清除所有覆盖物" onclick="clearAll()"/>
<input type="button" value="获取最后一个覆盖物信息" id="getLastOverLay"/>
</li>
</dd>
</dl>
</div>
<script type="text/javascript">
// 百度地图API功能
var map = new BMap.Map("map"); // 创建Map实例
map.centerAndZoom("南京市", 13);// 初始化地图,设置中心点坐标和地图级别。
map.enableScrollWheelZoom();
//map.addControl(new BMap.MapTypeControl({mapTypes: [BMAP_NORMAL_MAP,BMAP_HYBRID_MAP]})); //2D图,卫星图
//map.addControl(new BMap.MapTypeControl({anchor: BMAP_ANCHOR_TOP_LEFT})); //左上角,默认地图控件
//map.setCurrentCity("南京"); //由于有3D图,需要设置城市哦
var iconSize=new BMap.Size(64, 64);//标注图片大小
for(var i=0;i<10;i++){
var point = new BMap.Point(118.75415+i, 32.02024441+i);//标注图片的坐标
DynamicMarking(point,'access_point_r64.gif',"access_point_b64.gif",iconSize,"江苏省南京市建邺区黄山路盛世公馆202室"+i);//第二个值:初始标注;第三个值:鼠标指上去后的标注图标;第五个值:标注文本;
}
map.addControl(new BMap.NavigationControl()); //添加默认缩放平移控件
map.addControl(new BMap.NavigationControl({anchor: BMAP_ANCHOR_TOP_RIGHT, type: BMAP_NAVIGATION_CONTROL_SMALL})); //右上角,仅包含平移和缩放按钮
map.addControl(new BMap.NavigationControl({anchor: BMAP_ANCHOR_BOTTOM_LEFT, type: BMAP_NAVIGATION_CONTROL_PAN})); //左下角,仅包含平移按钮
map.addControl(new BMap.NavigationControl({anchor: BMAP_ANCHOR_BOTTOM_RIGHT, type: BMAP_NAVIGATION_CONTROL_ZOOM})); //右下角,仅包含缩放按钮
$("getLastOverLay").onclick = function(){
if(overlays.length){
alert(overlays[overlays.length - 1]);
}else{
alert("没有覆盖物");
}
}
//信息窗口的内容定义
var content = '<div style="margin:0;line-height:20px;padding:2px;">' +
'地址:北京市海淀区上地十街10号<br/>电话:(010)59928888<br/>简介:百度大厦位于北京市海淀区西二旗地铁站附近,为百度公司综合研发及办公总部。' +
'</div>';
//创建带信息窗口的poi点
var searchInfoWindow = new BMapLib.SearchInfoWindow(map, content, {
title : "百度大厦", //标题
width : 290, //宽度
height : 105, //高度
panel : "panel", //检索结果面板
enableAutoPan : true, //自动平移
searchTypes :[
BMAPLIB_TAB_SEARCH, //周边检索
BMAPLIB_TAB_TO_HERE, //到这里去
BMAPLIB_TAB_FROM_HERE //从这里出发
]
});
var overlays = [];
//回调获得覆盖物信息
var overlaycomplete = function(e){
overlays.push(e.overlay);
var result = "";
result = "";
result += e.drawingMode + ":";
if (e.drawingMode == BMAP_DRAWING_MARKER) {
result += ' 坐标:' + e.overlay.getPosition().lng + ',' + e.overlay.getPosition().lat;
if ($('isInfowindow').checked) {
searchInfoWindow.open(e.overlay);
}
}
if (e.drawingMode == BMAP_DRAWING_CIRCLE) {
result += ' 半径:' + e.overlay.getRadius();
result += ' 中心点:' + e.overlay.getCenter().lng + "," + e.overlay.getCenter().lat;
}
if (e.drawingMode == BMAP_DRAWING_POLYLINE || e.drawingMode == BMAP_DRAWING_POLYGON || e.drawingMode == BMAP_DRAWING_RECTANGLE) {
result += ' 所画的点个数:' + e.overlay.getPath().length;
}
result += "
";
$("showOverlayInfo").style.display = "none";
$("panel").innerHTML += result; //将绘制的覆盖物信息结果输出到结果面板
};
var styleOptions = {
strokeColor:"red", //边线颜色。
fillColor:"red", //填充颜色。当参数为空时,圆形将没有填充效果。
strokeWeight: 3, //边线的宽度,以像素为单位。
strokeOpacity: 0.8, //边线透明度,取值范围0 - 1。
fillOpacity: 0.01, //填充的透明度,取值范围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), //偏离值
scale: 0.8 //工具栏缩放比例
},
circleOptions: styleOptions, //圆的样式
polylineOptions: styleOptions, //线的样式
polygonOptions: styleOptions, //多边形的样式
rectangleOptions: styleOptions //矩形的样式
});
//添加鼠标绘制工具监听事件,用于获取绘制结果
drawingManager.addEventListener('overlaycomplete', overlaycomplete);
function $(id){
return document.getElementById(id);
}
function clearAll() {
for(var i = 0; i < overlays.length; i++){
map.removeOverlay(overlays[i]);
}
overlays.length = 0
}
</script>
</body>
</html>
</script>