How to get at the definition query for a layer via flex

2995
13
08-10-2010 08:36 AM
BradleyMontgomery
New Contributor II
From within Flex I need to get at the definition query for a feature class in an MXD that's being used for a map service. I can see the definition query (it's called the Definition Expression) when I look at the properties of a map service layer through REST. However I cannot find a method to get at it through flex. LayerDetails returns just about everything else except the definition expression. Is there a function that returns the definition expression?

Thanks,

Charlie Ware
Tags (2)
0 Kudos
13 Replies
DavidGalluzzo
New Contributor
try using ArcGISDynamicMapServiceLayer.layerDefinitions. I use this to set layer definitions at run-time. Not sure if it displays layer Definitions defined from the MXD but know it will display layer definitions defined at run-time.
0 Kudos
BradleyMontgomery
New Contributor II
I tested this and the layer definitions are null unless I set one in the flex application. The layer definitions don't seem to contain the MXD definition query. Thanks though.
0 Kudos
RobertScheitlin__GISP
MVP Emeritus
Charlie,

   This is the best way I know how to get at it.

import mx.rpc.events.FaultEvent;
import mx.rpc.events.ResultEvent;
import mx.rpc.http.HTTPService;
import com.esri.serialization.json.JSON;

private var httpServ:HTTPService;

httpServ2 = new HTTPService;
httpServ2.url = "http://yourServer/arcgis/rest/services/yourService/mapserver/0?f=json";
httpServ2.addEventListener(ResultEvent.RESULT, xmlResult);
httpServ2.addEventListener(FaultEvent.FAULT, xmlFault);
httpServ2.send();

private function xmlResult(event:ResultEvent):void
{
    var Info:Object = JSON.decode(event.result.toString());
    var defExpr:String = Info.definitionExpression;
}

private function xmlFault(event:FaultEvent):void
{
    var sInfo:String = "Error: ";
    sInfo += "Event Target: " + event.target + "\n\n";
    sInfo += "Event Type: " + event.type + "\n\n";
    sInfo += "Fault Code: " + event.fault.faultCode + "\n\n";
    sInfo += "Fault Info: " + event.fault.faultString;
    trace(sInfo);
}
0 Kudos
BradleyMontgomery
New Contributor II
Thanks very much Robert!! What would we do without you.

Charlie
0 Kudos
PaulLang
New Contributor III
I would like to set the definition of a layer based on user input.  Has anyone done this?
0 Kudos
BarbaraPatterson
New Contributor
Hi Paul - Did you have any luck setting the definition query through flex? I wanted to make it a part of my geoprocessing model but have not have any luck with that approach.

Thanks

Barb
0 Kudos
PaulLang
New Contributor III
Just found the thread again, and no luck with the code!
0 Kudos
tanyabisen
New Contributor
Robert I was trying to implement your code but httpServ2,this variable.. throws an error..Am i missing something.. ?? I wanted to ask whether simultaneously it will be reflected in my TOC also ?
0 Kudos
RobertScheitlin__GISP
MVP Emeritus
Tanya,

   The code had a typo. You need to correct this line:

private var httpServ2:HTTPService;


You have been asking a lot about the TOC... There is no TOC component out of the box in the flex API so you need to be specific as to which sample or source code you are referring to. But the bottom line is NONE of the TOC's that I have seen respond to programmatic changes. If you want a certain layer to enabled by default than that layer needs to checked on in ArcMap before you publish the MXD. All the TOC's out there read the default visibility that is set by ArcMap.
0 Kudos