⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 atlasuimap.js

📁 《圣殿祭司的ASP.NET 2.0开发详解——使用C#》光盘内容.包含了书籍所含的源代码.非常经典的一本asp.net2.0的书籍
💻 JS
📖 第 1 页 / 共 4 页
字号:
//-----------------------------------------------------------------------// Copyright (C) Microsoft Corporation. All rights reserved.//-----------------------------------------------------------------------// AtlasUIMap.js// Atlas Mapping UI Framework.function VE_MapControl(latitude,longitude,zoomLevel,mapStyle,position,x,y,width,height){this.index=VE_MapControl.controlList.length;this.latitude=latitude;this.longitude=longitude;this.preferredLatitude=latitude;this.preferredLongitude=longitude;this.offsetLeft=0;this.offsetTop=0;this.zoomLevel=this._ValidateZoomLevel(latitude,longitude,zoomLevel);this.prevZoomLevel=this.zoomLevel;this.mapStyle=this._ValidateMapStyle(mapStyle);this.x=x;this.y=y;this.width=width;this.height=height;this.tileWidth=0;this.tileHeight=0;this.dragging=false;this.dragPan=false;this.panLatitude=null;this.panLongitude=null;this.keyboardPan=false;this.tiles=new Array();this.oldTiles=null;this.unusedTiles=new Array();this.lastMouseX=0;this.lastMouseY=0;this.originX=0;this.originY=0;this.zoomCounter=0;this.zooming=false;this.panning=false;this.panCounter=0;this.panningX=0;this.panningY=0;this.debug=false;this.onMouseClick=null;this.onMouseDown=null;this.onMouseUp=null;this.onStartContinuousPan=null;this.onEndContinuousPan=null;this.onStartZoom=null;this.onEndZoom=null;this.pushpins=new Array();this.unusedPushpins=new Array();this.element=document.createElement("div");this.element.style.overflow="hidden";this.element.style.padding="0";this.element.style.margin="0";this.element.style.position=position;this.element.style.left=x;this.element.style.top=y;this.element.style.width=width;this.element.style.height=height;this.element.style.zIndex=VE_MapControl.containerZIndex;this.map=document.createElement("div");this.map.style.position="absolute";this.map.style.top="0px";this.map.style.left="0px";this.map.style.padding="0";this.map.style.margin="0";this.map.style.zIndex=VE_MapControl.mapZIndex;this.element.appendChild(this.map);this.keyboard=document.createElement("input");this.keyboard.style.position="absolute";this.keyboard.style.top="0px";this.keyboard.style.left="0px";this.keyboard.style.width="1px";this.keyboard.style.height="1px";this.keyboard.style.padding="0";this.keyboard.style.margin="0";this.keyboard.style.zIndex=VE_MapControl.kbInputZIndex;this.keyboard.onkeydown=VE_MapControl._KeyDown;this.keyboard.onkeyup=VE_MapControl._KeyUp;this.element.appendChild(this.keyboard);this._CreateCopyright();this._SetBackgroundColor();this.SetCenterAndZoom(latitude,longitude,zoomLevel);VE_MapControl.controlList.push(this);}VE_MapControl.prototype.SetCenter=function(latitude,longitude){this.SetCenterAndZoom(latitude,longitude,this.zoomLevel);}VE_MapControl.prototype.SetMapStyle=function(mapStyle){if(this.panning||this.zooming){return;}mapStyle=this._ValidateMapStyle(mapStyle);if(this.mapStyle!=mapStyle){this.mapStyle=mapStyle;this._SetBackgroundColor();this.latitude=this.GetCenterLatitude();this.longitude=this.GetCenterLongitude();this._StartMap();this._RepositionPushpins();this._UpdateCopyright();}}VE_MapControl.prototype._ValidateMapStyle=function(s){if(s=='a'||s=='h')return s;else return'r';}VE_MapControl.prototype._SetBackgroundColor=function(){var bg="#f2ede4";if(this.mapStyle=='a'||this.mapStyle=='h')bg="#404040";this.element.style.background=bg;}VE_MapControl.prototype.GetCenterLatitude=function(){return this.latitude;}VE_MapControl.prototype.GetCenterLongitude=function(){return this.longitude;}VE_MapControl.prototype._ComputeCenterPoint=function(capture){this.latitude=this.GetLatitude(this.height/2);this.longitude=this.GetLongitude(this.width/2);if(capture){this.preferredLatitude=this.latitude;this.preferredLongitude=this.longitude;}}VE_MapControl.prototype.GetLatitude=function(y){return this._YToLat(this.originY+this.offsetY+y);}VE_MapControl.prototype.GetLongitude=function(x){return this._XToLon(this.originX+this.offsetX+x);}VE_MapControl.prototype.GetY=function(latitude){return this._LatToY(latitude)-this.originY-this.offsetY;}VE_MapControl.prototype.GetX=function(longitude){return this._LonToX(longitude)-this.originX-this.offsetX;}VE_MapControl.prototype.GetZoomLevel=function(){return this.zoomLevel;}VE_MapControl.prototype.GetMapStyle=function(){return this.mapStyle;}VE_MapControl.prototype.GetMetersPerPixel=function(latitude,zoomLevel){if(!latitude){latitude=this.latitude;}if(!zoomLevel){zoomLevel=this.zoomLevel;}return Math.cos(DegToRad(latitude))*this._MetersPerPixel(zoomLevel);}VE_MapControl.prototype.Resize=function(width,height){if(!width||!height||width<=0||height<=0){return;}this.width=width;this.height=height;this.element.style.width=width;this.element.style.height=height;this.PanToLatLong(this.latitude,this.longitude);this._RepositionCopyright();}VE_MapControl.prototype._ClearTiles=function(){var t=this.tiles;var u=this.unusedTiles;var m=this.map;if(!t||t.length==0)return;while(t.length>0){var tile=t.pop();tile.RemoveFromMap();tile.img.src=VE_MapControl.emptyTile;u.push(tile);}}VE_MapControl.prototype._TileSize=function(){return 256;}VE_MapControl.prototype._StartMap=function(){this._ClearTiles();var m=this.map;m.style.top="0px";m.style.left="0px";this.originX=Math.round(this._LonToXAtZ(this.longitude,this.zoomLevel)-this.width/2);this.originY=Math.round(this._LatToYAtZ(this.latitude,this.zoomLevel)-this.height/2);this.offsetX=0;this.offsetY=0;var s=this._TileSize();var ox=this.originX;var oy=this.originY;var b=VE_MapControl.buffer;var w=this.width;var h=this.height;var x1=Math.floor((ox-b)/s);var y1=Math.floor((oy-b)/s);var x2=Math.floor((ox+w+b)/s);var y2=Math.floor((oy+h+b)/s);x1=Math.max(0,x1);y1=Math.max(0,y1);for(var x=x1;x<=x2;x++)for(var y=y1;y<=y2;y++){this._RequestTile(x,y,this.zoomLevel,s,this.mapStyle);}}VE_MapControl.prototype._UpdateMap=function(){var m=this.map;var s=this._TileSize();var ox=this.originX+this.offsetX;var oy=this.originY+this.offsetY;var w=this.width;var h=this.height;var b=VE_MapControl.buffer;var t=this.tiles;var x1=Math.floor((ox-b)/s);var y1=Math.floor((oy-b)/s);var x2=Math.floor((ox+w+b)/s);var y2=Math.floor((oy+h+b)/s);var oldx1=0;var oldy1=0;var oldx2=0;var oldy2=0;var first=true;var newTiles=new Array();for(var i=0;i<t.length;i++){var tile=t[i];var x=tile.tx;var y=tile.ty;if(x<x1||x>x2||y<y1||y>y2){tile.RemoveFromMap();}else{if(first){oldx1=x;oldy1=y;oldx2=x;oldy2=y;first=false;}else{oldx1=Math.min(oldx1,x);oldy1=Math.min(oldy1,y);oldx2=Math.max(oldx2,x);oldy2=Math.max(oldy2,y);}newTiles.push(tile);}}this.tiles=newTiles;x1=Math.max(0,x1);y1=Math.max(0,y1);for(var x=x1;x<=x2;x++)for(var y=y1;y<=y2;y++){if(x<oldx1||x>oldx2||y<oldy1||y>oldy2)this._RequestTile(x,y,this.zoomLevel,s,this.mapStyle);}}VE_MapControl.worldBounds={z:1,x1:0,y1:0,x2:2,y2:2};VE_MapControl.usaBounds={z:10,x1:172,y1:356,x2:332,y2:444};VE_MapControl.prototype._GetBounds=function(zoom){if(zoom>=VE_MapControl.usaBounds.z)return VE_MapControl.usaBounds;return VE_MapControl.worldBounds;}VE_MapControl.prototype._ClipDeltaX=function(deltaX){var b=this._GetBounds(this.zoomLevel);return this._ClipDelta(deltaX,this.width,this.originX+this.offsetX,b.z,b.x1,b.x2);}VE_MapControl.prototype._ClipDeltaY=function(deltaY){var b=this._GetBounds(this.zoomLevel);return this._ClipDelta(deltaY,this.height,this.originY+this.offsetY,b.z,b.y1,b.y2);}VE_MapControl.prototype._ClipDelta=function(delta,size,offset,bz,b1,b2){var z=this.zoomLevel;var s=this._TileSize();var min=s*(b1<<(z-bz));var max=s*(b2<<(z-bz));if(size>(max-min)){return((max-min-size)/2)-offset+min;}else if(offset+delta<min){return min-offset;}else if(offset+size+delta>max){return max-offset-size;}return delta;}VE_MapControl.prototype._ClipLatitude=function(latitude,zoom){var y=this._LatToYAtZ(latitude,zoom);var b=this._GetBounds(zoom);y=this._ClipAbsolute(y,zoom,this.height,b.z,b.y1,b.y2);return this._YToLatAtZ(y,zoom);}VE_MapControl.prototype._ClipLongitude=function(longitude,zoom){var x=this._LonToXAtZ(longitude,zoom);var b=this._GetBounds(zoom);x=this._ClipAbsolute(x,zoom,this.width,b.z,b.x1,b.x2);return this._XToLonAtZ(x,zoom);}VE_MapControl.prototype._ClipAbsolute=function(abs,z,size,bz,b1,b2){var s=this._TileSize();var min=s*(b1<<(z-bz));var max=s*(b2<<(z-bz));var half=size/2;if(size>max-min){return(max-min)/2;}else if(abs<min+half){return min+half;}else if(abs+half>max){return max-half;}return abs;}VE_MapControl.prototype._ValidateZoomLevel=function(latitude,longitude,z){if(z<VE_MapControl.minZoom){return VE_MapControl.minZoom;}if(z<VE_MapControl.usaBounds.z){return z;}var y=this._LatToYAtZ(latitude,z);var x=this._LonToXAtZ(longitude,z);var b=VE_MapControl.usaBounds;var s=this._TileSize();var minX=s*(b.x1<<(z-b.z));var maxX=s*(b.x2<<(z-b.z));var minY=s*(b.y1<<(z-b.z));var maxY=s*(b.y2<<(z-b.z));if(minX<x&&x<maxX&&minY<y&&y<maxY){return Math.min(VE_MapControl.maxZoom,z);}else{return Math.min(VE_MapControl.usaBounds.z-1,z);}}VE_MapControl.GetMouseX=function(e){var posX=0;if(e.pageX){posX=e.pageX;}else if(e.clientX){posX=e.clientX+document.body.scrollLeft;}return posX;}VE_MapControl.GetMouseY=function(e){var posY=0;if(e.pageY){posY=e.pageY;}else if(e.clientY){posY=e.clientY+document.body.scrollTop;}return posY;}VE_MapControl.GetMouseScrollDelta=function(e){if(e.wheelDelta){return e.wheelDelta;}else if(e.detail){return-e.detail;}return 0;}VE_MapControl.GetTarget=function(e){if(!e)e=window.event;var t=null;if(e.srcElement)t=e.srcElement;else if(e.target)t=e.target;if(t.nodeType==3)t=targ.parentNode;return t;}VE_MapControl.prototype._CreateCopyright=function(){var bg=document.createElement("div");bg.unselectable="on";with(bg.style){position="absolute";width="230px";height="28px";top="1px";left="1px";zIndex=30;color="Black";display="none";font="7pt Verdana";textAlign="right";cursor="pointer";}var fg=document.createElement("div");fg.unselectable="on";with(fg.style){position="absolute";width="230px";height="28px";top="0px";left="0px";zIndex=31;color="White";display="none";font="7pt Verdana";textAlign="right";cursor="pointer";}this.copyrightBg=bg;this.copyrightFg=fg;this._RepositionCopyright();this.element.appendChild(bg);this.element.appendChild(fg);}VE_MapControl.prototype._RepositionCopyright=function(){with(this.copyrightBg.style){top=(this.height-28)+"px";left=(this.width-240)+"px";display="block";}with(this.copyrightFg.style){top=(this.height-29)+"px";left=(this.width-241)+"px";display="block";}}VE_MapControl.prototype._UpdateCopyright=function(){var z=this.zoomLevel;var s=this.mapStyle;var c="&copy; 2005 Microsoft Corp";if(z>=5&&(s=="r"||s=="h")){c+=" &nbsp; &copy; 2004 NAVTEQ";}if(s=="h"||s=="a"){c+="<br>Image courtesy of ";if(z<=9){c+="NASA";}else{c+="USGS";}}this.copyrightBg.innerHTML=c;this.copyrightFg.innerHTML=c;this._RepositionCopyright();}VE_MapControl.prototype._MetersPerPixel=function(zl){return VE_MapControl.baseMetersPerPixel/(1<<zl);}VE_MapControl.prototype._XToLonAtZ=function(x,zl){var metersPerPixel=this._MetersPerPixel(zl);var metersX=x*metersPerPixel-VE_MapControl.offsetMeters;return RadToDeg(metersX/VE_MapControl.earthRadius);}VE_MapControl.prototype._LonToXAtZ=function(longitude,zl){var metersX=VE_MapControl.earthRadius*DegToRad(longitude);var metersPerPixel=this._MetersPerPixel(zl);return Math.round((metersX+VE_MapControl.offsetMeters)/metersPerPixel);}VE_MapControl.prototype._YToLatAtZ=function(y,zl){var metersPerPixel=this._MetersPerPixel(zl);var metersY=VE_MapControl.offsetMeters-y*metersPerPixel;return RadToDeg(Math.PI/2-2*Math.atan(Math.exp(-metersY/VE_MapControl.earthRadius)));}VE_MapControl.prototype._LatToYAtZ=function(latitude,zl){var sinLat=Math.sin(DegToRad(latitude));var metersY=VE_MapControl.earthRadius/2*Math.log((1+sinLat)/(1-sinLat));var metersPerPixel=this._MetersPerPixel(zl);return Math.round((VE_MapControl.offsetMeters-metersY)/metersPerPixel);}VE_MapControl.prototype._XToLon=function(x){return this._XToLonAtZ(x,this.zoomLevel);}VE_MapControl.prototype._LonToX=function(longitude){return this._LonToXAtZ(longitude,this.zoomLevel);}VE_MapControl.prototype._YToLat=function(y){return this._YToLatAtZ(y,this.zoomLevel);}VE_MapControl.prototype._LatToY=function(latitude){return this._LatToYAtZ(latitude,this.zoomLevel);}VE_MapControl.prototype._XToXAtZ=function(x,z1,z2){var lon=this._XToLonAtZ(x,z1);return this._LonToXAtZ(lon,z2);}VE_MapControl.prototype._YToYAtZ=function(y,z1,z2){var lat=this._YToLatAtZ(y,z1);return this._LatToYAtZ(lat,z2);}function DegToRad(d){return d*Math.PI/180.0;}function RadToDeg(r){return r*180.0/Math.PI;}VE_MapControl.prototype.Debug=function(enabled){var t=this.tiles;for(var i=0;i<t.length;i++){t[i].img.style.border=enabled?"1px dashed red":"0";if(enabled){this.map.appendChild(t[i].overlay);}else{if(t[i].overlay.parentNode==this.map){this.map.removeChild(t[i].overlay);}}}var u=this.unusedTiles;for(var i=0;i<u.length;i++){u[i].img.style.border=enabled?"1px dashed red":"0";}this.debug=enabled;}function VE_MapEvent(srcMapControl,latitude,longitude,zoomLevel){this.srcMapControl=srcMapControl;this.latitude=latitude;this.longitude=longitude;this.zoomLevel=zoomLevel;}VE_MapControl.prototype._CreateEvent=function(latitude,longitude,zoomLevel){if(!latitude)latitude=this.GetCenterLatitude();if(!longitude)longitude=this.GetCenterLongitude();if(!zoomLevel)zoomLevel=this.zoomLevel;return new VE_MapEvent(this,latitude,longitude,this.zoomLevel);}VE_MapControl.prototype._CallMouseDown=function(e){if(!e)e=this._CreateEvent();if(this.onMouseDown)this.onMouseDown(e);}VE_MapControl.prototype._CallMouseUp=function(e){if(!e)e=this._CreateEvent();if(this.onMouseUp)this.onMouseUp(e);}VE_MapControl.prototype._CallMouseClick=function(e){if(!e)e=this._CreateEvent();if(this.onMouseClick)this.onMouseClick(e);}VE_MapControl.prototype._CallStartContinuousPan=function(e){if(!e)e=this._CreateEvent();if(this.onStartContinuousPan)this.onStartContinuousPan(e);}VE_MapControl.prototype._CallEndContinuousPan=function(e){if(!e)e=this._CreateEvent();if(this.onEndContinuousPan)this.onEndContinuousPan(e);}VE_MapControl.prototype._CallStartZoom=function(e){if(!e)e=this._CreateEvent();if(this.onStartZoom)this.onStartZoom(e);}VE_MapControl.prototype._CallEndZoom=function(e){if(!e)e=this._CreateEvent();if(this.onEndZoom)this.onEndZoom(e);}VE_MapControl.controlList=new Array();VE_MapControl.altitudes=[2000,500,150,50,25,12,6,3,1];VE_MapControl.scaledRadius=5429123.84;VE_MapControl.buffer=100;VE_MapControl.dragElement=null;VE_MapControl.dragControl=null;VE_MapControl.animatedMovementEnabled=1;VE_MapControl.zoomTotalSteps=5;VE_MapControl.tileUrlPrefixes=["http://tiles0.virtualearth.msn.com/tiles/","http://tiles1.virtualearth.msn.com/tiles/","http://tiles2.virtualearth.msn.com/tiles/","http://tiles3.virtualearth.msn.com/tiles/"];VE_MapControl.tileVersion=1;VE_MapControl.keyboardPanSpeed=15;VE_MapControl.panToLatLongSpeed=15;VE_MapControl.earthRadius=6378137;VE_MapControl.minZoom=1;VE_MapControl.maxZoom=19;VE_MapControl.requests=new Array();VE_MapControl.offsetMeters=20971520;VE_MapControl.baseMetersPerPixel=163840;VE_MapControl.emptyTile="i/spacer.gif";VE_MapControl.minLatitude=-85;VE_MapControl.maxLatitude=85;VE_MapControl.minLongitude=-180;VE_MapControl.maxLongitude=180;VE_MapControl.kbInputZIndex=0;VE_MapControl.containerZIndex=0;VE_MapControl.mapZIndex=1;VE_MapTile.baseZIndex=2;VE_MapTile.swapZIndex=1;VE_MapTile.debugZIndex=3;VE_MapPushpin.baseZIndex=11;VE_MapPushpin.topZIndex=20;VE_MapControl.FindControlByInput=function(input){var c=VE_MapControl.controlList;for(var i=0;i<c.length;i++){if(c[i].keyboard==input)return c[i];}return null;}VE_MapControl._KeyDown=function(e){if(!e)var e=window.event;var t=VE_MapControl.GetTarget(e);var c=VE_MapControl.FindControlByInput(t);var s=VE_MapControl.keyboardPanSpeed;var x=c.panningX;var y=c.panningY;switch(e.keyCode){case 9:if(c.panning&&c.keyboardPan){c.StopContinuousPan();}return true;case 37:x=-s;break;case 38:y=-s;break;case 39:x=s;break;case 40:y=s;break;case 107:case 187:case 61:case 43:x=0;y=0;c.ZoomIn();break;case 109:case 189:x=0;y=0;c.ZoomOut();break;default:return false;}if(x||y)c.ContinuousPan(x,y,null,true);return false;}VE_MapControl._KeyUp=function(e){if(!e)var e=window.event;var t=VE_MapControl.GetTarget(e);var c=VE_MapControl.FindControlByInput(t);var s=VE_MapControl.keyboardPanSpeed;var x=c.panningX;var y=c.panningY;switch(e.keyCode){case 37:x=0;break;case 38:y=0;break;case 39:x=0;break;case 40:y=0;break;default:return false;}c.ContinuousPan(x,y,null,true);return false;}VE_MapControl._MouseDown=function(e){if(!e)e=window.event;e.cancelBubble=true;var t=VE_MapControl.GetTarget(e);var c=VE_MapControl.FindControlByTileImage(t);if(!c||c.zooming){return false;}if(c.panning){c.StopContinuousPan();}c.keyboard.focus();c.dragging=true;c.dragPan=false;c.lastMouseX=VE_MapControl.GetMouseX(e);c.lastMouseY=VE_MapControl.GetMouseY(e);t.style.cursor="move";if(t.setCapture)t.setCapture();VE_MapControl.dragElement=t;VE_MapControl.dragControl=c;c._CallStartContinuousPan();return false;}VE_MapControl._MouseUp=function(e){if(!e)e=window.event;if(VE_MapControl.dragElement){var c=VE_MapControl.dragControl;if(!c){return false;}c.dragging=false;c._ComputeCenterPoint(true);VE_MapControl.dragElement.style.cursor="pointer";if(VE_MapControl.dragElement.releaseCapture)VE_MapControl.dragElement.releaseCapture();if(c.dragPan)c._CallEndContinuousPan();c.dragPan=false;var x=VE_MapControl.GetMouseX(e)-c.x;var y=VE_MapControl.GetMouseY(e)-c.y;c._CallMouseClick(c._CreateEvent(c.GetLatitude(y),c.GetLongitude(x)));}return false;}VE_MapControl._MouseDoubleClick=function(e){if(!e)e=window.event;var c=VE_MapControl.dragControl;if(!c||c.panning||c.zooming){return false;}var lat=c._YToLat(c.originY+c.offsetY+VE_MapControl.GetMouseY(e)-c.offsetTop-c.y);var lon=c._XToLon(c.originX+c.offsetX+VE_MapControl.GetMouseX(e)-c.offsetLeft-c.x);if(e.altKey){if(c.zoomLevel==VE_MapControl.minZoom)c.PanToLatLong(lat,lon);else c.SetCenterAndZoom(lat,lon,c.zoomLevel-1);}else{if(c.zoomLevel+1!=c._ValidateZoomLevel(lat,lon,c.zoomLevel+1))c.PanToLatLong(lat,lon);else c.SetCenterAndZoom(lat,lon,c.zoomLevel+1);}return false;}VE_MapControl._MouseMove=function(e){if(!e)e=window.event;if(VE_MapControl.dragElement){var c=VE_MapControl.dragControl;if(!c){return false;}if(c.dragging){var x=VE_MapControl.GetMouseX(e);var y=VE_MapControl.GetMouseY(e);c.PanMap(c.lastMouseX-x,c.lastMouseY-y);c.lastMouseX=x;c.lastMouseY=y;c.dragPan=true;if(e.cancelBubble)e.cancelBubble=true;}}return false;}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -