<div class="codetitle"> <span><a style="CURSOR: pointer" data="622" class="copybut" id="copybut622" onclick="doCopy('code622')"><u>复制代码</u></a></span> 代码如下:</div> <div class="codebody" id="code622"> <br><script language="javascript" type="text/javascript"> <BR>//add by ahuinan 2009-8-17 <BR>//initialize(23.165613663312594,113.35968017578125) <BR>var map; <BR>var gdir; <BR>var marker2; <BR>var hasMarker = false; <BR>var hotelLatLng = new GLatLng(<%=initxy %>);//初始化酒店的坐标 <BR>var polyline; <BR>var points = []; <BR>points[1] = hotelLatLng; <BR>function initialize() { <BR>if (GBrowserIsCompatible()) { <BR>map = new GMap2(document.getElementById("divMap"), { googleBarOptions: { showOnLoad: true} }); <BR>gdir = new GDirections(map); <BR>map.setCenter(hotelLatLng, 9); <BR>map.addControl(new GOverviewMapControl()); <BR>map.addControl(new GLargeMapControl()); <br><br>//加入搜索框 <BR>map.enableGoogleBar(); <br><br>map.enableScrollWheelZoom(); <br><br>//创建酒店的标注,不可拖动 <BR>var hotelMarker = new GMarker(new GLatLng(<%=initxy %>)); <BR>map.addOverlay(hotelMarker); <br><br>//鼠标左键可以建立一个标记, <BR>GEvent.addListener(map,"click",function(overlay,latlng,overlaylatlng){ <BR>if(latlng == null || hasMarker == true){ <BR>return; <BR>} <BR>var greenIcon = new GIcon(G_DEFAULT_ICON); <BR>greenIcon.image = "../googlemap/green-dot.png"; <BR>greenIcon.iconSize = new GSize(32,32); <BR>greenIcon.iconAnchor = new GPoint(16,32); <BR>greenIcon.shadowSize=new GSize(56,33); <BR>marker2 = new GMarker(latlng,{draggable: true,icon:greenIcon}); <BR>map.addOverlay(marker2); <br><br>GEvent.addListener(marker2,"dragend",function(){ <BR>points[0] = marker2.getLatLng(); <BR>gdir.loadFromWaypoints(points,{"preserveViewport":true}); <br><br><br><br>}) <BR>GEvent.addListener(gdir, "addoverlay", function(){ <BR>for (var i=0; i<=gdir.getNumRoutes(); i++){ <BR>var originalMarker = gdir.getMarker(i); <BR>map.removeOverlay(originalMarker); <BR>} <BR>polyline = gdir.getPolyline(); <br><br><BR>polyline.setStrokeStyle({color:"red",weight:2,opacity:1}); <BR>// map.addOverlay(polyline); <br><br>}); <BR>hasMarker = true; <BR>points[0] = latlng; <BR>gdir.loadFromWaypoints(points,{"preserveViewport":true}); <br><br>}) <BR>} <BR>} <BR>//按下添加按钮 <BR>function add(){ <BR>if(points.length == 1){ <BR>alert("没有线路,终止操作"); <BR>}else{ <BR>window.opener.document.getElementById("txtHI_MapMarkDesc").value = window.opener.document.getElementById("txtHI_MapMarkDesc").value+"\n"+document.getElementById("txtName").value+"||||"+document.getElementById("txtType").value+"||||"+points[0]+"\n"; <BR>window.close(); <BR>} <BR>} <BR>window.onload = function() { <BR>initialize() <BR>} <BR></script> <br> </div>