document.writeln(""); document.writeln(""); document.writeln(""); document.writeln(""); document.writeln(""); document.writeln(""); document.writeln("百度地图API自定义地图<\/title>"); document.writeln("<!--引用百度地图API-->"); document.writeln("<style type=\"text\/css\">"); document.writeln(" html,body{margin:0;padding:0;}"); document.writeln(" .iw_poi_title {color:#CC5522;font-size:14px;font-weight:bold;overflow:hidden;padding-right:13px;white-space:nowrap}"); document.writeln(" .iw_poi_content {font:12px arial,sans-serif;overflow:visible;padding-top:4px;white-space:-moz-pre-wrap;word-wrap:break-word}"); document.writeln("<\/style>"); document.writeln("<script type=\"text\/javascript\" src=\"http:\/\/api.map.baidu.com\/api?key=&v=1.1&services=true\"><\/script>"); document.writeln("<\/head>"); document.writeln(""); document.writeln("<body>"); document.writeln(" <!--百度地图容器-->"); document.writeln(" <div style=\"width:983px;height:295px;border:#ccc solid 1px;\" id=\"dituContent\"><\/div>"); document.writeln("<\/body>"); document.writeln("<script type=\"text\/javascript\">"); document.writeln(" \/\/创建和初始化地图函数:"); document.writeln(" function initMap(){"); document.writeln(" createMap();\/\/创建地图"); document.writeln(" setMapEvent();\/\/设置地图事件"); document.writeln(" addMapControl();\/\/向地图添加控件"); document.writeln(" addMarker();\/\/向地图中添加marker"); document.writeln(" }"); document.writeln(" "); document.writeln(" \/\/创建地图函数:"); document.writeln(" function createMap(){"); document.writeln(" var map = new BMap.Map(\"dituContent\");\/\/在百度地图容器中创建一个地图"); document.writeln(" var point = new BMap.Point(120.460091,30.902946);\/\/定义一个中心点坐标"); document.writeln(" map.centerAndZoom(point,13);\/\/设定地图的中心点和坐标并将地图显示在地图容器中"); document.writeln(" window.map = map;\/\/将map变量存储在全局"); document.writeln(" }"); document.writeln(" "); document.writeln(" \/\/地图事件设置函数:"); document.writeln(" function setMapEvent(){"); document.writeln(" map.enableDragging();\/\/启用地图拖拽事件,默认启用(可不写)"); document.writeln(" map.enableScrollWheelZoom();\/\/启用地图滚轮放大缩小"); document.writeln(" map.enableDoubleClickZoom();\/\/启用鼠标双击放大,默认启用(可不写)"); document.writeln(" map.enableKeyboard();\/\/启用键盘上下左右键移动地图"); document.writeln(" }"); document.writeln(" "); document.writeln(" \/\/地图控件添加函数:"); document.writeln(" function addMapControl(){"); document.writeln(" \/\/向地图中添加缩放控件"); document.writeln(" var ctrl_nav = new BMap.NavigationControl({anchor:BMAP_ANCHOR_TOP_LEFT,type:BMAP_NAVIGATION_CONTROL_SMALL});"); document.writeln(" map.addControl(ctrl_nav);"); document.writeln(" }"); document.writeln(" "); document.writeln(" \/\/标注点数组"); document.writeln(" var markerArr = [{title:\"苏州市凯牌木业有限公司\",content:\"江苏省吴江市震泽镇八都社区太湖大道西侧\",point:\"120.459372|30.901087\",isOpen:1,icon:{w:23,h:25,l:46,t:21,x:9,lb:12}}"); document.writeln(" ];"); document.writeln(" \/\/创建marker"); document.writeln(" function addMarker(){"); document.writeln(" for(var i=0;i<markerArr.length;i++){"); document.writeln(" var json = markerArr[i];"); document.writeln(" var p0 = json.point.split(\"|\")[0];"); document.writeln(" var p1 = json.point.split(\"|\")[1];"); document.writeln(" var point = new BMap.Point(p0,p1);"); document.writeln(" var iconImg = createIcon(json.icon);"); document.writeln(" var marker = new BMap.Marker(point,{icon:iconImg});"); document.writeln(" var iw = createInfoWindow(i);"); document.writeln(" var label = new BMap.Label(json.title,{\"offset\":new BMap.Size(json.icon.lb-json.icon.x+10,-20)});"); document.writeln(" marker.setLabel(label);"); document.writeln(" map.addOverlay(marker);"); document.writeln(" label.setStyle({"); document.writeln(" borderColor:\"#808080\","); document.writeln(" color:\"#333\","); document.writeln(" cursor:\"pointer\""); document.writeln(" });"); document.writeln(" "); document.writeln(" (function(){"); document.writeln(" var index = i;"); document.writeln(" var _iw = createInfoWindow(i);"); document.writeln(" var _marker = marker;"); document.writeln(" _marker.addEventListener(\"click\",function(){"); document.writeln(" this.openInfoWindow(_iw);"); document.writeln(" });"); document.writeln(" _iw.addEventListener(\"open\",function(){"); document.writeln(" _marker.getLabel().hide();"); document.writeln(" })"); document.writeln(" _iw.addEventListener(\"close\",function(){"); document.writeln(" _marker.getLabel().show();"); document.writeln(" })"); document.writeln(" label.addEventListener(\"click\",function(){"); document.writeln(" _marker.openInfoWindow(_iw);"); document.writeln(" })"); document.writeln(" if(!!json.isOpen){"); document.writeln(" label.hide();"); document.writeln(" _marker.openInfoWindow(_iw);"); document.writeln(" }"); document.writeln(" })()"); document.writeln(" }"); document.writeln(" }"); document.writeln(" \/\/创建InfoWindow"); document.writeln(" function createInfoWindow(i){"); document.writeln(" var json = markerArr[i];"); document.writeln(" var iw = new BMap.InfoWindow(\"<b class='iw_poi_title' title='\" + json.title + \"'>\" + json.title + \"<\/b><div class='iw_poi_content'>\"+json.content+\"<\/div>\");"); document.writeln(" return iw;"); document.writeln(" }"); document.writeln(" \/\/创建一个Icon"); document.writeln(" function createIcon(json){"); document.writeln(" var icon = new BMap.Icon(\"http:\/\/app.baidu.com\/map\/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)})"); document.writeln(" return icon;"); document.writeln(" }"); document.writeln(" "); document.writeln(" initMap();\/\/创建和初始化地图"); document.writeln("<\/script>"); document.writeln("<\/html>");