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.
//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; 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>