ivan8422

problems with to see feature atributes of any service

Discussion created by ivan8422 on Jul 21, 2010
Hi, i have problems with queryTask.execute(query, function (fset), in a code, I do not know why the function not return the featureset, I do not know if when creating the service needed to do something special, the code is as folws.


<!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" />
    <title>Jorge ivan ramirez</title>
    <link rel="stylesheet" type="text/css" href="http://serverapi.arcgisonline.com/jsapi/arcgis/1.6/js/dojo/dijit/themes/tundra/tundra.css">
    <script type="text/javascript" src="http://serverapi.arcgisonline.com/jsapi/arcgis/?v=1.6"></script>
    <script type="text/javascript" language="Javascript">
      dojo.require("esri.map");
      dojo.require("esri.tasks.query");

      var map, queryTask, query;
      var featureSet;
   var pt = null;

      function init() {
  var startExtent = new esri.geometry.Extent(1000000, 1000000,1500000, 1500000, new esri.SpatialReference({wkid:3116}) );

        //create map
        map = new esri.Map("mapDiv", {extent:startExtent});

        //var tiledLayer = new esri.layers.ArcGISTiledMapServiceLayer("http://server.arcgisonline.com/ArcGIS/rest/services/ESRI_Imagery_World_2D/MapServer");
        //map.addLayer(tiledLayer);

        //create and add new layer
        //var dynamicLayer = new esri.layers.ArcGISDynamicMapServiceLayer("http://hocol-gis/arcgis/rest/services/fusion/MapServer");
  var dynamicLayer2 = new esri.layers.ArcGISDynamicMapServiceLayer("http://hocol-gis/arcgis/rest/services/fusion/MapServer");
        //map.addLayer(dynamicLayer);
        //var layerDefs = [];
  //layerDefs[1] = "CONTRATO_N = 'NISCOTA'";

  //dynamicLayer2.setLayerDefinitions(layerDefs);
  map.addLayer(dynamicLayer2);
  //Listen for click event on the map, when the user clicks on the map call executeQueryTask function.
        dojo.connect(map, "onClick", executeQueryTask);
  //Listent for infoWindow onHide event
        dojo.connect(map.infoWindow, "onHide", function() {map.graphics.clear();});
 
  //build query task
        queryTask = new esri.tasks.QueryTask("http://hocol-gis/arcgis/rest/services/fusion/MapServer/1");

        //Can listen for onComplete event to process results or can use the callback option in the queryTask.execute method.
        //dojo.connect(queryTask, "onComplete", showResults);

        //build query filter
        query = new esri.tasks.Query();
       
        query.returnGeometry = false;
        query.outFields = ["MOD_ESTADO", "CONTRATO_N", "AREA__Ha_"];
 
}

function executeQueryTask(evt) {
        map.infoWindow.hide();
        map.graphics.clear();
        featureSet = null;
        //onClick event returns the evt point where the user clicked on the map.
        //This is contains the mapPoint (esri.geometry.point) and the screenPoint (pixel xy where the user clicked).

        query.where = "CONTRATO_N = 'NISCOTA'";

        //Execute task and call showResults on completion
        queryTask.execute(query, function (fset) {
    alert("Nombre:  " + fset.features.length);
   
          if (fset.features.length === 1) {
            showFeature(fset.features[0],evt);
          } else if (fset.features.length !== 0) {
            showFeatureSet(fset,evt);
          }
        });

      }


function showFeature(feature,evt) {
        map.graphics.clear();

        //set symbol
        var symbol = new esri.symbol.SimpleFillSymbol(esri.symbol.SimpleFillSymbol.STYLE_SOLID, new esri.symbol.SimpleLineSymbol(esri.symbol.SimpleLineSymbol.STYLE_SOLID, new dojo.Color([255,0,0]), 2),   new dojo.Color([255,255,0,0.5]));
        feature.setSymbol(symbol);
 
        //construct infowindow title and content
        var attr = feature.attributes;
       
  var title = attr.MOD_ESTADO;
 
        var content = "Field ID : " + attr.MOD_ESTADO
                    + "<br />Produces Gas : " + attr.CONTRATO_N;
        map.graphics.add(feature);
 
        map.infoWindow.setTitle(title);
        map.infoWindow.setContent(content);

        (evt) ? map.infoWindow.show(evt.screenPoint,map.getInfoWindowAnchor(evt.screenPoint)) : null;
      }
  
  
 
function showFeatureSet(fset,evt) {
   //remove all graphics on the maps graphics layer
   map.graphics.clear();
   var screenPoint = evt.screenPoint;

   featureSet = fset;

   var numFeatures = featureSet.features.length;

   //QueryTask returns a featureSet.  Loop through features in the featureSet and add them to the infowindow.
   var title = "You have selected " + numFeatures + " fields.";
   var content = "Please select desired field from the list below.<br />";

   for (var i=0; i<numFeatures; i++) {
     var graphic = featureSet.features[i];
     content = content + graphic.attributes.MOD_ESTADO + " Field (<A href='#' onclick='showFeature(featureSet.features[" + i + "]);'>show</A>)<br/>";
   }
   map.infoWindow.setTitle(title);
   map.infoWindow.setContent(content);
   map.infoWindow.show(screenPoint,map.getInfoWindowAnchor(evt.screenPoint));
    }

dojo.addOnLoad(init);
    </script>
  </head>
  <body class="tundra">
    Click on a petrolueum field to get more info.  If mulitple fields are selected then you can select the field to display.
    <div id="mapDiv" style="width:800px; height:600px; border:1px solid #000;"></div>
  </body>
</html>

Outcomes