select and zoom to a feature works for polygon feature, but for polyline only zoom not select

3266
0
12-07-2014 07:23 PM
LiYao
by
New Contributor III


Hello everybody,

I have 2 layers in the map (1 polyline layer and 1 polygon layer), and a "select and zoom" function which will select a feature and zoom to it.

The strange thing is although I use the same code(except the geometry type), the result is different:

- for polygon feature : can select the feature and zoom to it properly.

- for polyline feature : only zoom to the feature, but never select the feature.

I cannot figure out why this happen, is this because of the layer data or something else?

The code I am using is as follows:

private function onSelectItem(e:ContextMenuEvent):void{
    if(datagrid.selectedIndex >= 0){ 
     this.cursorManager.setBusyCursor();
        
     if (datagrid.selectedItem.shape == "Polyline")
     {
      var query:Query = new Query;
      queryTask.url = "http://localhost:6080/arcgis/rest/services/MyService/MapServer/0";               
      query.where = "Segment_ID = '" + datagrid.selectedItem.segmentID + "'";        
      query.outSpatialReference = map.spatialReference;
      query.returnGeometry=true;

     queryTask.execute(query, new AsyncResponder(onResult, onFault)); 
     }
     else if (datagrid.selectedItem.shape == "Polygon")
     {
      var queryP:Query = new Query;
      queryTask.url = "http://localhost:6080/arcgis/rest/services/MyService/MapServer/1";
      queryP.where = "Segment_ID = '" + datagrid.selectedItem.segmentID + "'"; 
      queryP.outSpatialReference = map.spatialReference;
      queryP.returnGeometry=true;
      queryTask.execute(queryP, new AsyncResponder(onResultPolygon, onFault)); 
     }
    
    
     function onResult(featureSet:FeatureSet, token:Object = null):void 
     { 
      graphicsLayer.clear(); 
      if (featureSet.features.length == 0) 
      { 
       Alert.show("No feature found. Please try again."); 
      } 
      else 
      { 
       var unionExtent:Extent; 
       var myFirstGraphic:Graphic = featureSet.features[0]; 
       unionExtent = Polyline(myFirstGraphic.geometry).extent; 
      
       myFirstGraphic = new Graphic();
      
       for each (var myGraphic1:Graphic in featureSet.features) 
       { 
        myFirstGraphic.geometry = myGraphic1.geometry;
        graphicsLayer.add(myGraphic1);

        if(myGraphic1.geometry !== myFirstGraphic.geometry){ 
         unionExtent = unionExtent.union(Polyline(myGraphic1.geometry).extent); 
        } 
       } 
       map.extent = unionExtent;
      }
     }
    
     function onResultPolygon(featureSet:FeatureSet, token:Object = null):void 
     { 
      graphicsLayer.clear(); 
      if (featureSet.features.length == 0) 
      { 
       Alert.show("No feature found. Please try again."); 
      } 
      else 
      { 
       var unionExtent:Extent; 
       var myFirstGraphic:Graphic = featureSet.features[0]; 
       unionExtent = Polygon(myFirstGraphic.geometry).extent; 
      
       myFirstGraphic = new Graphic();     
      
       for each (var myGraphic1:Graphic in featureSet.features) 
       { 
        myFirstGraphic.geometry = myGraphic1.geometry;
        graphicsLayer.add(myGraphic1); 
       
        if(myGraphic1.geometry !== myFirstGraphic.geometry){ 
         unionExtent = unionExtent.union(Polygon(myGraphic1.geometry).extent); 
        } 
       }
       map.extent = unionExtent;
      }
     }
     function onFault(info:Object, token:Object = null):void 
     { 
      Alert.show(info.toString()); 
     }

}

I am using ArcGIS api for flex 3.6, thanks in advance.

0 Kudos
0 Replies