map.addEventListener(MouseEvent.MOUSE_MOVE, mapMouseMove);
private function mapMouseMove(event:MouseEvent):void { var mapPoint:MapPoint = map.toMapFromStage(event.stageX, event.stageY); mapPoint = UTMtoLATLON(mapPoint); //translate coordinates SiteContainer.dispatchEvent(new AppEvent(AppEvent.SET_XY, false, false, mapPoint)); }
public static const SET_XY:String = "setxyLoc";
SiteContainer.addEventListener(AppEvent.SET_XY, setXY);
private function setXY(event:AppEvent):void { if (event.data) var mapPoint:MapPoint = event.data as MapPoint; xLoc = mapPoint.x.toFixed(6); yLoc = mapPoint.y.toFixed(6); }
Hi Jackson,This code is pretty much exactly what I'm looking for. I'll just have to change it for zone 11N. One question though, where in Desktop do I put it? I've never worked with straight code before. I'm using ArcEditor 9.3 with Spatial Analyst extension. Any help would be greatly appreciated.One other question, will this add the lat. lon. coordinates to the attribute table? Cheers,Paul
If you can switch your map services to web mercator than that is your best bet.
private function UTMtoLATLON(mapPoint:MapPoint):MapPoint { //The math in this function was based off of methods found on http://www.gpsy.com/gpsinfo/geotoutm/ by Karen Nakamura //Set easting and northing from the MapPoint var easting:Number = mapPoint.x; //the X coordinate from the service in UTM meters var northing:Number = mapPoint.y; //the Y coordinate from the service in UTM meters //Settings for WGS_1984_UTM_Zone_12N or WKID 32612 var avflat:Number = 298.257223563; //the Inverse Flattening that ArcGIS provides in the geographic coordinate description var semiMAJaxis:Number = 6378137.0; //the Semimajor Axis that ArcGIS provides in the geographic coordinate description var meridORIG:Number = -111.0; //the Central Meridian that ArcGIS provides in the projection description var scFACTorig:Number = 0.9996; //the Scale Factor that ArcGIS provides in the projection description var falseNOR:Number = 0.0; //the False Northing that ArcGIS provides in the projection description var falseEST:Number = 500000.0; //the False Easting that ArcGIS provides in the projection description //Calculations var flattening:Number = 1.0/avflat; //change Inverse Flattening into flattening var eccentricity:Number = (2.0*flattening)-(flattening*flattening); //calculate eccentricity var semiMINaxis:Number = semiMAJaxis*(Math.pow((1.0-eccentricity),0.5)); //calculate the Semiminor Axis var n:Number = (semiMAJaxis - semiMINaxis)/(semiMAJaxis + semiMINaxis); //calculate n var semiMAJecc:Number = semiMAJaxis*(1.0-eccentricity); //calculate the Semimajor Eccentricity var semiMINecc:Number = 1.0/(Math.sin((1.0/3600.0)*Math.PI/180.0)); //calculate the Semiminor Eccentricity var epsilon:Number = 1097.0*(Math.pow(n,4.0))/512.0; //calculate epsilon var delta:Number = 151.0*(Math.pow(n,3.0))/96.0-(417.0*(Math.pow(n,5.0))/128.0); //calculate delta var gamma:Number = 21.0*(Math.pow(n,2.0))/16.0-(55.0*(Math.pow(n,4.0))/32.0); //calculate gamma var beta:Number = 3.0*n/2.0-(27.0*(Math.pow(n,3.0))/32.0)+(269.0*(Math.pow(n,5.0))/512.0); //calculate beta var alpha:Number = (semiMAJaxis + semiMINaxis)/2.0*(1.0+(Math.pow(n,2.0))/4.0+(Math.pow(n,4.0))/64.0); //calculate alpha var phiprime:Number = (northing - falseNOR)/(scFACTorig*alpha); //calculate phiprime var phiF:Number = phiprime+beta*Math.sin(2.0*phiprime)+gamma*Math.sin(4.0*phiprime)+delta*Math.sin(6.0*phiprime)+epsilon*Math.sin(8.0*phiprime); //calculate phiF var v:Number = semiMAJaxis/(Math.pow(1.0-(eccentricity*(Math.pow(Math.sin(phiF),2.0))),0.5)); //calculate v var p:Number = semiMAJecc/Math.pow((1.0-(eccentricity*Math.pow(Math.sin(phiF),2.0))),1.5); //calculate p var VII:Number = ((Math.tan(phiF)*Math.pow((easting-falseEST),2.0))/(2.0*Math.pow(scFACTorig,2.0)*v*p))*((1.0/(Math.sin((1.0/3600.0)*Math.PI/180.0)))); //calculate VII var VIII:Number = ((Math.tan(phiF)*Math.pow((easting-falseEST),4.0))/(24.0*Math.pow(scFACTorig,4.0)*Math.pow(v,3.0)*p))*(5.0+3.0*Math.pow((Math.tan(phiF)),2.0))*(1.0/(Math.sin((1.0/3600.0)*Math.PI/180.0))); //calculate VIII var X:Number = ((1.0/Math.cos(phiF))*Math.pow((easting-falseEST),3.0)*semiMINecc)/(6.0*Math.pow(scFACTorig,3.0)*Math.pow(v,3.0))*((v/p)+2.0*Math.pow((Math.tan(phiF)),2.0)); //calculate X var IX:Number = ((1.0/Math.cos(phiF))*(easting-falseEST)*semiMINecc)/(scFACTorig*v); //calculate XI var E:Number = ((1.0/Math.cos(phiF))*Math.pow((easting-falseEST),5.0)*semiMINecc)/(120.0*Math.pow(scFACTorig,5.0)*Math.pow(v,5.0))*(5.0+28.0*Math.pow((Math.tan(phiF)),2.0)+24.0*Math.pow((Math.tan(phiF)),4.0)); //calculate E var phiFdegrees:Number = phiF*180.0/Math.PI; //change phiF from radians to degrees var DDegLat:Number = phiFdegrees-VII/3600.0+VIII/3600.0; //calculate degrees latitude var DDegLon:Number = meridORIG+(IX-X+E)/3600.0; //calculate degrees longitude //Set the MapPoint to the new Lat and Lon mapPoint.x = DDegLon; mapPoint.y = DDegLat; //Return the MapPoint return mapPoint; }
Signed in members can post, follow updates, and more. New here? Register a free account.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.