Select to view content in your preferred language

Autocomplete search box

3558
36
01-12-2011 04:13 AM
LemvigKommune
Deactivated User
Hi.

I've just uploaded my AutocompleteSearch widget to arcgis.com - but

I would like it to iterate through multible url's and add the features in each url to the dropdownbox, but i can't get it to do just that.

If anybody has any idea as to how i could solve this, i'll be happy to hear about it.

Thanks
Mads Gren
Tags (2)
0 Kudos
36 Replies
ReneRubalcava
Esri Frequent Contributor
I have a widget with some functionality that can load services via a config.xml that might help.
http://www.arcgis.com/home/item.html?id=ca9e4de998714d07a6bdc59ededa0efc
/**
 * Takes URL for a ArcGIS Server Rest directory and
 * will attempt to extract the SiteMap.
 * @param directory
 */
protected function loadServices(servername:String):void
{
 var service:HTTPService = new HTTPService();
 var sitemap:String = "/ArcGIS/rest/services/?f=sitemap";
 var url:String = "http://" + servername + sitemap;
 service.url = url;
 service.resultFormat = "e4x";
 var token:AsyncToken = service.send();
 token.addResponder(new AsyncResponder(onServiceResults_handler, onFault_handler));
}

/**
 * Handles the results of accessing the SiteMap.
 * @param event
 * @param token
 */
protected function onServiceResults_handler(event:ResultEvent, token:Object = null):void
{
 var xml:XML = event.result as XML;
 var xmlColl:XMLListCollection = new XMLListCollection(xml.children());
 var list:Array = [];
 var qn:QName = new QName(sitemapNS, "loc");
 var sxml:XML;
 for each (sxml in xmlColl)
 {
  var url:String = sxml[qn].text();
  var tmp:Array = url.split("/");
  var i:uint = tmp.length;
  if (tmp[i-1] == "MapServer")
  {
   var item:ServiceItem = new ServiceItem();
   item.serverType = tmp[i-1];
   item.name = tmp[i-2];
   item.url = url;
   list.push(item);
   findServiceDetails(item);
  }
 }
 list.sortOn("name");
 dataList = new ArrayList(list);
 vUrls = new Vector.<String>(list.length);
 servicesList.dataProvider = dataList;
}

/**
 * Parses <code>ServiceItem</code> object url to find layer details
 * in service REST.
 * @param item
 */
protected function findServiceDetails(item:ServiceItem):void
{
 var jsonurl:String = "?f=json&pretty=false";
 var url:String = item.url + jsonurl;
 
 var srv:HTTPService = new HTTPService();
 srv.url = url;
 srv.resultFormat = "text";
 var token:AsyncToken = srv.send();
 token.addResponder(new mx.rpc.Responder(onJSONResult_handler, onFault_handler));
 
 function onJSONResult_handler(event:ResultEvent):void {
  var data:String = event.result.toString();
  // this regex replace can be used to make parsing the JSON faster.
  // It removes spaces, but it will mess up service description.
  //data = data.replace( /\s/g, '' );
  var details:Object = JSON.decode(data);
  item.description = details["serviceDescription"];
  if (!details["singleFusedMapCache"])
   item.type = DYNAMIC;
  else
   item.type = TILED;
 }
}


This will get you as far as loading the individual URL's for each service in a server, like "sampleserver1.arcgisonline.com", then you can create a layers using the URL and pull out the Layer info via layerInfos. I have a function for another tool that does just that.

/**
 * Will find all the items that make up a given map service layer.
 * @param lyr
 */
protected function findLayerDetails(lyr:Layer):void
{
 if (layers)
  layers.removeAll();
 
 layers = new ArrayList();
 var layerInfos:Array;
 layerIDSet = null;
 layerIDSet = {};
 if (lyr is ArcGISDynamicMapServiceLayer)
  layerInfos = ArcGISDynamicMapServiceLayer(lyr).layerInfos;
 else if (lyr is ArcGISTiledMapServiceLayer)
  layerInfos = ArcGISTiledMapServiceLayer(lyr).layerInfos;
 else if (lyr is FeatureLayer) {
  var lyrId:int = FeatureLayer(lyr).layerDetails.id;
  var lyrName:String = FeatureLayer(lyr).layerDetails.name;
  layerIDSet[lyrName] = lyrId;
  layers.addItem(lyrName);
 }
 
 if (layerInfos)
 {
  var info:LayerInfo;
  for each (info in layerInfos)
  {
   layerIDSet[info.name] = info.id;
   layers.addItem(info.name);
  }
 }
}
0 Kudos
LemvigKommune
Deactivated User
Thanks Rene

But there must be a simpler way beside using httpservices.
The thing i'm looking for is a way to iterate over a actionscript query, with different layerURL's and get it into an array.

But if nothing else comes up, i'll look at your code.

Mads
0 Kudos
ReneRubalcava
Esri Frequent Contributor
If you set up your xml config file to let you know the Layer type, "dynamic", "tiled", etc, you can iterate through your list, create layers, then iterate through the layers to get the layerinfos.
0 Kudos
LemvigKommune
Deactivated User
Hi again

I can almost see that, but i don't want more layers, all I want is the data from a single row, and the graphics so that i can use it as a searchbox

we are using it for our adresssPoints, but I would like to get the parcelID and the graphics from another services as well and put that into the dropdownlist, so that when my coworkers are starting to type, it sorts out the list for them, and when they hit enter it will pan and zoom to their selection.
0 Kudos
philippschnetzer
Frequent Contributor
Mads

Nice. Works very well.  Very configurable as well!  To improve the widget it would be nice to have it ignore null values in a table....and also to be able to see the letters you type into the search box.  With those two additions it would be absolutely perfect for me!

Again - good job!

- and perhaps also a clear graphics button...
0 Kudos
xanderm
Occasional Contributor
Is this widget affected by the maximum number of records returned by server (500)? Im not seeing all of my results in the drop down.
0 Kudos
LemvigKommune
Deactivated User
Hi Phillip
The thing about not seeing what you are typeing into the searchbox, is a problem i don't understand, have you tried my testsite ??

I'll look at the thing about ignore Null values and a clearbutton - thanks for the ideas....

Hi Xander - yes the widget is affected by the max. number in the service - and i can see that i have only told about this on the arcgis.com site, not in the info.txt file in the zip-file, sorry - i'll correct this soon - thanks.
0 Kudos
LemvigKommune
Deactivated User
Hi Philip

with the help from Robert S, the widget now iterater over multiple layers, and exclude null-values.

and the clear-button is added...

see arcgis.com

Mads

Mads

Nice. Works very well.  Very configurable as well!  To improve the widget it would be nice to have it ignore null values in a table....and also to be able to see the letters you type into the search box.  With those two additions it would be absolutely perfect for me!

Again - good job!

- and perhaps also a clear graphics button...
0 Kudos
PedroGarcia
Deactivated User
Hi Phillip
The thing about not seeing what you are typeing into the searchbox, is a problem i don't understand, have you tried my testsite ??

I'll look at the thing about ignore Null values and a clearbutton - thanks for the ideas....

Hi Xander - yes the widget is affected by the max. number in the service - and i can see that i have only told about this on the arcgis.com site, not in the info.txt file in the zip-file, sorry - i'll correct this soon - thanks.


I think that problem is because the backgroundcolor of searchbox is the same than text color (using for example Black Gold style colors, see attached image). Is it feasible that the searchbox background color uses the background color defined in style tag?

Concerning to the problem with the widget is affected by the maximum number of records returned by server, is there any workaround to solve this? (because my addressesPoints are thousands points).

Regards,
   Pedro.
0 Kudos