mylady

Select features by drawing a rectangle on the map

Discussion created by mylady on Oct 21, 2010
Latest reply on Oct 22, 2010 by a.schaefer-esri-de-esridist
hi ,all

i want to select features on the map by drawing a rectangle and i use the following js code,but i can't get any feature selected.

dojo.require("esri.map");
   dojo.require("esri.toolbars.draw");
dojo.require("esri.toolbars.navigation");
dojo.require("esri.tasks.query");

var map,mapdraw,tiledlayer,dynamiclayer;

function init(){
  map = new esri.Map("map");
  mapdraw = new esri.toolbars.Draw(map);
 
  dojo.connect(mapdraw,"onDrawEnd",drawEnd);
 
  tiledlayer = new esri.layers.ArcGISTiledMapServiceLayer("http://mylady-pc/ArcGIS/rest/services/image/MapServer");
  dynamiclayer = new esri.layers.ArcGISDynamicMapServiceLayer("http://mylady-pc/ArcGIS/rest/services/data/MapServer");
 
  map.addLayer(tiledlayer);
  map.addLayer(dynamiclayer);
}

function draw(){
  mapdraw.activate(esri.toolbars.Draw.EXTENT);
}

function drawEnd(geometry){
  map.graphics.clear();
  var  symbol = new esri.symbol.SimpleFillSymbol(esri.symbol.SimpleFillSymbol.STYLE_NONE,
             new esri.symbol.SimpleLineSymbol(esri.symbol.SimpleLineSymbol.STYLE_DASHDOT,
             new dojo.Color([255,0,0]), 2), new dojo.Color([255,255,0,0.25]));
  var graphic = new esri.Graphic(geometry,symbol);
  map.graphics.add(graphic);
  queryByGeometry(geometry);
  mapdraw.deactivate();
}

function queryByGeometry(geometry){
  var query = new esri.tasks.Query();
  var querytask = new esri.tasks.QueryTask("http://mylady-pc/ArcGIS/rest/services/data/MapServer/0");
  dojo.connect(querytask,"onComplete",queryComplete);
 
  query.returnGeometry = true;
  query.outFileds = ["Name","Mono"];
  query.spatialRelationship = esri.tasks.Query.SPATIAL_REL_CONTAINS;
  querytask.execute(query);
}

function queryComplete(featureSet){
  alert(featureSet.features.length);
}

dojo.addOnLoad(init);

Outcomes