var map,wgs=new WGSprojection();var map_zone=47;var isSouth=0;var c_minlong=1013899.66,c_maxlong=1058852.42,c_maxlat=189868.33,c_minlat=151921.19;var scale=new MapScale(169,142,1,1,c_minlong,c_maxlong,c_minlat,c_maxlat);function getTopLeft(obj){var curleft=curtop=0;if(obj.offsetParent){curleft=obj.offsetLeft;curtop=obj.offsetTop;while(obj=obj.offsetParent){curleft+=obj.offsetLeft;curtop+=obj.offsetTop;}}return{x:curleft,y:curtop};}function getCursorPos(e,obj){var _alt=getTopLeft(obj);var currX,currY,_x,_y;currX=(!document.all)?e.pageX:(event.clientX+(document.documentElement.scrollLeft||document.body.scrollLeft));currX-=_alt.x;currY=(!document.all)?e.pageY:(event.clientY+(document.documentElement.scrollTop||document.body.scrollTop));currY-=_alt.y;if(document.all){_x=event.clientX;_y=event.clientY;}else{_x=e.clientX;_y=e.clientY;}return{x:currX,y:currY,vx:_x,vy:_y};}function moveThumbnail(obj,e){var pos=getCursorPos(e,obj);document.getElementById("thumbNailControl").style.top=pos.y-7+"px";document.getElementById("thumbNailControl").style.left=pos.x-7+"px";}function move_star(e){if(document.getElementById('star')){var obj=document.getElementById('satelliteMapPane');var pos=getCursorPos(e,obj);var w=parseFloat(document.getElementById("star").style.width);var h=parseFloat(document.getElementById("star").style.height);document.getElementById("star").style.top=pos.y-(h/2)+"px";document.getElementById("star").style.left=pos.x-(w/2)+"px";}}var drag_thumbnail=false;function onmousedown_thumbnail(obj,e){if(moveToOtherMap(e,obj)){drag_thumbnail=true;}}function onmousemove_thumbnail(obj,e){if(drag_thumbnail==true){moveThumbnail(obj,e);}}function onmouseup_thumbnail(obj,e){if(drag_thumbnail==true){moveToOtherMap(e,obj);var pos=getCursorPos(e,obj);var vertex=scale.pixelToUtm(pos.x-5,pos.y-4);longlat=wgs.UTMToGeo(vertex.x,vertex.y,map_zone,isSouth);var lat=longlat[0];var long=longlat[1];map.setCenter(new GLatLng(lat,long),level_sat);;document.getElementById("last_pos").innerHTML="("+lat+","+long+")";moveThumbnail(obj,e);}drag_thumbnail=false;}function onmouseup_sat(){drag_thumbnail=false;var latlong=(document.getElementById("last_pos").innerHTML).split(",");var lat=latlong[0].replace("(","");var long=latlong[1].replace(")","");pos=wgs.GeoToUTM(lat,long,map_zone);var x=pos[0];var y=pos[1];var topLeft=scale.GetTopLeftPoint(x-600,y+1000,7,7);document.getElementById("thumbNailControl").style.top=topLeft.y+"px";document.getElementById("thumbNailControl").style.left=topLeft.x+"px";}function moveToOtherMap(e,obj){var pos=getCursorPos(e,obj);var base_url="http://"+location.hostname;var url_singapore=base_url+"/asia_travel/travel/travel_id_9797/travel_site_22985/";var url_mallaca=base_url+"/malaysia/malacca/travel/travel_id_8404/travel_site_151944/";if(pos.x>15&&pos.x<50&&pos.y>15&&pos.y<22){if(confirm("Are you sure go to Malacca map?"))window.location.href=url_mallaca;return false;}else if(pos.x>75&&pos.x<120&&pos.y>130&&pos.y<140){if(confirm("Are you sure go to Singapore map?"))window.location.href=url_singapore;return false;}return true;}function setFirstPositionLatLong(lat,long){pos=wgs.GeoToUTM(lat,long,map_zone);var x=pos[0];var y=pos[1];setFirstPositionFromXY(x,y);}function setFirstPositionFromXY(x,y){var topLeft=scale.GetTopLeftPoint(x-600,y+1000,7,7);document.getElementById("thumbNailControl").style.top=topLeft.y+"px";document.getElementById("thumbNailControl").style.left=topLeft.x+"px";}function MapScale(mapWidth,mapHeight,maxCol,maxRow,minLon,maxLon,minLat,maxLat,name_,desc,userScale,gridArray){this.mapWidth=mapWidth;this.mapHeight=mapHeight;this.maxCol=maxCol;this.maxRow=maxRow;this.minLon=minLon;this.maxLon=maxLon;this.minLat=minLat;this.maxLat=maxLat;this._name=name_;this.desc=desc;this.userScale=userScale;this.scaleValue=function(){var _scaleValue=(this.maxLon-this.minLon)/(this.maxCol*this.mapWidth);return _scaleValue;};this.pixelToUtm=function(x,y){var _scaleValue=this.scaleValue();return new Vertex((this.minLon)+(x*_scaleValue),(this.maxLat)-(y*_scaleValue));};this.utmToPixel=function(vertX,vertY){var result=new Point();var _scaleValue=this.scaleValue();result.x=Math.round((vertX-this.minLon)/_scaleValue);result.y=Math.round((this.maxLat-vertY)/_scaleValue);return result;};this.inflateVert=function(vert,x,y){var ptPixel=this.utmToPixel(vert.x,vert.y);ptPixel=OffsetPoint(ptPixel,x,y);return this.pixelToUtm(ptPixel.x,ptPixel.y);};this.GetDistance=function(vert0,vert1){if(isNaN(vert0.x)||isNaN(vert0.y)||isNaN(vert1.x)||isNaN(vert1.y))return;return Math.sqrt((vert0.x-vert1.x)*(vert0.x-vert1.x)+(vert1.y-vert0.y)*(vert1.y-vert0.y));};this.GetCenterVertex=function(){return this.pixelToUtm((this.maxCol*this.mapWidth)/2,(this.maxRow*this.mapHeight)/2);};this.GetTopLeftPoint=function(vertX,vertY,displayWidth,displayHeight){var pt=this.utmToPixel(vertX,vertY);pt=OffsetPoint(pt,-(displayWidth/2),-(displayHeight/2));return pt;};};function OffsetPoint(pt,x,y){var result=new Point();result.x=pt.x+x;result.y=pt.y+y;return result;};function Point(x,y){this.x=x;this.y=y;};function Vertex(x,y){this.x=x;this.y=y;};function WGSprojection(){this.a=6378137;this.b=6356752.3142;this.k0=0.9996;this.GeoToUTM=function(latitude,longitude,longitude_zone){var n=(this.a-this.b)/(this.a+this.b);var sin_1=Math.PI/(180.0*60.0*60.0);var e=Math.sqrt(1.0-Math.pow(this.b/this.a,2));var e_2=Math.pow(e,2)/(1.0-Math.pow(e,2));latitude=latitude*Math.PI/180;var nu=this.a/Math.sqrt(1-Math.pow(e*Math.sin(latitude),2));if(!longitude_zone)longitude_zone=31+parseInt((Math.floor(longitude/6)));var longitude_zone_cm=parseInt((6*longitude_zone)-183);var delta_long=(longitude-longitude_zone_cm);var p=delta_long*3600.0/10000.0;var Ax=this.a*(1-n+(5/4)*Math.pow(n,2)*(1-n)+(81/64)*Math.pow(n,4)*(1-n));var Bx=(3*this.a*n/2)*(1-n-(7/8)*Math.pow(n,2)*(1-n)+(55/64)*Math.pow(n,4));var Cx=(15*this.a*Math.pow(n,2)/16)*(1-n+(3/4)*Math.pow(n,2)*(1-n));var Dx=(35*this.a*Math.pow(n,3)/48)*(1-n+(11/16)*Math.pow(n,2));var Ex=(315*this.a*Math.pow(n,4)/51)*(1-n);var calMerArcLL=(Ax*latitude)-(Bx*Math.sin(2*latitude))+(Cx*Math.sin(4*latitude))-(Dx*Math.sin(6*latitude))+(Ex*Math.sin(8*latitude));var K1=calMerArcLL*this.k0;var K2=this.k0*(100000000)*Math.pow(sin_1,2)*nu*Math.sin(latitude)*Math.cos(latitude)/2;var K3=(this.k0*(10000000000000000)*Math.pow(sin_1,4)*nu*Math.sin(latitude)*Math.pow(Math.sin(latitude),3)/24)*((5-Math.pow(Math.tan(latitude),2)+9*e_2*Math.pow(Math.cos(latitude),2)+4*Math.pow(e_2,2)*Math.pow(Math.cos(latitude),4)));var K4=this.k0*10000*sin_1*nu*Math.cos(latitude);var K5=(this.k0*(1000000000000)*Math.pow(sin_1,3)*nu*Math.pow(Math.cos(latitude),3)/6)*(1-Math.pow(Math.tan(latitude),2)+e_2*Math.pow(Math.cos(latitude),2));var A6=(Math.pow(p*sin_1,6)*nu*Math.sin(latitude)*Math.pow(Math.cos(latitude),5)/720)*(61-58*Math.pow(Math.tan(latitude),2)+Math.pow(Math.tan(latitude),4)+270*e_2*Math.pow(Math.cos(latitude),2)-330*e_2*Math.pow(Math.sin(latitude),2))*this.k0*Math.pow(10,24);var y=K1+(K2*Math.pow(p,2))+(K3*Math.pow(p,4))+(A6*Math.pow(p,6));if(y<0)y=y+10000000;var x=(K4*p)+(K5*Math.pow(p,3))+500000;return Array(x,y);};this.UTMToGeo=function(x,y,longitude_zone,isSouth){var e=Math.sqrt(1.0-Math.pow(this.b/this.a,2));var e_2=Math.pow(e,2)/(1.0-Math.pow(e,2));x=500000-x;var yy=y;if(isSouth)y=10000000-y;var longintude_zone_cm=6*longitude_zone-183;var calMerArcUTM=y/this.k0;var mu=calMerArcUTM/(this.a*(1.0-Math.pow(e,2)/4.0-3.0*Math.pow(e,4)/64.0-5.0*Math.pow(e,6)/256.0));var E1=(1.0-Math.sqrt((1.0-Math.pow(e,2))))/(1.0+Math.sqrt((1.0-Math.pow(e,2))));var J1=(3.0*E1/2.0-27.0*Math.pow(E1,3)/32.0);var J2=(21.0*Math.pow(E1,2)/16.0-55.0*Math.pow(E1,4)/32.0);var J3=(151.0*Math.pow(E1,3)/96.0);var J4=(1097.0*Math.pow(E1,4)/512.0);var fp=mu+J1*Math.sin(2.0*mu)+J2*Math.sin(4.0*mu)+J3*Math.sin(6.0*mu)+J4*Math.sin(8.0*mu);var C1=e_2*Math.pow(Math.cos(fp),2);var T1=Math.pow(Math.tan(fp),2);var R1=this.a*(1.0-Math.pow(e,2))/Math.pow((1.0-Math.pow(e,2)*Math.pow(Math.sin(fp),2)),(3.0/2.0));var N1=this.a/Math.sqrt((1.0-Math.pow(e*Math.sin(fp),2)));var D=x/(N1*this.k0);var Q1=N1*Math.tan(fp)/R1;var Q2=(Math.pow(D,2)/2.0);var Q3=(5.0+3.0*T1+10.0*C1-4.0*Math.pow(C1,2)-9.0*e_2)*Math.pow(D,4)/24.0;var Q4=(61.0+90.0*T1+298.0*C1+45.0*Math.pow(T1,2)-3.0*Math.pow(C1,2)-252.0*e_2)*Math.pow(D,6)/720.0;var Q5=D;var Q6=(1.0+2.0*T1+C1)*Math.pow(D,3)/6.0;var Q7=(5.0-2.0*C1+28.0*T1-3.0*Math.pow(C1,2)+8.0*e_2+24.0*Math.pow(T1,2))*Math.pow(D,5)/120.0;latitude=180.0*(fp-Q1*(Q2-Q3+Q4))/Math.PI;if(isSouth)latitude=latitude*-1.0;longitude=longintude_zone_cm-((Q5-Q6+Q7)/Math.cos(fp))*180.0/Math.PI;return Array(latitude,longitude)};}
