Select to view content in your preferred language

how  to  get  the selected  feature  by infowindow?

1929
3
10-24-2012 11:32 PM
yanli
by
Emerging Contributor
how  to  get the   selected   feature  by  infowindow??
Just like  map.infoWindow.getSelectedFeature() in the    " esri.dijit.Popup"
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> 
<html> 
  <head> 
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/> 
    <meta http-equiv="X-UA-Compatible" content="IE=7,IE=9" /> 
    <!--The viewport meta tag is used to improve the presentation and behavior of the samples  
      on iOS devices--> 
    <meta name="viewport" content="initial-scale=1, maximum-scale=1,user-scalable=no"/> 
    <title>QueryTask with query geometry from another task</title> 
    <link rel="stylesheet" type="text/css" href="http://serverapi.arcgisonline.com/jsapi/arcgis/3.2/js/dojo/dijit/themes/claro/claro.css"> 
    <link rel="stylesheet" type="text/css" href="http://serverapi.arcgisonline.com/jsapi/arcgis/3.2/js/esri/css/esri.css" /> 
 
      
    <script type="text/javascript" src="http://serverapi.arcgisonline.com/jsapi/arcgis/?v=3.2"></script> 
 
    <script type="text/javascript"> 
      dojo.require("esri.map"); 
      dojo.require("esri.tasks.query"); 
      dojo.require("esri.tasks.geometry"); 
 
      var map; 
      /*Initialize map, buffer, & query params*/ 
      function init() { 
        var startExtent = new esri.geometry.Extent({"xmin":-13165918,"ymin":3997806,"xmax":-13149675,"ymax":4007360,"spatialReference":{"wkid":102100}}); 
        map = new esri.Map("mapDiv", { extent: startExtent }); 
        //listen for when map is loaded and then add query functionality 
        dojo.connect(map, "onLoad", initFunctionality); 
 
        var streetMap = new esri.layers.ArcGISTiledMapServiceLayer("http://server.arcgisonline.com/ArcGIS/rest/services/World_Street_Map/MapServer"); 
        map.addLayer(streetMap); 
      } 
 
      function initFunctionality(map) { 
        var queryTask = new esri.tasks.QueryTask("http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Demographics/ESRI_Census_USA/MapServer/1"); 
        var queryTaskTouches = new esri.tasks.QueryTask("http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Demographics/ESRI_Census_USA/MapServer/1"); 
 
        //identify proxy page to use if the toJson payload to the geometry service is greater than 2000 characters. 
        //If this null or not available the buffer operation will not work.  Otherwise it will do a http post to the proxy. 
        esri.config.defaults.io.proxyUrl = "/arcgisserver/apis/javascript/proxy/proxy.ashx"; 
        esri.config.defaults.io.alwaysUseProxy = false; 
 
        // Query 
        var query = new esri.tasks.Query(); 
        query.returnGeometry = true; 
        query.outFields = ["POP2000","POP2007","MALES", "FEMALES", "FIPS"]; 
        query.outSpatialReference = {"wkid":102100}; 
         
        var infoTempContent = "POP2007 = ${POP2007}<br/>POP2000 = ${POP2000}<br/>MALES = ${MALES}<br/>FEMALES = ${FEMALES}" 
            + "<br/><A href='#' onclick='map.graphics.clear();getfeature();'>Remove Selected Features</A>"; 
        //Create InfoTemplate for styling the result infowindow. 
        var infoTemplate = new esri.InfoTemplate("Block: ${FIPS}", infoTempContent); 
        map.infoWindow.resize(275,190); 
 
        var currentClick = null; 
        // +++++Listen for map onClick event+++++ 
        dojo.connect(map, "onClick", function(evt) { 
          map.graphics.clear(); 
          map.infoWindow.hide(); 
          currentClick = query.geometry = evt.mapPoint; 
          query.spatialRelationship = esri.tasks.Query.SPATIAL_REL_INTERSECTS; 
          queryTask.execute(query); 
          dojo.byId('messages').innerHTML = "<b>Executing Point Intersection Query...</b>"; 
        }); 
 
        var firstGraphic = null; 
        // +++++Listen for QueryTask onComplete event+++++ 
        dojo.connect(queryTask, "onComplete", function(graphics) { 
          firstGraphic = graphics.features[0]; 
          var symbol = new esri.symbol.SimpleFillSymbol(esri.symbol.SimpleFillSymbol.STYLE_SOLID, new esri.symbol.SimpleLineSymbol(esri.symbol.SimpleFillSymbol.STYLE_SOLID, new dojo.Color([100,100,100]), 3), new dojo.Color([255,0,0,0.20])); 
          firstGraphic.setSymbol(symbol); 
          firstGraphic.setInfoTemplate(infoTemplate); 
 
          map.graphics.add(firstGraphic); 
          
         
        }); 
 
 
      } 
   function  getfeature()
   {
   
      if(map.infoWindow.isShowing){
   alert("have the feature")
            var loc = map.infoWindow.getSelectedFeature().geometry;
   
   var lg=loc.rings.length;
   alert(lg);
          //  if(!map.extent.contains(loc)){
          //    map.infoWindow.hide();
          //  }
          }
    else
    {
    
    alert("No the  feature");
    }

   }
 

      dojo.addOnLoad(init); 
    </script> 
  </head> 
 
  <body class="claro"> 
    Click on map to select census block group that intersects the map click and all block groups that touch selected group. 
    <div id="mapDiv" style="width: 850px; height:500px; position:relative;"></div> 
    <span id="messages"></span> 
  </body> 
</html> 
0 Kudos
3 Replies
DawenXie
Regular Contributor
If you just wanted to get the feature from the first query result, it has been stored in "firstGraphic" once the query task finished. "firstGraphic = graphics.features[0];"
0 Kudos
yanli
by
Emerging Contributor
it  maybe  well  ,if it  is  a  identify  task  with  one   return  feature,

but  if  it  is  a  query  task  with  many  return  feature  view  on  the  map
how  to  get  the each   feature  by  the button click  in  the each   infowindow  ?
0 Kudos
DawenXie
Regular Contributor
I see. I was commenting on the example you gave.

Since the Popup is an implementation of InfoWindow and provided the functionality you need, I'm wondering why you do not want to use the Popup.

it  maybe  well  ,if it  is  a  identify  task  with  one   return  feature,

but  if  it  is  a  query  task  with  many  return  feature  view  on  the  map
how  to  get  the each   feature  by  the button click  in  the each   infowindow  ?
0 Kudos