20px;background:
yellow'>我是自定义版权控件呀",bounds:
bs});//Copyright(id,content,bounds)类作为CopyrightControl.addCopyright()方法的参数
4.添加标注点和弹出信息
//XX地图API功能
varmap=newBMap.Map("allmap");
map.centerAndZoom(newBMap.Point(116.404,39.915),14);
varmarker1=newBMap.Marker(newBMap.Point(116.384,39.925));//创建标注
map.addOverlay(marker1);//将标注添加到地图中
//创建信息窗口
varinfoWindow1=newBMap.InfoWindow("普通标注");
marker1.addEventListener("click",function(){this.openInfoWindow(infoWindow1);});
//创建小狐狸
varpt=newBMap.Point(116.417,39.909);
varmyIcon=newBMap.Icon("fox.gif",newBMap.Size(300,157));
varmarker2=newBMap.Marker(pt,{icon:
myIcon});//创建标注
map.addOverlay(marker2);//将标注添加到地图中
//让小狐狸说话(创建信息窗口)
varinfoWindow2=newBMap.InfoWindow("14px;'>哈哈,你看见我啦!
我可不常出现哦!
14px;'>赶快查看源代码,看看我是如何添加上来的!
");
marker2.addEventListener("click",function(){this.openInfoWindow(infoWindow2);});
5.添加动态的标注
//XX地图API功能
varmap=newBMap.Map("allmap");
varpoint=newBMap.Point(116.404,39.915);
map.centerAndZoom(point,15);
varmarker=newBMap.Marker(point);//创建标注
map.addOverlay(marker);//将标注添加到地图中
marker.setAnimation(BMAP_ANIMATION_BOUNCE);//跳动的动画
5.随机添加标注点
//编写自定义函数,创建标注
functionaddMarker(point){
varmarker=newBMap.Marker(point);
map.addOverlay(marker);
}
//随机向地图添加25个标注
varbounds=map.getBounds();
varsw=bounds.getSouthWest();
varne=bounds.getNorthEast();
varlngSpan=Math.abs(sw.lng-ne.lng);
varlatSpan=Math.abs(ne.lat-sw.lat);
for(vari=0;i<25;i++){
varpoint=newBMap.Point(sw.lng+lngSpan*(Math.random()*0.7),ne.lat-latSpan*(Math.random()*0.7));
addMarker(point);
}
6.添加折线
arpolyline=newBMap.Polyline([
newBMap.Point(116.399,29.910),
newBMap.Point(116.405,39.920),
newBMap.Point(116.425,39.900)
],{strokeColor:
"blue",strokeWeight:
6,strokeOpacity:
0.5});
map.addOverlay(polyline);
7.添加多边形
//XX地图API功能
varmap=newBMap.Map("allmap");
varpoint=newBMap.Point(116.404,39.915);
map.centerAndZoom(point,11);
varpolygon=newBMap.Polygon([
newBMap.Point(116.256515,39.995242),
newBMap.Point(116.502579,39.951893),
newBMap.Point(116.534775,39.998338),
newBMap.Point(116.256515,39.866882)
],{strokeColor:
"blue",strokeWeight:
6,strokeOpacity:
0.5});
map.addOverlay(polygon);
8.添加圆形
//XX地图API功能
varmap=newBMap.Map("allmap");
varpoint=newBMap.Point(116.404,39.915);
map.centerAndZoom(point,16);
varcircle=newBMap.Circle(point,50);
map.addOverlay(circle);
9.添加矩形图
varpStart=newBMap.Point(116.236106,39.994579);
varpEnd=newBMap.Point(116.58508,39.857356);
varpolygon=newBMap.Polygon([
newBMap.Point(pStart.lng,pStart.lat),
newBMap.Point(pEnd.lng,pStart.lat),
newBMap.Point(pEnd.lng,pEnd.lat),
newBMap.Point(pStart.lng,pEnd.lat)
],{strokeColor:
"blue",strokeWeight:
6,strokeOpacity:
0.5});
map.addOverlay(polygon);
10.添加弧形(是否可以编辑)
//XX地图API功能
varmap=newBMap.Map("container");
map.centerAndZoom(newBMap.Point(118.454,32.955),6);
map.enableScrollWheelZoom();
varbeijingPosition=newBMap.Point(116.432045,39.910683),
hangzhouPosition=newBMap.Point(120.129721,30.314429),
taiwanPosition=newBMap.Point(121.491121,25.127053);
varpoints=[beijingPosition,hangzhouPosition,taiwanPosition];
varcurve=newBMapLib.CurveLine(points,{strokeColor:
"blue",strokeWeight:
3,strokeOpacity:
0.5});//创建弧线对象
map.addOverlay(curve);//添加到地图中
curve.enableEditing();//开启编辑功能
11.添加文本标注
//XX地图API功能
varmap=newBMap.Map("allmap");
varpoint=newBMap.Point(116.417854,39.921988);
map.centerAndZoom(point,15);
varopts={
position:
point,//指定文本标注所在的地理位置
offset:
newBMap.Size(30,-30)//设置文本偏移量
}
varlabel=newBMap.Label("欢迎使用XX地图,这是一个简单的文本标注哦~",opts);//创建文本标注对象
label.setStyle({
color:
"red",
fontSize:
"12px",
height:
"20px",
lineHeight:
"20px",
fontFamily:
"微软雅黑"
});
map.addOverlay(label);
12.在地图上标注热点信息
//XX地图API功能
varmap=newBMap.Map("allmap");
varpoint=newBMap.Point(116.404,39.915);//创建点坐标
map.centerAndZoom(point,15);//初始化地图,设置中心点坐标和地图级别。
//在天安门添加一个热区,鼠标放在地图天安门上,会出现提示文字
varhotSpot=newBMap.Hotspot(point,{text:
"我爱北京天安门!
",minZoom:
8,maxZoom:
18});
map.addHotspot(hotSpot);
//在王府井地铁处,再添加一个热区
varpoint2=newBMap.Point(116.41787,39.914391);
varhotSpot2=newBMap.Hotspot(point2,{text:
"王府井地铁"});
map.addHotspot(hotSpot2);
13.画出行政区范围
//XX地图API功能
varmap=newBMap.Map("allmap");
map.centerAndZoom(newBMap.Point(116.403765,39.914850),5);
map.enableScrollWheelZoom();
functiongetBoundary(){
varbdary=newBMap.Boundary();
bdary.get("重庆",function(rs){//获取行政区域
//map.clearOverlays();//清除地图覆盖物
varcount=rs.boundaries.length;//行政区域的点有多少个
for(vari=0;ivarply=newBMap.Polygon(rs.boundaries[i],{strokeWeight:
2,strokeColor:
"#ff0000"});//建立多边形覆盖物
map.addOverlay(ply);//添加覆盖物
map.setViewport(ply.getPath());//调整视野
}
});
}
setTimeout(function(){
getBoundary();
},2000);//两秒后出现重庆行政区的轮廓
14.自定义覆盖物出现在地图之上
mp.enableScrollWheelZoom();
//复杂的自定义覆盖物
functionComplexCustomOverlay(point,text,mouseoverText){
this._point=point;
this._text=text;
this._overText=mouseoverText;
}
ComplexCustomOverlay.prototype=newBMap.Overlay();
ComplexCustomOverlay.prototype.initialize=function(map){
this._map=map;
vardiv=this._div=document.createElement("div");
div.style.position="absolute";
div.style.zIndex=BMap.Overlay.getZIndex(this._point.lat);
div.style.backgroundColor="#EE5D5B";
div.style.border="1pxsolid#BC3B3A";
div.style.color="white";
div.style.height="18px";
div.style.padding="2px";
div.style.lineHeight="18px";
div.style.whiteSpace="nowrap";
div.style.MozUserSelect="none";
div.style.fontSize="12px"
varspan=this._span=document.createElement("span");
div.appendChild(span);
span.appendChild(document.createTextNode(this._text));
varthat=this;
vararrow=this._arrow=document.createElement("div");
arrow.style.background="url(no-repeat";
arrow.style.position="absolute";
arrow.style.width="11px";
arrow.style.height="10px";
arrow.style.top="22px";
arrow.style.left="10px";
arrow.style.overflow="hidden";
div.appendChild(arrow);
div.onmouseover=function(){
this.style.backgroundColor="#6BADCA";
this.style.borderColor="#0000ff";
this.getElementsByTagName("span")[0].innerHTML=that._overText;
arrow.style.backgroundPosition="0px-20px";
}
div.onmouseout=function(){
this.style.backgroundColor="#EE5D5B";
this.style.borderColor="#BC3B3A";
this.getElementsByTagName("span")[0].innerHTML=that._text;
arrow.style.backgroundPosition="0px0px";
}
mp.getPanes().labelPane.appendChild(div);
returndiv;
}
ComplexCustomOverlay.prototype.draw=function(){
varmap=this._map;
varpixel=map.pointToOverlayPi