Error#1069 Locate Coordinate Widget

1535
11
Jump to solution
02-13-2013 05:21 AM
MouMezou
New 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
1 Solution

Accepted Solutions
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=""/>

View solution in original post

0 Kudos
11 Replies
RobertScheitlin__GISP
MVP Emeritus
Moussadak,

   What version of the Viewer are you using?... Is this the standard locate widget you are talking about or some custom widget from the gallery?
0 Kudos
MouMezou
New Contributor
Moussadak,

   What version of the Viewer are you using?... Is this the standard locate widget you are talking about or some custom widget from the gallery?


Hi Robert,

Thanks for your response I am currently using the flex viewer 2.5  and the code was modified to address the user submitting the lat/long and and having it showing on the basemap with wkid=2953. so i am converting the lat/long to DD.Dec and trying to project it on my basemap.
0 Kudos
RobertScheitlin__GISP
MVP Emeritus
Mou,

   In order for you to get a clearer error message you need to comment out the try catch in this function:

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);
                //}
            }
0 Kudos
MouMezou
New Contributor
I got a blank Results return, it didn't display the point on the map.
0 Kudos
RobertScheitlin__GISP
MVP Emeritus
Mou,

   That does not make sense that you did not get an error this time but you did before. Are you typing something in the lat and lon different now?
0 Kudos
MouMezou
New Contributor
Mou,

   That does not make sense that you did not get an error this time but you did before. Are you typing something in the lat and lon different now?


not at all I am typing the same lat/long and I even put an alertbox to make sure the DD.Dec is being calculated properly and it showing "46.29277777777778, -67.53472222222221. the issue is more like with my statement geometryService.Project where thing aren't working. the Error it was dispalying earlier came out from the Catch statement and it returned "Error#1069" without any text after that, and I did check if I was able to access the geometry server url : http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Geometry/GeometryServer.
0 Kudos
RobertScheitlin__GISP
MVP Emeritus
Mou,

   Do you have the Flash Player Debugger version installed? If not use this link to get the Flash Player Debugger.

http://www.adobe.com/support/flashplayer/downloads.html

It will help you get some real errors that you can debug.
0 Kudos
MouMezou
New Contributor
Mou,

   Do you have the Flash Player Debugger version installed? If not use this link to get the Flash Player Debugger.

http://www.adobe.com/support/flashplayer/downloads.html

It will help you get some real errors that you can debug.


I finally got a full description error poiting to this

ReferenceError: Error #1069: Property type not found on com.esri.ags.Graphic and there is no default value.
at com.esri.ags.tasks::GeometryService/project()
at widgets.Locate::LocateWidget/locateCoordinates()
at widgets.Locate::LocateWidget/___LocateWidget_Button3_click()
0 Kudos
RobertScheitlin__GISP
MVP Emeritus
Mou,

   At version 2.5 of the API and Viewer the project function expects an array of geometries and not a graphic as you are passing in.
0 Kudos