Why wont ClosestFacilityParameters Facilities populate?

3146
2
11-11-2015 09:21 AM
AndrewDavis2
New Contributor III

Hi, I have a FindClosestFacility task published on my 10.2 server.  It works just fine with a point generated on my jsapi map as the incident.  However, I cannot get a set of facilities (26 of them) to populate to the "params.facilities" .  Below is the javascript I am using to try and do this with.   **Forgive me, but I can't figure out the format as script in this new interface**

The odd thing is I can put all 26 of the facilities into my browser endpoint for this, hit 'Post', and get answers back just fine.  But not here.  I've played with this in Chrome, FireFox (FireBug) and no facilities make it into the network traffic.

Any help would be most welcome.

Andy..

function callTheClosest(pt, map) {

            try {             

                params = new ClosestFacilityParameters();

                var location = new Graphic(pt);

                incidentsGraphicsLayer.add(location);                                              

                params.impedenceAttribute = "Miles";

                params.defaultCutoff = 7.0;

                params.returnIncidents = false;

                params.returnRoutes = true;

                params.returnDirections = true;

                routeGraphicLayer = new GraphicsLayer();

                var routePolylineSymbol = new SimpleLineSymbol(

                  SimpleLineSymbol.STYLE_SOLID,

                  new Color([89, 95, 35]),

                  4.0

                );

                var routeRenderer = new SimpleRenderer(routePolylineSymbol);

                routeGraphicLayer.setRenderer(routeRenderer);

                map.addLayer(routeGraphicLayer);

                

                 //limited here for the sake of this post         

                var myFacilities = new FeatureSet();

                myFacilities.features = {

                    "type": "features",

                    "features": [

                        { "geometry": { "x": -10787913.494708639, "y": 3863379.223503378, "spatialReference": { "wkid": 102100 } } },

                        { "geometry": { "x": -10766632.183609722, "y": 3880144.7048543575, "spatialReference": { "wkid": 102100 } } },                       

                        { "geometry": { "x": -10780407.638873382, "y": 3850484.94712767, "spatialReference": { "wkid": 102100} } },

                        { "geometry": { "x": -10776983.283847023, "y": 3881291.5947306715, "spatialReference": { "wkid": 102100} } },

                        { "geometry": { "x": -10775121.812611572, "y": 3895000.163088483, "spatialReference": { "wkid": 102100} } },

                        { "geometry": { "x": -10770883.746324655, "y": 3876436.115831069, "spatialReference": { "wkid": 102100} } },

                        { "geometry": { "x": -10764544.326520529, "y": 3866776.454696822, "spatialReference": { "wkid": 102100} } },

                        { "geometry": { "x": -10780675.771202894, "y": 3895735.085189703, "spatialReference": { "wkid": 102100} } },

                        { "geometry": { "x": -10782024.923372362, "y": 3877269.7042271197, "spatialReference": { "wkid": 102100} } }

                    ],

                    "doNotLocateOnRestrictedElements": true

                };

                params.facilities = myFacilities;

                params.returnIncidents = true;

                params.returnFacilities = true;

                var features = [];

                features.push(location);

                var incidents = new FeatureSet();

                incidents.features = features;

                params.incidents = incidents;

                params.outSpatialReference = map.spatialReference;          

                closestFac = new ClosestFacilityTask("myURL");

                closestFacilityTask.solve(params, function (solveResult) {

                    array.forEach(solveResult.routes, function (route, index) {

                        //build an array of route info

                        var attr = array.map(solveResult.directions[index].features, function (feature) {

                            return feature.attributes.text;

                        });

                        var infoTemplate = new InfoTemplate("Attributes", "${*}");

                        route.setInfoTemplate(infoTemplate);

                        route.setAttributes(attr);

                        routeGraphicLayer.add(route);

                        dom.byId("directionsDiv").innerHTML = "Hover over the route to view directions";

                    });

                    //display any messages

                    if (solveResult.messages.length > 0) {

                        dom.byId("directionsDiv").innerHTML = "<b>Error:</b> " + solveResult.messages[0];

                    }

                });

                                        

            }

            catch (e) {

                console.log("TROUBLE inside the callTheClosest: " + e.message);

            }          

        }

0 Kudos
2 Replies
RobertScheitlin__GISP
MVP Emeritus

Andrew,

    A FeatureSets Features property is a array of graphics. You are supplying it with a object that has a property called features that is an array.

I am not where I can test this but I think it should be like this instead:

myFacilities.features = [
    { "geometry": { "x": -10787913.494708639, "y": 3863379.223503378, "spatialReference": { "wkid": 102100 } } },
    { "geometry": { "x": -10766632.183609722, "y": 3880144.7048543575, "spatialReference": { "wkid": 102100 } } },
    { "geometry": { "x": -10780407.638873382, "y": 3850484.94712767, "spatialReference": { "wkid": 102100} } },
    { "geometry": { "x": -10776983.283847023, "y": 3881291.5947306715, "spatialReference": { "wkid": 102100} } },
    { "geometry": { "x": -10775121.812611572, "y": 3895000.163088483, "spatialReference": { "wkid": 102100} } },
    { "geometry": { "x": -10770883.746324655, "y": 3876436.115831069, "spatialReference": { "wkid": 102100} } },
    { "geometry": { "x": -10764544.326520529, "y": 3866776.454696822, "spatialReference": { "wkid": 102100} } },
    { "geometry": { "x": -10780675.771202894, "y": 3895735.085189703, "spatialReference": { "wkid": 102100} } },
    { "geometry": { "x": -10782024.923372362, "y": 3877269.7042271197, "spatialReference": { "wkid": 102100} } }
];

and doNotLocateOnRestrictedElements is a property of the ClosestFacilityParameters object not the feature array.

0 Kudos
AndrewDavis2
New Contributor III

Robert,

Thanks..  the array looks better.  I'm working with it now, want to chew on it more.  Currently getting a "TROUBLE inside the callTheClosest: a.toJson is not a function" error inside the esri jsapi.

I will keep on it and come back with it again.

Andy

0 Kudos