Select to view content in your preferred language

query a feature layer and the onfault function is being called

1699
12
09-14-2011 06:04 AM
PeterHoffman
Deactivated User
I am trying to query a feature layer and the onfault function is being called. The first query works fine but the second one - // Status part does not.

Any ideas?

Thanks.



<?xml version="1.0" encoding="utf-8"?>
<!--
     ////////////////////////////////////////////////////////////////////////////////
     //
     // Copyright (c) 2010 ESRI
     //
     // All rights reserved under the copyright laws of the United States.
     // You may freely redistribute and use this software, with or
     // without modification, provided you include the original copyright
     // and use restrictions.  See use restrictions in the file:
     // <install location>/License.txt
     //
     ////////////////////////////////////////////////////////////////////////////////
-->
<viewer:BaseWidget xmlns:fx="http://ns.adobe.com/mxml/2009"
                   xmlns:s="library://ns.adobe.com/flex/spark"
                   xmlns:mx="library://ns.adobe.com/flex/mx"
                   xmlns:viewer="com.esri.viewer.*"
                   widgetConfigLoaded="init()">
    <fx:Script>
        <![CDATA[
   import com.esri.ags.FeatureSet;
   import com.esri.ags.layers.FeatureLayer;
   import com.esri.ags.tasks.supportClasses.Query;
   import com.esri.viewer.components.HTMLPopup;
  
   import flashx.textLayout.edit.SelectionFormat;
   import flashx.textLayout.events.SelectionEvent;
  
   import mx.collections.ArrayCollection;
   import mx.collections.SortField;
   import mx.controls.Alert;
   import mx.rpc.AsyncResponder;
   import mx.rpc.events.FaultEvent;

            private var content:String;
   private var contentStatus:String;
            private var btnLabel:String
            private var txtareaWidth:Number;
            private var txtareaHeight:Number;
   private var sSheltersClosedMessage:String;
   private var sSheltersOpenMessage:String;
  
  
   private var fLayer:FeatureLayer
   private var statusLayer:FeatureLayer
  
            private function init():void
            {
                if (configXML)
                {
                    content = configXML.content || "...";
                    btnLabel = configXML.btnlabel || getDefaultString("okLabel");
                    txtareaWidth = configXML.width || 500;
                    txtareaHeight = configXML.height || 500;
     sSheltersClosedMessage = configXML.sheltersclosedmessage;
     sSheltersOpenMessage = configXML.sheltersopenmessage;
    
     fLayer = new FeatureLayer(configXML.sheltersurl);
     fLayer.useAMF = false;
    
     var qry:Query = new Query();
     qry.where = "OPEN = 1";
     // fLayer.queryFeatures(qry, new AsyncResponder(onResult, onFault));
    
     // Status part
     statusLayer = new FeatureLayer("http://gis.co.suffolk.ny.us/ArcGIS/rest/services/EmergencyShelters/MapServer/1");  
     fLayer.useAMF = false;
    
     var qryStatus:Query = new Query();
     qryStatus.where = "STATUS = 1";
     statusLayer.queryFeatures(qryStatus, new AsyncResponder(onResultStatus, onFault));   
    
                }
       
    function onResultStatus(fSet:FeatureSet, token:Object=null):void
    {
     trace("Result");
     if(fSet.features.length > 0)
     {
      contentStatus = "HERE1";
     
      HTMLPopup.show(contentStatus, btnLabel, txtareaWidth, txtareaHeight);
     }
     else
     {
      contentStatus = "HERE";
      HTMLPopup.show(contentStatus, btnLabel, txtareaWidth, txtareaHeight);
     
     }
    }
       
    function onResult(fSet:FeatureSet, token:Object=null):void
    {
     trace("Result");
    
     if(fSet.features.length > 0)
     {
      content = content.replace("[SHELTERMESSAGETOKEN]", sSheltersOpenMessage);
     
     
      var arr:Array = new Array();
      for(var i:int=0; i<fSet.features.length; i++)
      {
       arr.push(fSet.attributes.NAME);
      }
      arr.sort();
     
     
      var tmp:String = "";
      for(i=0; i<arr.length; i++)
      {
       tmp += arr + "<br>";
      }
      tmp = tmp += "<br>";
     
     
      content = content.replace("[OPENSHELTERSTOKEN]", tmp);
      var bkgrndColor:String = "0x00FF00";
      HTMLPopup.show(content, btnLabel, txtareaWidth, txtareaHeight);
     }
     else
     {
      content = content.replace("[SHELTERMESSAGETOKEN]", sSheltersClosedMessage);
      HTMLPopup.show(content, btnLabel, txtareaWidth, txtareaHeight);
    
     }
    }
   
    function onFault(info:Object, token:Object = null):void
    {
     trace("Fault");
    }
            }
        ]]>
    </fx:Script>
</viewer:BaseWidget>
Tags (2)
0 Kudos
12 Replies
PeterHoffman
Deactivated User
OK, I will try that. I was given this method by someone else.
Thanks,
0 Kudos
RobertScheitlin__GISP
MVP Emeritus
Peter,

   See if this works then:

<?xml version="1.0" encoding="utf-8"?>
<!--
////////////////////////////////////////////////////////////////////////////////
//
// Copyright (c) 2010 ESRI
//
// All rights reserved under the copyright laws of the United States.
// You may freely redistribute and use this software, with or
// without modification, provided you include the original copyright
// and use restrictions. See use restrictions in the file:
// <install location>/License.txt
//
////////////////////////////////////////////////////////////////////////////////
-->
<viewer:BaseWidget xmlns:fx="http://ns.adobe.com/mxml/2009"
                   xmlns:s="library://ns.adobe.com/flex/spark"
                   xmlns:mx="library://ns.adobe.com/flex/mx"
                   xmlns:viewer="com.esri.viewer.*"
                   widgetConfigLoaded="init()">
    <fx:Script>
        <![CDATA[
            import com.esri.ags.FeatureSet;
            import com.esri.ags.events.LayerEvent;
            import com.esri.ags.layers.FeatureLayer;
            import com.esri.ags.tasks.QueryTask;
            import com.esri.ags.tasks.supportClasses.Query;
            import com.esri.viewer.components.HTMLPopup;
            
            import flashx.textLayout.edit.SelectionFormat;
            import flashx.textLayout.events.SelectionEvent;
            
            import mx.collections.ArrayCollection;
            import mx.collections.SortField;
            import mx.controls.Alert;
            import mx.rpc.AsyncResponder;
            import mx.rpc.events.FaultEvent;
            
            private var content:String;
            private var contentStatus:String;
            private var btnLabel:String
            private var txtareaWidth:Number;
            private var txtareaHeight:Number;
            private var sSheltersClosedMessage:String;
            private var sSheltersOpenMessage:String;
            
            
            private var fLayer:FeatureLayer;
            private var statusQuery:QueryTask;
            
            private function init():void
            {
                if (configXML)
                {
                    content = configXML.content || "...";
                    btnLabel = configXML.btnlabel || getDefaultString("okLabel");
                    txtareaWidth = configXML.width || 500;
                    txtareaHeight = configXML.height || 500;
                    sSheltersClosedMessage = configXML.sheltersclosedmessage;
                    sSheltersOpenMessage = configXML.sheltersopenmessage;
                    
                    fLayer = new FeatureLayer(configXML.sheltersurl);
                    fLayer.useAMF = false;
                    
                    var qry:Query = new Query();
                    qry.where = "OPEN = 1";
                    // fLayer.queryFeatures(qry, new AsyncResponder(onResult, onFault));
                    
                    // Status part
                    statusQuery = new QueryTask("http://gis.co.suffolk.ny.us/ArcGIS/rest/services/EmergencyShelters/MapServer/1");
                    statusQuery.useAMF = false;
                    var qryStatus:Query = new Query();
                    qryStatus.where = "STATUS = 1";
                    qryStatus.returnGeometry = false;
                    qryStatus.outFields = ["*"];
                    statusQuery.execute(qryStatus, new AsyncResponder(onResultStatus, onFault));
                }
                
                private function onResultStatus(fSet:FeatureSet, token:Object=null):void
                {
                    trace("Result");
                    if(fSet.features.length > 0)
                    {
                        contentStatus = "HERE1";
                        
                        HTMLPopup.show(contentStatus, btnLabel, txtareaWidth, txtareaHeight);
                    }
                    else
                    {
                        contentStatus = "HERE";
                        HTMLPopup.show(contentStatus, btnLabel, txtareaWidth, txtareaHeight);
                        
                    }
                }
                
                private function onResult(fSet:FeatureSet, token:Object=null):void
                {
                    trace("Result");
                    
                    if(fSet.features.length > 0)
                    {
                        content = content.replace("[SHELTERMESSAGETOKEN]", sSheltersOpenMessage);
                        
                        
                        var arr:Array = new Array();
                        for(var i:int=0; i<fSet.features.length; i++)
                        {
                            arr.push(fSet.attributes.NAME);
                        }
                        arr.sort();
                        
                        
                        var tmp:String = "";
                        for(i=0; i<arr.length; i++)
                        {
                            tmp += arr + "<br>";
                        }
                        tmp = tmp += "<br>";
                        
                        
                        content = content.replace("[OPENSHELTERSTOKEN]", tmp);
                        var bkgrndColor:String = "0x00FF00";
                        HTMLPopup.show(content, btnLabel, txtareaWidth, txtareaHeight);
                    }
                    else
                    {
                        content = content.replace("[SHELTERMESSAGETOKEN]", sSheltersClosedMessage);
                        HTMLPopup.show(content, btnLabel, txtareaWidth, txtareaHeight);
                        
                    }
                }
                
                private function onFault(info:Object, token:Object = null):void
                {
                    trace("Fault");
                }
            }
        ]]>
    </fx:Script>
</viewer:BaseWidget>
0 Kudos
PeterHoffman
Deactivated User
That works!
Thanks,

Still having trouble with this forum web site due to County firewalls, etc.
0 Kudos