Select to view content in your preferred language

Get Network attributes in Rest service from a flex query

1152
4
09-21-2011 04:26 AM
carinestolz
Emerging Contributor
Dear all,

I would like to get some Na Server Route details in my Flex website. Is there a function in the Flex api that can helps me in retrieving the details of my Network Analyst Layer, in my REST Service ?

For example, I would like to get the Network Attributes of usage type : esriNAUTCost, using a query like getDetails in the api (see image).

Many thanks for your help,

Best regards,

Carine
Tags (2)
0 Kudos
4 Replies
AndyGup
Esri Regular Contributor
@Carine, if you haven't already be sure to check out the samples in the online help, for example: http://help.arcgis.com/en/webapi/flex/samples/index.html#/Routing_around_barriers/01nq0000004m000000...

And, here is the link to the RouteParameters class documentation: http://help.arcgis.com/en/webapi/flex/apiref/com/esri/ags/tasks/supportClasses/RouteParameters.html

-Andy

Esri Developer Network (EDN)
0 Kudos
carinestolz
Emerging Contributor
Many thanks Andy for your reply but this is not exactly what I was looking for.

I am looking for a function that can help me in retreiving from my Flex application, some network attributes in the REST Api.

I would like to find a function like:

var networkLayer= new Layer("my_url.../NaServer")

//make a request on the rest api to get all the details of the NAServer Layer
var details = networkLayer.getDetails() 

// in the details, get the network_attributes : I can then get the several cost existing in my Network
var costs=details.network_attributes


Does something like that exists ?

Thanks for your help 🙂

Carine
0 Kudos
RobertScheitlin__GISP
MVP Emeritus
Carine,

   Sure you can parse the HTML response yourself in flex. As the values you are after are displayed in the REST endpoint then you can get same in Flex.

<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" 
               xmlns:s="library://ns.adobe.com/flex/spark" 
               xmlns:mx="library://ns.adobe.com/flex/mx"
               minWidth="955" minHeight="600"
                creationComplete="application1_creationCompleteHandler(event)">
    <fx:Declarations>
        <!-- Place non-visual elements (e.g., services, value objects) here -->
    </fx:Declarations>
    <fx:Script>
        <![CDATA[
            import com.esri.serialization.json.JSON;
            
            import mx.events.FlexEvent;
            import mx.rpc.events.FaultEvent;
            import mx.rpc.events.ResultEvent;
            import mx.rpc.http.HTTPService;
            import mx.utils.ObjectUtil;
            
            private var httpServ:HTTPService;
            
            
            private function xmlResult(event:ResultEvent):void
            {
                var Info:Object = JSON.decode(event.result.toString());
                trace(ObjectUtil.toString(Info.networkDataset.networkAttributes));
            }
            
            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);
            }
            
            protected function application1_creationCompleteHandler(event:FlexEvent):void
            {
                httpServ = new HTTPService;
                httpServ.url = "http://tasks.arcgisonline.com/ArcGIS/rest/services/NetworkAnalysis/ESRI_Route_NA/NAServer/Route?f=pjson";
                httpServ.addEventListener(ResultEvent.RESULT, xmlResult);
                httpServ.addEventListener(FaultEvent.FAULT, xmlFault);
                httpServ.send();
            }
            
        ]]>
    </fx:Script>
</s:Application>
0 Kudos
carinestolz
Emerging Contributor
Many thanks Robert for your reply.

I will use your example to code the function by myself.

Thanks again 🙂

Carine
0 Kudos