Select to view content in your preferred language

Passing Parameter to Flex Viewer

20591
114
01-14-2011 03:46 AM
CurtNielsen
Occasional Contributor
I would like to pass a parameter, parcel id, to flex viewer and have the map pan to that location. I have modified the Search widget to use a layer that we can search by parcel ID. Just want the same capability if I pass a parameter, paracle ID, to http://mynode/FlexViewer. Maybe something like http://mynode/FlexViewer?request=widget&version=2.1&WidgetName=Search&ParcelID=1234

Thank you!
Tags (2)
0 Kudos
114 Replies
BrendanCunningham
Emerging Contributor
Hi Marc,
That worked perfectly, thanks a lot.
The only further customization I need is to switch the query from a "like" search to an exact search.
Is this possible through the code or can you advise how to go about it via the MXD?
Thanks a lot,
brendan
0 Kudos
MarcWeinshenker1
Regular Contributor
Hi Marc,
That worked perfectly, thanks a lot.
The only further customization I need is to switch the query from a "like" search to an exact search.
Is this possible through the code or can you advise how to go about it via the MXD?
Thanks a lot,
brendan


Brendan,

There might be a couple of ways to get around the LIKE.  One would be to use the WHERE property of the QUERY to create a SQL expression to validate the value parsed from the URL (see the QUERY class in the Flex API Reference).  Another way would be to use coding prior to the submission of the query to validate the parsed value, e.g, for string length.  Sorry I can't offer any specific examples since I'm not doing either of these.

I doubt there is any way to do it in the MXD since all the query is looking at is field values, and there probably isn't much chance that the values are so completely different from each other that all LIKE comparisons would fail. 

Marc
0 Kudos
AmberReynolds
Deactivated User
Marc - Thank you for the code! I've tried modifying my MapManager.mxml and I keep getting the error "[RPC Fault faultString="Unexpected < encountered" faultcode="null" faultDetail="null"]

I've tried different services/layers to query with no luck. Any ideas? Any help would be much appreciated!

Steve,

I've successfully modified the code to pass a parcel ID in the URL.  The map opens and zooms to the parcel which has been overlaid by a graphic. I'm attaching a text file with explanations and code.

Marc
0 Kudos
MarcWeinshenker1
Regular Contributor
Marc - Thank you for the code! I've tried modifying my MapManager.mxml and I keep getting the error "[RPC Fault faultString="Unexpected < encountered" faultcode="null" faultDetail="null"]

I've tried different services/layers to query with no luck. Any ideas? Any help would be much appreciated!


I'll take a guess that maybe you haven't modified the line for entering your own map service path to the REST endpoint or, if you did, maybe you left behind one or more of the angle brackets I used to indicate where you need to enter the portions of the service path.  The brackets are not meant to be left behind, but just to indicate where a variable should be.

To be specific, here is the generic line to be edited:
var qFCPre:String = "http://<server>/<instance>/rest/services/<optional:subdirectory>";

and here is an example of what a real path might look like:
var qFCPre:String = "http://mygisserver/ArcGIS/rest/services/service_subdirectory";

You won't need the subdirectory if all your services are in the services directory.

Hope this helps.

Marc
0 Kudos
AmberReynolds
Deactivated User
Marc - I double checked the service and layer, and it's hitting the right one. Any other insight would be great!

Thanks,
Amber
0 Kudos
MarcWeinshenker1
Regular Contributor
Marc - I double checked the service and layer, and it's hitting the right one. Any other insight would be great!

Thanks,
Amber


Amber, 

Three questions.  Is the error coming up during compile or run time?  Did you add the set of import statements I listed to the MapManager.mxml?  And, from the error saying it came across an unexpected < , did you do a text search on MapManager.mxml to see if there is a stray angle bracket?

Marc
0 Kudos
AmberReynolds
Deactivated User
Marc -
1) Run Time
2) Yes, I added the import statements
3) Yes, I checked for that too

Thanks again!!

Amber, 

Three questions.  Is the error coming up during compile or run time?  Did you add the set of import statements I listed to the MapManager.mxml?  And, from the error saying it came across an unexpected < , did you do a text search on MapManager.mxml to see if there is a stray angle bracket?

Marc
0 Kudos
RobertScheitlin__GISP
MVP Emeritus
Marc and Amber,

Marc, hope you don't mind I'm going to jump in and see if I can help.

Amber, can you post your code for the mapLoadComplete function that you are attempting to use?
0 Kudos
MarcWeinshenker1
Regular Contributor
Marc and Amber,

Marc, hope you don't mind I'm going to jump in and see if I can help.

Amber, can you post your code for the mapLoadComplete function that you are attempting to use?


I'll gladly pass the baton....
0 Kudos
AmberReynolds
Deactivated User
Ah - Robert! Seeing your name jingled something loose in my head. My error may be larger than this code to pass parameters in the RUL. A few months ago I had downloaded and modified your SalesWidget (found here in this thread), and remembered I also received the exact same error. After a quick search for a solution, I just gave up.

Here's the code I'm using to modify the URL query string in the mapLoadComplete function in MapManager.mxml
Import declarations:
import com.esri.ags.FeatureSet;
import com.esri.ags.geometry.Polygon;
import com.esri.ags.layers.GraphicsLayer;
import com.esri.ags.tasks.QueryTask;
import com.esri.ags.tasks.supportClasses.Query;
import mx.rpc.AsyncResponder;

ViewerContainer.dispatchEvent(new AppEvent(AppEvent.LAYER_LOADED));
  var urlSubstring:String = ExternalInterface.call("window.location.search.substring", 1); 
     if (urlSubstring != ""){  // Parse URL
       var totalLength:Number = urlSubstring.length;
       var i:int = 0;
       var firstLetter:String = urlSubstring.charAt(i);
       var firstEqualsSignLocation:Number =  urlSubstring.indexOf('=');
       var firstStarLocation:Number =  urlSubstring.indexOf('*');
       var firstExclamtionLocation:Number = urlSubstring.indexOf('!');           
   
           if (firstLetter == "q"){  // Parcel Query
      
               var label:String = "Processing query...  please wait."
               var queryTask:QueryTask = new QueryTask();
               var qGlyr:GraphicsLayer = new GraphicsLayer();
               map.addLayer(qGlyr);
               var graphicLineSym:SimpleLineSymbol = new SimpleLineSymbol("solid", 0xFFFF00, 0.8, 2); // Yellow outline
               var graphicPolySym:SimpleFillSymbol = new SimpleFillSymbol("solid", 0xFF0000, 0.5, graphicLineSym); // Red fill
               var qValue:String = urlSubstring.substring( (firstEqualsSignLocation + 1),firstExclamtionLocation);
               var qValueLyr:String = urlSubstring.substring( (firstExclamtionLocation + 1),firstStarLocation); 
               var vValue:String = urlSubstring.substring( (firstStarLocation + 3),totalLength);
               var qFCPre:String = "<theservername>/arcgis/rest/services/";
               var qFCSuf:String = "/MapServer/";       
               var queryLayer:String = qFCPre + qValue + qFCSuf + qValueLyr;
               var query:Query = new Query();
               query.returnGeometry = true;
               query.text = vValue;
               queryTask.url = queryLayer;
               queryTask.execute(query, new AsyncResponder(onResult, onFault));
      
               function onResult(featureSet:FeatureSet, token:Object = null):void {
                  qGlyr.clear(); // clear the graphics layer
                  if (featureSet.features.length == 0) {
                    Alert.show("No Parcels matched. Please try again.");
                    }
                  else {
                    var unionExtent:Extent;
                    var myFirstGraphic:Graphic = featureSet.features[0];
                    unionExtent = Polygon(myFirstGraphic.geometry).extent;
                       for each (var myGraphic1:Graphic in featureSet.features){
                           myGraphic1.symbol = graphicPolySym;
                           qGlyr.add(myGraphic1);
                           unionExtent = unionExtent.union(Polygon(myGraphic1.geometry).extent);
                   }
        
               map.extent = unionExtent; // Zoom to queried polygon
               }
               }
               function onFault(info:Object, token:Object = null):void {
               Alert.show(info.toString());
               } 
               } 
               } // LCRA - URL Modification ends here      


Anyway  - again any insight is much appreciated!

Amber
Jackson Co, Missouri
0 Kudos