Select to view content in your preferred language

Select point from Feature Layer, input into Service Area

1022
4
08-27-2013 08:44 AM
MatthewBorr
Deactivated User
I'm able to use a clicked point for an input facility in a Service Area solve. I can't figure out how to use a selected point from a feature layer in the same Service Area operation.

function initSelectToolbar(map) {
            selectionToolbar = new esri.toolbars.Draw(map);
           var selectQuery = new esri.tasks.Query();
     selectQuery.returnGeometry = true;
  
        
        dojo.connect(selectionToolbar, "onDrawEnd", function(geometry) {
          selectionToolbar.deactivate();
  
  
          selectQuery.geometry = geometry;
          featureSLayer.selectFeatures(selectQuery, esri.layers.FeatureLayer.SELECTION_NEW);
    var results = [];
    
      var pointSymbol = new esri.symbol.SimpleMarkerSymbol(
        esri.symbol.SimpleMarkerSymbol.STYLE_DIAMOND, 
        20,
        new esri.symbol.SimpleLineSymbol(
          esri.symbol.SimpleLineSymbol.STYLE_SOLID,
          new dojo.Color([88,116,152]), 2
        ),
        new dojo.Color([88,116,152,0.45])
      );
   
  
    //  var inPoint = new esri.geometry.Point(evt.mapPoint,map.spatialReference);
       //var location = new esri.Graphic(inPoint,pointSymbol);
   
      featureSLayer.getselectedfeatures();
     
      var facilities = new esri.tasks.FeatureSet();
      facilities.features = features;
      params.facilities = facilities;

        //solve 
   serviceAreaTask.solve(params,function(solveResult){
        var result = solveResult;
        var serviceAreaSymbol = new esri.symbol.SimpleFillSymbol(
        esri.symbol.SimpleFillSymbol.STYLE_SOLID,  
        new esri.symbol.SimpleLineSymbol(
       esri.symbol.SimpleLineSymbol.STYLE_SOLID, 
        new dojo.Color([232,104,80]), 2),
          new dojo.Color([232,104,80,0.25])
        );
  
        var polygonSymbol = new esri.symbol.SimpleFillSymbol(esri.symbol.SimpleFillSymbol.STYLE_SOLID,  new esri.symbol.SimpleLineSymbol(esri.symbol.SimpleLineSymbol.STYLE_SOLID, 
        new dojo.Color([232,104,80]), 2),new dojo.Color([232,104,80,0.25]));
        dojo.forEach(solveResult.serviceAreaPolygons, function(serviceArea){
        serviceArea.setSymbol(polygonSymbol);
        map.graphics.add(serviceArea);       
    
  var query = new esri.tasks.Query();
        query.geometry = serviceArea.geometry;
    
    
  var symbol = new esri.symbol.SimpleMarkerSymbol();
        symbol.style = esri.symbol.SimpleMarkerSymbol.STYLE_SQUARE;
       symbol.setSize(8);
       symbol.setColor(new dojo.Color([255,255,0,0.5]));
        featureSLayer.setSelectionSymbol(symbol);

          
          dojo.byId('messages').innerHTML = "<b>Selecting Features...</b>";
          featureSLayer.selectFeatures(query, esri.layers.FeatureLayer.SELECTION_NEW);
        });


Anyone know how to use a selected feature as an input into a Service Area?

Thanks!
0 Kudos
4 Replies
JasonZou
Frequent Contributor
Try this.
function initSelectToolbar(map) {
    selectionToolbar = new esri.toolbars.Draw(map);
    var selectQuery = new esri.tasks.Query();
    selectQuery.returnGeometry = true;
    dojo.connect(selectionToolbar, "onDrawEnd", function (geometry) {
        selectionToolbar.deactivate();
        selectQuery.geometry = geometry;
        featureSLayer.selectFeatures(selectQuery, esri.layers.FeatureLayer.SELECTION_NEW, generateServiceArea);
    });
}

function generateServiceArea(featureSet) {
    params.facilities = featureSet;     // assume params is a global variable

    // assume serviceAreaTask is defined as a global variable somewhere else
    serviceAreaTask.solve(params, function (solveResult) {
        var polygonSymbol = new esri.symbol.SimpleFillSymbol(
            esri.symbol.SimpleFillSymbol.STYLE_SOLID, 
            new esri.symbol.SimpleLineSymbol(
                esri.symbol.SimpleLineSymbol.STYLE_SOLID,
                new dojo.Color([232, 104, 80]), 
                2
            ), 
            new dojo.Color([232, 104, 80, 0.25])
        );
        
        dojo.forEach(solveResult.serviceAreaPolygons, function (serviceArea) {
            serviceArea.setSymbol(polygonSymbol);
            map.graphics.add(serviceArea);

            var query = new esri.tasks.Query();
            query.geometry = serviceArea.geometry;

            var symbol = new esri.symbol.SimpleMarkerSymbol();
            symbol.style = esri.symbol.SimpleMarkerSymbol.STYLE_SQUARE;
            symbol.setSize(8);
            symbol.setColor(new dojo.Color([255, 255, 0, 0.5]));
            featureSLayer.setSelectionSymbol(symbol);

            dojo.byId('messages').innerHTML = "<b>Selecting Features...</b>";
            featureSLayer.selectFeatures(query, esri.layers.FeatureLayer.SELECTION_NEW);
        });
    });
}
0 Kudos
MatthewBorr
Deactivated User
Thanks for replying and helping!

I inserted the code you provided and deleted my code at line 422. It's still not generating the service area when selecting a point from the feature layer. I know the network service is working because I have a test file that creates the service area when I click any place on the network.

Can you look at the file? The test network service is located on the blue dotted line route near the Michigan-Indiana border (around New Buffalo). The access points will select, but nothing happens afterward.

The file is located at:

http://lmwt.geography.wmich.edu/test2.html

Thanks again!
0 Kudos
JasonZou
Frequent Contributor
Now I see your code. But I have no idea which feature layer you like to click to get the service area. Tell me what you like to accomplish for the app, and I will see what I can make the code work.

By the way, it requires a login to access your map services.
0 Kudos
MatthewBorr
Deactivated User
Thanks for looking.

The short term goal is to select an access point (numbered points on shoreline) from the feature layer with the select toolbar. The selected point is the input to the service area which works on a network analysis service which is coincident with the kayak route feature layer (blue dotted lines in the water).

The service layer geometry then selects the access points within the polygon and highlights them. Sorry I was not clear before.

Not sure about the login problem, I will start working on that. For now try logging in with

arcadmin
wrEs3uy8

Thanks again!
0 Kudos