singrdk/base/Applications/WebApps/MapDemo/MapControl.js

15 lines
82 KiB
JavaScript
Raw Normal View History

2008-11-17 18:29:00 -05:00
// Copyright 2005 Microsoft Corporation
function ap(b){return b?b:window.event;}function aC(b){b.cancelBubble=true;}function G(b){b=ap(b);aC(b);return false;}function bh(b){var gj=0;if(b.pageX){gj=b.pageX;}else if(b.clientX){if(document.documentElement&&document.documentElement.scrollLeft){gj=b.clientX+document.documentElement.scrollLeft;}else if(document.body){gj=b.clientX+document.body.scrollLeft;}}return gj;}function ca(b){var gk=0;if(b.pageY){gk=b.pageY;}else if(b.clientY){if(document.documentElement&&document.documentElement.scrollTop){gk=b.clientY+document.documentElement.scrollTop;}else if(document.body){gk=b.clientY+document.body.scrollTop;}}return gk;}function kp(b){if(b.wheelDelta){return b.wheelDelta;}else if(b.detail){return-b.detail;}return 0;}function rD(b){if(!b){b=window.event;}var T=null;if(b.srcElement){T=b.srcElement;}else if(b.target){T=b.target;}if(T&&T.nodeType){if(T.nodeType==3){T=rk.parentNode;}}return T;}function hZ(cU){var cn=cU;var jg=0;while(cn){jg+=cn.offsetLeft;cn=cn.offsetParent;}if(navigator.userAgent.indexOf("Mac")!=-1&&typeof(document.body.leftMargin)!="undefined"){jg+=document.body.leftMargin;}return jg;}function gh(cU){var cn=cU;var iZ=0;while(cn){iZ+=cn.offsetTop;cn=cn.offsetParent;}if(navigator.userAgent.indexOf("Mac")!=-1&&typeof(document.body.topMargin)!="undefined"){iZ+=document.body.topMargin;}return iZ;}function ak(d){return Math.floor(d);}function cx(d){return Math.ceil(d);}function dJ(d,f){return Math.max(d,f);}function dX(d,f){return Math.min(d,f);}function aZ(d){return Math.abs(d);}function aj(d){return Math.round(d);}function cw(az){return az*Math.PI/180.0;}function gL(oG){return oG*180.0/Math.PI;}function lS(ah,X){if(!ah||!X||ah[0].length!=X.length){return;}var p=ah.length;var q=X[0].length;var aU=new Array(p);var bc=X.length;for(var a=0;a<p;a++){aU[a]=new Array(q);for(var Y=0;Y<q;Y++){aU[a][Y]=0;for(var gu=0;gu<bc;gu++){aU[a][Y]+=ah[a][gu]*X[gu][Y];}}}return aU;}function RegisterNamespaces(){for(var a=0;a<arguments.length;a++){var gv=arguments[a].split(".");var gX=window;for(var Y=0;Y<gv.length;Y++){if(!gX[gv[Y]]){gX[gv[Y]]=new Object();}gX=gX[gv[Y]];}}}RegisterNamespaces("Msn.VE");
Msn.VE.MapControl=function(y,V){var eJ=20971520;var js=163840;var bH=0;var dV=true;var cg=6;var mo=15;var mf=15;var bm=6378137;var fX=bm*2.0*Math.PI;var fC=fX*0.5;var fG=1;var fh=19;var ri="http://virtualearth.msn.com/i/spacer.gif";var jR=-85;var jW=85;var km=-180;var lO=180;var M=256;var ej=new Object();var oE=0;var om=0;var mj=1;var lP=1;var fZ=2;var nv=3;var fZ=11;var pX=20;var h=this;var cY='r';var eq='h';var eT='a';var aS='o';var c=new Msn.VE.MapView();var au=new Msn.VE.MapView();var kP=1;var pw=null;var hY=15;var iM=cY;var d=0,f=0,q=0,p=0;var K=new Array();var cD=null;var I=0,H=0;var af=0,ag=0;var bV=0,bL=0;var ci=0,ck=0;var aB=0,cb=0;var cR=false;var iH=false;var iF=0,iC=0;var bi=false;var cG=0;var aQ=false;var gB=0;var fA=0,fB=0;var eI=null,fH=null;var an=new Array();var bk=new Array();var j=document.createElement("div");var bY=document.createElement("input");bY.id="wl_ve_mapInput";var di=null;var bN=null;var cs=null;var R=null;var eC=null;var cE=null;var dE=null;var df=null;var dp=null;var z=null;var x=null;var hu=null;var dk=new Array();var ga=false;this.Init=function(){ej[cY]=15;ej[eT]=15;ej[eq]=15;ej[aS]=14;dp=new py();dp.Init();if(V.obliqueEnabled&&V.obliqueUrl){z=new qP();z.Init(V.obliqueUrl);}jj();j.className="Map";j.style.zIndex=mj;y.appendChild(j);bY.className="KeyboardInput";y.appendChild(bY);if(!V.fixedView){cE=new nu();cE.Init();dE=new oT();dE.Init();df=dE;y.attachEvent("onmousedown",dc);y.attachEvent("onmouseup",bt);y.attachEvent("onmousemove",cz);y.attachEvent("onmousewheel",er);y.attachEvent("ondblclick",mM);y.attachEvent("oncontextmenu",lH);bY.attachEvent("onkeydown",mL);bY.attachEvent("onkeyup",jl);if(window.addEventListener&&navigator.product&&navigator.product=="Gecko"){y.addEventListener("DOMMouseScroll",er,false);}bH=M;}if(V.buffer!=undefined&&V.buffer!=null){bH=V.buffer;}if(V.latitude&&V.longitude&&V.zoomlevel&&V.mapstyle){try{var gA=new Msn.VE.MapView();gA.SetMapStyle(lK(V.mapstyle),V.obliqueSceneId);gA.SetZoomLevel(eval(V.zoomlevel));gA.SetCenterLatLong(new Msn.VE.LatLong(eval(V.latitude),eval(V.longitude)));av(gA);}catch(dw){kX();}}else{kX();}if(!V.disableLogo){di=new oa(y);di.Init();}cs=new nI(y);cs.Init();if(V.showScaleBar){bN=new ov(y);bN.Init();eu("onendzoom",bN.Update);eu("onendcontinuouspan",bN.Update);eu("onresize",bN.Reposition);}if(V.showDashboard){pa(V.dashboardX,V.dashboardY,V.dashboardSize);}if(z&&x!=z){z.UpdateAvailability();}};this.GetDashboard=function(){return eC;};this.Destroy=function(){if(!V.fixedView){y.detachEvent("onmousedown",dc);y.detachEvent("onmouseup",bt);y.detachEvent("onmousemove",cz);y.detachEvent("onmousewheel",er);y.detachEvent("ondblclick",mM);y.detachEvent("oncontextmenu",lH);bY.detachEvent("onkeydown",mL);bY.detachEvent("onkeyup",jl);}while(K.length>0){var ad=K.pop();ad.RemoveFromMap();}K=null;while(an.length){an.pop().Destroy();}an=null;ju();if(eC){eC.Destroy();eC=null;}if(R){R.detachEvent("onmousedown",G);R.detachEvent("onmouseup",G);R.detachEvent("onmousemove",G);R.detachEvent("onmousewheel",G);R.detachEvent("ondblclick",G);R.detachEvent("oncontextmenu",G);R.detachEvent("onkeydown",G);R.detachEvent("onkeyup",G);y.removeChild(R);R=null;}if(bN){ee("onendzoom",bN.Update);ee("onendcontinuouspan",bN.Update);ee("onresize",bN.Reposition);bN.Destroy();bN=null;}if(di){di.Destroy();di=null;}if(cs){cs.Destroy();cs=null;}if(dp){dp.Destroy();dp=null;}if(z){z.Destroy();z=null;}if(cE){cE.Destroy();cE=null;}if(dE){dE.Destroy();dE=null;}mR();y=h=null;};function jj(){d=hZ(y);f=gh(y);q=y.offsetWidth;p=y.offsetHeight;}function pa(d,f,aT){if(!aT){aT=Msn.VE.DashboardSize.Normal;}if(aT==Msn.VE.DashboardSize.Tiny){aT=Msn.VE.DashboardSize.Small;}R=document.createElement("div");y.appendChild(R);R.className="Dashboard Dashboard_"+aT;R.style.top=f+"px";R.style.left=d+"px";R.attachEvent("onmousedown",G);R.attachEvent("onmouseup",G);R.attachEvent("onmousemove",G);R.attachEvent("onmousewheel",G);R.attachEvent("ondblclick",G);R.attachEvent("oncontextmenu",G);R.attachEvent("onkeydown",G);R.attachEvent("onkeyup",G);eC=new Msn.VE.Dashboard(R,h,aT);eC.Init();}function kX(){var e=new Ms
Msn.VE.Bounds=function(fd,eY,C,B,O,P){this.z1=fd;this.z2=eY;this.x1=C;this.y1=B;this.x2=O;this.y2=P;};
Msn.VE.Dashboard=function(i,j,aT){var gE=document.createElement("div");var gw=document.createElement("div");var dO=document.createElement("div");var gp=null;var jI=document.createElement("hr");var be=document.createElement("div");var cr=document.createElement("input");var kh=true;var bq=null;var dr=null;var em=null;var de=null;var bG=null;var ch=null;var hX=document.createElement("table");hX.className="dashboardContainerTable";var iS=document.createElement("tbody");var iG=document.createElement("tr");hX.appendChild(iS);iS.appendChild(iG);var ig=document.createElement("td");var dT=document.createElement("td");dT.vAlign="top";var dL=document.createElement("td");dL.colSpan=2;dL.setAttribute("colspan",2);dL.className="obliqueSelectorTable";iG.appendChild(ig);iG.appendChild(dT);var kS=document.createElement("tr");kS.appendChild(dL);iS.appendChild(kS);this.Init=function(){var Z=j.GetMapStyle();iD(gE,"road",mH);iD(gw,"aerial",lJ);iD(dO,"bird's eye",iL);jI.className="Dashboard_separator";i.appendChild(jI);i.appendChild(hX);if(!aT||aT==Msn.VE.DashboardSize.Normal){bq=new ql(ig,5,30);bq.Init();bq.Show();}dr=new pi(ig);dr.Hide();em=new qt(dT,100,30);em.Init();de=new pH(dT);oR();nS();ch=new nU(dL);ch.Init();j.AttachEvent("onendzoom",me);j.AttachEvent("onobliqueenter",mz);j.AttachEvent("onobliqueleave",jO);j.AttachEvent("onchangemapstyle",ks);j.AttachEvent("onobliquechange",nN);if(j.IsObliqueAvailable()){mK();}else{jM();}switch(Z){case'r':kM();break;case'a':case'h':mx();break;case'o':mq();break;}};this.Destroy=function(){hD(gE,mH);hD(gw,lJ);hD(dO,iL);gp=gE=gw=dO=null;be.removeChild(cr);dT.removeChild(be);be.detachEvent("onclick",kY);be=cr=null;if(bq){bq.Destroy();bq=null;}if(de){de.Destroy();de=null;}if(ch){ch.Destroy();ch=null;}if(j){j.DetachEvent("onendzoom",me);j.DetachEvent("onobliqueenter",mz);j.DetachEvent("onobliqueleave",jO);j.DetachEvent("onchangemapstyle",ks);j=null;}};this.GetY=function(){return gh(i);};this.GetHeight=function(){return i.offsetHeight;};function iD(bI,aR,cX,rz){bI.className="Dashboard_tab Dashboard_unselected";bI.href="javascript:void(0)";bI.innerText=aR;bI.attachEvent("onclick",cX);i.appendChild(bI);}function hD(bI,cX){bI.detachEvent("onclick",cX);i.removeChild(bI);}function je(bI){if(gp){gp.className="Dashboard_tab Dashboard_unselected";}bI.className="Dashboard_tab Dashboard_selected";gp=bI;}function oR(){cr.type="checkbox";be.className="Dashboard_toggler";be.style.display="none";be.attachEvent("onclick",kY);be.appendChild(cr);be.appendChild(document.createTextNode("Show labels"));dT.appendChild(be);}function nS(){bG=document.createElement("div");bG.className="Dashboard_notification";bG.innerHTML="<div id=\"obliqueNotifyIcon\">&nbsp;</div> There is Bird's Eye imagery available for this location.";bG.style.display="none";bG.onclick=iL;dL.appendChild(bG);}function kM(){je(gE);be.style.display="none";ch.Hide();de.Hide();em.Show();if(j.IsObliqueAvailable()){bG.style.display="block";}if(bq){bq.Show();}dr.Hide();}function mx(){je(gw);be.style.display="block";ch.Hide();de.Hide();em.Show();if(j.GetMapStyle()=='h'){cr.checked=true;}else{cr.checked=false;}if(j.IsObliqueAvailable()){bG.style.display="block";}if(bq){bq.Show();}dr.Hide();}function mq(){je(dO);be.style.display="none";bG.style.display="none";ch.Show();em.Hide();de.Show();if(bq){bq.Hide();}dr.Show();}function mK(){dO.className="Dashboard_tab Dashboard_unselected";bG.style.display="block";}function jM(){dO.className="Dashboard_tab Dashboard_disabled";bG.style.display="none";}function mH(){j.SetMapStyle('r');}function lJ(){if(kh||cr.checked){j.SetMapStyle('h');}else{j.SetMapStyle('a');}kh=false;}function iL(){j.SetMapStyle('o');}function kY(b){var Z=j.GetMapStyle();if(Z=='a'){j.SetMapStyle('h');cr.checked=true;}else if(Z=='h'){j.SetMapStyle('a');cr.checked=false;}}function me(b){em.UpdateFromMap();de.UpdateFromMap();}function mz(b){if(j.GetMapStyle()=="o"){return;}mK();dr.UpdateFromMap();}function jO(b){jM();}function ks(b){switch(b.view.mapStyle){case'r':kM();break;case'a':case'h':mx();break;case'o':mq();break;}}function nN(b){ch.Update();dr.UpdateFromMa
Msn.VE.DashboardSize=new function(){this.Normal="normal";this.Small="small";this.Tiny="tiny";};
Msn.VE.LatLong=function(A,L){this.latitude=A;this.longitude=L;this.ToString=function(){return"("+this.latitude+", "+this.longitude+")";};this.Copy=function(o){if(!o){return;}this.latitude=o.latitude;this.longitude=o.longitude;};};
Msn.VE.LatLongRectangle=function(iz,hr){this.northwest=iz;this.southeast=hr;this.ToString=function(){return"("+(this.northwest?this.northwest.ToString():"null")+", "+(this.southeast?this.southeast.ToString():"null")+")";};this.Copy=function(bA){if(!bA){return;}if(!this.northwest){this.northwest=new Msn.VE.LatLong();}if(!this.southeast){this.southeast=new Msn.VE.LatLong();}this.northwest.Copy(bA.northwest);this.southeast.Copy(bA.southeast);};this.Center=function(){var eU=Math.sin(this.northwest.latitude*Math.PI/180.0);var eK=Math.sin(this.southeast.latitude*Math.PI/180.0);var rf=0.25*(Math.log((1.0+eU)/(1.0-eU))+Math.log((1.0+eK)/(1.0-eK)));var bU=new Msn.VE.LatLong();bU.latitude=Math.atan(Math.exp(rf))*360.0/Math.PI-90.0;bU.longitude=0.5*(this.northwest.longitude+this.southeast.longitude);return bU;};this.Contains=function(o){return o.latitude<=iz.latitude&&o.longitude>=iz.longitude&&o.latitude>=hr.latitude&&o.longitude<=hr.longitude;};};
Msn.VE.MapStyle=new function(){this.Road="r";this.Aerial="a";this.Hybrid="h";this.Oblique="o";};
Msn.VE.MapView=function(){this.zoomLevel=0;this.mapStyle=null;this.center=new Msn.VE.Pixel();this.latlong=new Msn.VE.LatLong();this.pixelRect=new Msn.VE.PixelRectangle();this.latlongRect=new Msn.VE.LatLongRectangle();this.sceneId=null;this.sceneOrientation=null;var h=this;var bE="pixel";this.Destroy=function(){this.center=this.latlong=h=null;};this.GetViewType=function(){return bE;};function qM(){var ky=new Msn.VE.MapView();ky.Copy(h);return ky;}function np(e){h.zoomLevel=e.zoomLevel;h.mapStyle=e.mapStyle;h.center.Copy(e.center);h.latlong.Copy(e.latlong);h.pixelRect.Copy(e.pixelRect);h.latlongRect.Copy(e.latlongRect);h.sceneId=e.sceneId;h.sceneOrientation=e.sceneOrientation;bE=e.GetViewType();}function mU(e){return e!=null&&h.zoomLevel==e.zoomLevel&&h.mapStyle==e.mapStyle&&aZ(h.center.x-e.center.x)<0.000001&&aZ(h.center.y-e.center.y)<0.000001&&h.sceneId==e.sceneId&&h.sceneOrientation==e.sceneOrientation;}function iQ(){return"("+h.latlong.ToString()+", "+h.zoomLevel+", "+h.mapStyle+")";}function hn(l){if(!l){return;}h.center=l;bE="pixel";}function qy(o){if(!o){return;}h.latlong=o;bE="latlong";}function pG(mS){h.pixelRect=mS;bE="pixelRect";}function rd(nx){h.latlongRect=nx;bE="latlongRect";}function kt(m){if(m<=0){return;}switch(bE){case"pixel":var ab=Math.pow(2,m-h.zoomLevel);h.center.x*=ab;h.center.y*=ab;break;case"pixelRect":var ab=Math.pow(2,m-h.zoomLevel);h.pixelRect.topLeft.x*=ab;h.pixelRect.topLeft.y*=ab;h.pixelRect.bottomRight.x*=ab;h.pixelRect.bottomRight.y*=ab;break;}h.zoomLevel=m;}function cc(Z,bS,il){h.mapStyle=Z;if(bE=="pixel"){bE="latlong";}if(Z!='o'){h.sceneId=null;h.sceneOrientation=null}else{h.sceneId=bS;h.sceneOrientation=il;}}function hK(m){if(m){return h.center.x*Math.pow(2,m-h.zoomLevel);}return h.center.x;}function hJ(m){if(m){return h.center.y*Math.pow(2,m-h.zoomLevel);}return h.center.y;}function oX(m){if(m==undefined){return h.center;}return new Msn.VE.Pixel(h.GetX(m),h.GetY(m));}function rg(bd,q,p){switch(bE){case"pixel":h.latlong=bd.PixelToLatLong(h.center,h.zoomLevel);break;case"latlong":h.center=bd.LatLongToPixel(h.latlong,h.zoomLevel);break;case"pixelRect":hR(bd,q,p);break;case"latlongRect":if(h.mapStyle=="o"){h.zoomLevel=1;var g=bd.GetScene();if(!g.ContainsLatLong(h.latlongRect.northwest)||!g.ContainsLatLong(h.latlongRect.southeast)){h.latlong=h.latlongRect.Center();h.center=bd.LatLongToPixel(h.latlong,h.zoomLevel);}else{h.pixelRect.topLeft=bd.LatLongToPixel(h.latlongRect.northwest,h.zoomLevel);h.pixelRect.bottomRight=bd.LatLongToPixel(h.latlongRect.southeast,h.zoomLevel);hR(bd,q,p);}}else{h.zoomLevel=12;h.pixelRect.topLeft=bd.LatLongToPixel(h.latlongRect.northwest,h.zoomLevel);h.pixelRect.bottomRight=bd.LatLongToPixel(h.latlongRect.southeast,h.zoomLevel);hR(bd,q,p);}break;}bE="pixel";}function hR(bd,q,p){var hS=19;var U=Math.pow(2,hS-h.zoomLevel);var pf=dJ(1,aZ(h.pixelRect.topLeft.x-h.pixelRect.bottomRight.x)*U);var qU=dJ(1,aZ(h.pixelRect.topLeft.y-h.pixelRect.bottomRight.y)*U);var lZ=Math.log(2);var qg=hS-Math.ceil(Math.log(pf/q)/lZ);var pv=hS-Math.ceil(Math.log(qU/p)/lZ);var bf=dX(qg,pv);U=Math.pow(2,bf-h.zoomLevel);h.center.x=0.5*(h.pixelRect.topLeft.x+h.pixelRect.bottomRight.x)*U;h.center.y=0.5*(h.pixelRect.topLeft.y+h.pixelRect.bottomRight.y)*U;h.zoomLevel=bf;h.latlong=bd.PixelToLatLong(h.center,h.zoomLevel);}this.MakeCopy=qM;this.Copy=np;this.Equals=mU;this.ToString=iQ;this.SetCenter=hn;this.SetCenterLatLong=qy;this.SetPixelRectangle=pG;this.SetLatLongRectangle=rd;this.SetZoomLevel=kt;this.SetMapStyle=cc;this.GetX=hK;this.GetY=hJ;this.GetCenter=oX;this.Resolve=rg;this.SetZoomLevel=kt;};
Msn.VE.ObliqueScene=function(F,bF,pZ,ea,nP,nQ,eg,gJ,pW,pU,oo,oI){var M=256;var t=new Msn.VE.Bounds(1,2,0,0,eg/2,gJ/2);function du(l,m){var U=Math.pow(2,m-2);var iI=[[l.x/U],[l.y/U],[1]];var aU=lS(pW,iI);var o=new Msn.VE.LatLong();o.longitude=aU[0][0]/aU[2][0];o.latitude=aU[1][0]/aU[2][0];return o;}function cQ(o,m){var U=Math.pow(2,m-2);var iI=[[o.longitude],[o.latitude],[1]];var aU=lS(pU,iI);var l=new Msn.VE.Pixel();l.x=aU[0][0]/aU[2][0]*U;l.y=aU[1][0]/aU[2][0]*U;return l;}function fy(W,ac,m){if(W<0||ac<0){return false;}if(m==1){return W<(eg/2)&&ac<(gJ/2);}return W<eg&&ac<gJ;}function pO(){return F;}function qc(W,ac,m){var pC=ac*(m==1?eg/2:eg)+W;return"http://c"+(W%2)+".p"+nQ+".oblique.tiles.virtualearth.net/tiles/o"+bF+"-"+pZ+"-"+(nP+m-2)+"-"+pC+".jpeg?g=14";}function qE(){return"http://thumbs.oblique.tiles.virtualearth.net/tiles/ot"+F+".jpeg?g=14";}function rb(a){var bS=oo[a];if(bS==null||bS==-1){return null;}return new Msn.VE.ObliqueScene(bS);}function nF(a){var bS=oI[a];if(bS==null||bS==-1){return null;}return new Msn.VE.ObliqueScene(bS);}function pl(){return ea;}function dj(){return t;}function li(){return eg*M;}function gm(){return gJ*M;}function pV(o){if(!o){return false;}var l=cQ(o,2);return kd(l,2);}function kd(l,m){var U=Math.pow(2,2-m);var d=l.x*U;var f=l.y*U;return d>=0&&f>=0&&d<li()&&f<gm();}this.PixelToLatLong=du;this.LatLongToPixel=cQ;this.IsValidTile=fy;this.GetID=pO;this.GetTileFilename=qc;this.GetThumbnailFilename=qE;this.GetNeighbor=rb;this.GetRotation=nF;this.GetOrientation=pl;this.GetBounds=dj;this.GetWidth=li;this.GetHeight=gm;this.ContainsLatLong=pV;this.ContainsPixel=kd;};
Msn.VE.Orientation=new function(){this.North="North";this.East="East";this.West="West";this.South="South";};
Msn.VE.Pixel=function(d,f){this.x=d;this.y=f;this.ToString=function(){return"("+this.x+", "+this.y+")";};this.Copy=function(l){if(!l){return;}this.x=l.x;this.y=l.y;};};
Msn.VE.PixelRectangle=function(rh,pD){this.topLeft=rh;this.bottomRight=pD;this.ToString=function(){return"("+(this.topLeft?this.topLeft.ToString():"null")+", "+(this.bottomRight?this.bottomRight.ToString():"null")+")";};this.Copy=function(bA){if(!bA){return;}if(!this.topLeft){this.topLeft=new Msn.VE.Pixel();}if(!this.bottomRight){this.bottomRight=new Msn.VE.Pixel();}this.topLeft.Copy(bA.topLeft);this.bottomRight.Copy(bA.bottomRight);};};
Msn.VE.LineRegion=function(od,cH,nB){this.boundingRectangle=od;this.indices=cH;this.childRegions=nB;function iQ(){return"Bounding Rectangle: "+this.boundingRectangle[0].ToString()+" to "+this.boundingRectangle[1].ToString()+" | Indices: ["+cH+"]";};this.ToString=iQ;}