jihoon03

Can I use QueryTask for kml file?

Discussion created by jihoon03 on Apr 6, 2012
Latest reply on Dec 17, 2012 by jeff.pace
I am trying to select kml features using Buffer. I think I need to create QueryTask using "esri.tasks.QueryTask(url)" but it is not working for kml file.
Is there any way to select kml features without using QueryTask?

I tried to use "onBufferComplete" event, but it gives an error - code below.

      dojo.connect(kml, 'onLoad', function() {
        layers = kml.getLayers();
dojo.forEach(layers, function(layer){        
   if(layer.declaredClass === "esri.layers.FeatureLayer"){    
     var selectBufferQuery = new esri.tasks.Query();   
     dojo.connect(gsvc, "onBufferComplete", function(geometry) {
       selectBufferQuery.geometry = geometry;
       layer.selectFeatures(selectBufferQuery, esri.layers.FeatureLayer.SELECTION_NEW);
     });
   }
});
      });

Below is the code I used for creating 1 and 2 mile buffer.

      gsvc = new esri.tasks.GeometryService("http://tasks.arcgisonline.com/ArcGIS/rest/services/Geometry/GeometryServer");

      function doBuffer(evt) {
        map.graphics.clear();
        var params = new esri.tasks.BufferParameters();
        params.geometries = [ evt.mapPoint ];

        //buffer in linear units such as meters, km, miles etc.
        params.distances = [ 1, 2 ];
        params.unit = esri.tasks.GeometryService.UNIT_US_NAUTICAL_MILE;
        params.outSpatialReference = map.spatialReference;

        gsvc.buffer(params, showBuffer);
  map.centerAndZoom(evt.mapPoint, 12);
      }

      function showBuffer(geometries) {

        var symbol = new esri.symbol.SimpleFillSymbol(
          esri.symbol.SimpleFillSymbol.STYLE_SOLID,
          new esri.symbol.SimpleLineSymbol(
            esri.symbol.SimpleLineSymbol.STYLE_SOLID,
            new dojo.Color([0,0,255,0.65]), 2
          ),
          new dojo.Color([0,0,255,0.15])
        );

        dojo.forEach(geometries, function(geometry) {
          var graphicBuffer = new esri.Graphic(geometry,symbol);
          map.graphics.add(graphicBuffer);
        });
      }

Outcomes