Select to view content in your preferred language

Error#1069 Locate Coordinate Widget

2664
11
Jump to solution
02-13-2013 05:21 AM
MouMezou
Emerging Contributor
I have been reworking the locate coordinate Widget to address a situation where a User input a Lat/long(DMS) (wkid=4326) and I have to locate them on a NAD83 (wkid=2653) basemap , so I tried to run the following code to execute that but I have been getting "Error#1069" on the Results view of the widget. Can you please tell me what am I doing wrong here is my code:

private function locateCoordinates():void             {                 originatingLocateState = currentState;                  // refresh before each request                 hideInfoWindow();                 graphicsLayer.clear();                 if (locateResultAC)                 {                     locateResultAC.removeAll();                 }                  try                 {       var vals:Array;      var long:String=txtLong.text;      var lat:String= txtLat.text;      vals=long.split(" ");      long=(Number(vals[0]) + Number(vals[1]) / 60 + Number(vals[2]) / 3600).toString();      vals=lat.split(" ");      lat=(Number(vals[0]) - Number(vals[1]) / 60 - Number(vals[2]) / 3600).toString();                            if (long && lat)                     {                         showStateResults();                          var locateResult:LocateResult = new LocateResult();                         locateResult.symbol = resultSymbol;                         locateResult.title = coordinatesLabel;                         locateResult.content = long + " " + lat;       locateResult.link = "";       locateResult.selected = true;                         locateResult.point = new MapPoint(Number(long), Number(lat),new SpatialReference(4326));       var gra:Graphic= new Graphic(locateResult.point);       geometryService.project([gra],map.spatialReference);                                                                                   }                 }                 catch (error:Error)                 {                     showMessage(error.message, false);                 }             }


private function projectCompleteHandler(event:GeometryServiceEvent):void    {     hideInfoWindow();     graphicsLayer.clear();     //WidgetEffects.flipWidget(this, viewStack, "selectedIndex", 2, 400);     try     {      var long:String = txtLong.text;      var lat:String = txtLat.text;            var point:MapPoint = (event.result as Array)[0] as MapPoint;      var icon:String = widgetIcon;      var title:String = coordinatesLabel;        var content:String = long.toString() + ", " + lat.toString();      var link:String = "";      var infoData:Object =        {        icon: icon,         title: title,         content: content,         link: link,         point: point,        geometry: point       };            //showLocation(infoData);      //showMessage(locationsLabel, false);            locateResultAC = new ArrayCollection([ infoData ]);      addSharedData(widgetTitle, locateResultAC);      showLocation(infoData);      showMessage(locationsLabel + " " + locateResultAC.length, false);           }     catch (error:Error)     {      showMessage(error.message, false);     }    }
 

<esri:GeometryService    id="geometryService"         url="http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Geometry/GeometryServer"          projectComplete="projectCompleteHandler(event)"/>
Tags (2)
0 Kudos
11 Replies
RobertScheitlin__GISP
MVP Emeritus
Mou,

   Here is your functions fixed:

There is a big difference in how I am expecting the user to enter the coorinates though:

85-50-1.45W
33-39-10.99N

Dashes instead of your spaces and they must specify NSWE

            private function dms_to_deg ( dmsStr:String ):Number             {                 var negNum:Boolean = false;                 if(dmsStr.toLowerCase().indexOf("w") > -1){                     negNum = true;                 }                 if(dmsStr.toLowerCase().indexOf("s") > -1){                     negNum = true;                 }                 var myPattern:RegExp = /[WwnN ]/g;                 dmsStr = dmsStr.replace(myPattern,"");                 var dmsArr:Array = dmsStr.split("-");                 //Compute degrees, minutes and seconds:                 var sec:Number = Number(dmsArr[2]) / 60;                 var min:Number = sec + Number(dmsArr[1]);                 var dec:Number = min / 60;                 var fDeg:Number = dec + Number(dmsArr[0]);                 if(negNum){                     fDeg = -Math.abs(fDeg);                 }                 return fDeg;             }              private function locateCoordinates():void             {                 originatingLocateState = currentState;                  // refresh before each request                 hideInfoWindow();                 graphicsLayer.clear();                 if (locateResultAC)                 {                     locateResultAC.removeAll();                 }                  try                 {                     var vals:Array;                     var long:String = txtLong.text;                     var lat:String = txtLat.text;                                          if (long && lat)                     {                         showStateResults();                         var nLat:Number = dms_to_deg(lat);                         var nLon:Number = dms_to_deg(long);                         var mp:MapPoint = new MapPoint(nLon, nLat, new SpatialReference(4326));                         geometryService.project([mp], map.spatialReference);                     }                     else                     {                         // dont send any request as the required field(s) not completed                         coordinatesRequiredFieldsLabel.visible = true;                         coordinatesRequiredFieldsLabel.includeInLayout = true;                         if (long == "" && lat == "")                         {                             coordinatesRequiredFieldsLabel.text = getDefaultString("requiredFields") + " " + xLabel + ", " + yLabel;                         }                         else                         {                             coordinatesRequiredFieldsLabel.text = long == "" ? getDefaultString("requiredField") + " " + xLabel : getDefaultString("requiredField") + " " + yLabel;                         }                     }                 }                 catch (error:Error)                 {                     showMessage(error.message, false);                 }             }                          private function projectCompleteHandler(event:GeometryServiceEvent):void             {                 try                 {                     var long:String = txtLong.text;                     var lat:String = txtLat.text;                                          var locateResult:LocateResult = new LocateResult();                     locateResult.symbol = resultSymbol;                     locateResult.title = coordinatesLabel;                     locateResult.content = long + " " + lat;                     locateResult.link = "";                     locateResult.selected = true;                     var mp:MapPoint = (event.result as Array)[0] as MapPoint;                     locateResult.point = mp;                                          locateResultAC = new ArrayCollection([ locateResult ]);                                          addSharedData(widgetTitle, locateResultAC);                     showLocation(locateResult);                     showMessage(locationsLabel + " " + locateResultAC.length, false);                 }                 catch (error:Error)                 {                     showMessage(error.message, false);                 }             }


Also here is the textInputs that restrict the text entered to the format you need:

<mx:TextInput id="txtLong"                                   restrict="0-9\.\-\W\E\w\e"                                   width="100%"                                   enter="locateCoordinates()"                                   text=""/>


and
<mx:TextInput id="txtLat"                                   restrict="0-9\.\-\N\S\n\s"                                   width="100%"                                   enter="locateCoordinates()"                                   text=""/>
0 Kudos
MouMezou
Emerging Contributor
Thanks Robert for you answer and help. the code i posted initially i had to remove the "Else" and other exeception just so i can target geometryservice.project as i thoughn it was the cause of my error. I like to use the "-" in between but our users will need just to copy/paste the coordinate with the space from another application, so I have to split with the "space".

Again thanks for your assistance.
0 Kudos