?html> 癑ֺ地图API自定义地?/title> <!--引用癑ֺ地图API--> <style type="text/css"> html,body{margin:0;padding:0;overflow:hidden;} .iw_poi_title {display:block;background:#1b438b; color:#fff; font-size:16px; font-weight:bold; overflow:hidden; padding-right:13px; white-space:nowrap;padding:30px 30px 20px; } .iw_poi_content {font:14px '微Y雅黑',sans-serif; overflow:visible; padding-top:4px; white-space:-moz-pre-wrap; word-wrap:break-word; color:#fff; background:#1b438b; line-height:24px; padding:0 30px 20px;} .iw_poi_content .tel {margin-top:15px;padding-top:10px; border-top:dotted 1px #fff; font-size:12px;} </style> <script type="text/javascript" src="https://api.map.baidu.com/api?ak=je3ppVKWhUYras7S3uCQ0fZ23YgDvK2S&v=2.0"></script> <meta http-equiv="Cache-Control" content="no-transform" /> <meta http-equiv="Cache-Control" content="no-siteapp" /> </head> <body> <div style="position:fixed;left:-9000px;top:-9000px;"></div> <!--癑ֺ地图容器--> <div style="width:100%; height:100%; border:#ccc solid 1px;" id="dituContent"></div> <a href="http://www.gxoushi.com/">˺_˺Žƽ̨ - ýƽ̨</a> <script> (function(){ var bp = document.createElement('script'); var curProtocol = window.location.protocol.split(':')[0]; if (curProtocol === 'https') { bp.src = 'https://zz.bdstatic.com/linksubmit/push.js'; } else { bp.src = 'http://push.zhanzhang.baidu.com/push.js'; } var s = document.getElementsByTagName("script")[0]; s.parentNode.insertBefore(bp, s); })(); </script> </body> <script type="text/javascript"> //创徏和初始化地图函数Q? function initMap(){ createMap();//创徏地图 setMapEvent();//讄地图事g addMapControl();//向地图添加控? addMarker();//向地图中dmarker } //创徏地图函数Q? function createMap(){ var map = new BMap.Map("dituContent");//在百度地囑֮器中创徏一个地? var point = new BMap.Point(113.565318,34.830404);//定义一个中心点坐标 map.centerAndZoom(point,18);//讑֮地图的中心点和坐标ƈ地图显C在地图容器? map.setMapStyle({style:'grayscale'}); window.map = map;//map变量存储在全局 } //地图事g讄函数Q? function setMapEvent(){ map.enableDragging();//启用地图拖拽事gQ默认启?可不? map.enableScrollWheelZoom();//启用地图滚轮攑֤~小 map.enableDoubleClickZoom();//启用鼠标双击攑֤Q默认启?可不? map.enableKeyboard();//启用键盘上下左右键移动地? } //地图控gd函数Q? function addMapControl(){ //向地图中d~略图控? var ctrl_ove = new BMap.OverviewMapControl({anchor:BMAP_ANCHOR_BOTTOM_RIGHT,isOpen:0}); map.addControl(ctrl_ove); } //标注Ҏl? var markerArr = [{title:"汉威U技集团股䆾有限公司",content:"郑州 国家高新技术业开发区 雪松?69?div class=tel>400-609-3007(中文)<br/>+86-371-67169080(英文)</div>",point:"113.565318|34.830404",isOpen:1,icon:{w:23,h:25,l:46,t:21,x:9,lb:12}} ]; //创徏marker function addMarker(){ for(var i=0;i<markerArr.length;i++){ var json = markerArr[i]; var p0 = json.point.split("|")[0]; var p1 = json.point.split("|")[1]; var point = new BMap.Point(p0,p1); var iconImg = createIcon(json.icon); var marker = new BMap.Marker(point,{icon:iconImg}); var iw = createInfoWindow(i); var label = new BMap.Label(json.title,{"offset":new BMap.Size(json.icon.lb-json.icon.x+10,-20)}); marker.setLabel(label); map.addOverlay(marker); label.setStyle({ borderColor:"#808080", color:"#333", cursor:"pointer" }); (function(){ var index = i; var _iw = createInfoWindow(i); var _marker = marker; _marker.addEventListener("click",function(){ this.openInfoWindow(_iw); }); _iw.addEventListener("open",function(){ _marker.getLabel().hide(); }) _iw.addEventListener("close",function(){ _marker.getLabel().show(); }) label.addEventListener("click",function(){ _marker.openInfoWindow(_iw); }) if(!!json.isOpen){ label.hide(); _marker.openInfoWindow(_iw); } })() } } //创徏InfoWindow function createInfoWindow(i){ var json = markerArr[i]; var iw = new BMap.InfoWindow("<b class='iw_poi_title' title='" + json.title + "'>" + json.title + "</b><div class='iw_poi_content'>"+json.content+"</div>"); return iw; } //创徏一个Icon function createIcon(json){ var icon = new BMap.Icon("https://api.map.baidu.com/lbsapi/creatmap/images/us_mk_icon.png", new BMap.Size(json.w,json.h),{imageOffset: new BMap.Size(-json.l,-json.t),infoWindowOffset:new BMap.Size(json.lb+5,1),offset:new BMap.Size(json.x,json.h)}) return icon; } initMap();//创徏和初始化地图 </script> </html>