function init() { //create map and add layer map = new esri.Map("mapDiv"); var layer = new esri.layers.ArcGISDynamicMapServiceLayer("http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Specialty/ESRI_StatesCitiesRivers_USA/MapServer"); map.addLayer(layer); //initialize query task queryTask = new esri.tasks.QueryTask("http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Specialty/ESRI_StatesCitiesRivers_USA/MapServer/0"); //initialize query query = new esri.tasks.Query(); query.returnGeometry = true; query.outFields = ["CITY_NAME", "STATE_NAME", "POP1990"]; //initialize InfoTemplate infoTemplate = new esri.InfoTemplate("${CITY_NAME}", "Name : ${CITY_NAME}<br/> State : ${STATE_NAME}<br />Population : ${POP1990}"); //create symbol for selected features symbol = new esri.symbol.SimpleMarkerSymbol(); symbol.setStyle(esri.symbol.SimpleMarkerSymbol.STYLE_SQUARE); symbol.setSize(10); symbol.setColor(new dojo.Color([255,255,0,0.5])); }
function showResults(featureSet) { //remove all graphics on the maps graphics layer map.graphics.clear(); //Performance enhancer - assign featureSet array to a single variable. var resultFeatures = featureSet.features; //Loop through each feature returned for (var i=0, il=resultFeatures.length; i<il; i++) { //Get the current feature from the featureSet. //Feature is a graphic var graphic = resultFeatures; graphic.setSymbol(symbol); //Set the infoTemplate. graphic.setInfoTemplate(infoTemplate); //Add graphic to the map graphics layer. map.graphics.add(graphic); } }
What i think is, you cannot get symbology in QueryTask from the server.
If you want symbology, you may want to use the FeatureLayer. The FeatureLayer will, by default, use the drawing information (symbology and domains) from the server
5. Initialize the Symbol you want to use for displaying the highlighted features on the map.
OK - old topic, but doe the same apply for the idtask ? Symbolgy isn't returned, just the geometry? has anything changed over the years?
Adrain,
No nothing has changed. The symbol is not something that is returned from the Identify task. You will have to make a esriRequest call to the service to get the renderer json info and in code create the renderer from that json and then use the getSymbol method on the renderer to get the symbol that that specific graphic should have or apply the renderer to the layer/graphics you create from the IdentTask results.
Cheers - one for a day when I've not much on. My ID task already has the ability to take the geometry and create a simply highlighted feature to help the users pick out a feature where there are scores overlapping, but we want that added graphic to have similar styling to the layer, so by switching the layer off you get left with just the single added graphic for the required feature. Mainly for printout reasons
Check out getSymbol (3.x) and getDisplayedSymbol (4.x) as they might provide a way to use the renderer of the source layer and the graphic from the returned query/identify to retrieve a specific symbol. In 4.x I normally create a FeatureLayer (using client-side graphics) with the same render as the source layer and then add the query/identify results to it. Critical to both of these approaches is that the returned graphic must have all the necessary attributes and values so the renderer can figure out the correct symbol to use or return.
Thanks for that - in the end I went about it totally differently.
I have all the results of the ID task appear in a table - one table per layer - just like they used to in ArcIMS
At the end of each row (feature) I now have a button - this button takes the OBJECTID of that feature and the feature number and applies a filter to that layer. So the result is exactly what the users want - in those areas where there a 100s of features, they can ID the one they want, hit the button, and only that one is left - they then can print out just that one feature, without the others messing with the map.
Another button clears all these Isolations
The only pre-req is the existence of OBJECTID - which isn't a given - so much of our data are from other Esrti sites, that when they are imported the old OBJECTID is ignored and a new OBJECTID_1 is set up. But that can be resolved.