需要注意的地方:
1、 地图控件不能放在table中,否则出错
2、 页面不能包含服务器控件,否则出错
3、 控件如果不设置宽、高,默认不出现
操作小结:
1、地图初始化:
map = new BMap.Map("l-map") map.centerAndZoom("西安市", 12); map.enableScrollWheelZoom(); map.addControl(new BMap.OverviewMapControl()); //添加默认缩略地图控件 map.addControl(new BMap.OverviewMapControl({ isOpen: true, anchor: BMAP_ANCHOR_BOTTOM_LEFT })); map.addControl(new BMap.NavigationControl({ anchor: BMAP_ANCHOR_TOP_RIGHT })); //添加默认缩放平移控件
2、创建自定义标准:
var truckpoint = new BMap.Point(0, 0); var myIcon = new BMap.Icon("../../Img/bus.png", new BMap.Size(48, 48)); var marker = new BMap.Marker(truckpoint, { icon: myIcon }); // 创建标注 marker.setTitle(oJson[i].Truck[j].TruckCode); map.addOverlay(marker);
3、画线:
var CarsListInfo = []; LineListInfo = eval(data); for (var o = 0; o < LineListInfo.length; o++) { for (var i = 0; i < LineListInfo[o].TransportTask.length; i++) { var line = []; if (LineListInfo[o].TransportTask[i].LinePoint != null) { for (var j = 0; j < LineListInfo[o].TransportTask[i].LinePoint.length; j++) { var point = new BMap.Point(LineListInfo[o].TransportTask[i].LinePoint[j].PointJD, LineListInfo[o].TransportTask[i].LinePoint[j].PointWD); line.push(point); } var bb = new BMap.Polyline(line, { strokeColor: "blue", strokeWeight: 3, strokeOpacity: 0.5 }); //绘制经纬度点数组 map.addOverlay(bb); } } }
4、查找指定的标注(根据标注标题查找)
var markers = map.getOverlays(); for (var m = 0; m < markers.length; m++) { if (markers[m].z.title != undefined) { if (markers[m].z.title == CarsListInfo[i].TruckCode) { }}}
5、删除所有线
var markers = map.getOverlays(); for (var m = 0; m < markers.length; m++) { if (markers[m].$ != undefined) { map.removeOverlay(markers[m]); } }