I am using map.graphic layer to present a query result, which is a featureset. I assigned symbol and template to the graphics and added them to map.graphics. However, when I apply the function, it doesn't display the graphics. I added another single graphic to the map and it presents well. Can anybody help me with the issue?
Here is the webpage:
When you hit the select, and then click the apply it will execute the function.
Here is the query and display part of code:

var whereExpression = "";
myQueryTask = new QueryTask("http://arcgis-cabhpgis-2026970499.us-west-1.elb.amazonaws.com/arcgis/rest/services/HCIC/160524_interactive_map_jzz_v02/MapServer/0");
myQuery = new Query();
myQuery.returnGeomery = true;
function executeQuery(){
    console.log("executequery started");
    whereExpression = "";
        if(i==0) {
            whereExpression += ("ServiceProvided LIKE '%" + serviceList[i] + "%'");
            whereExpression += (" AND ServiceProvided LIKE '%" + serviceList[i] + "%'");
    myQuery.where = whereExpression;
    console.log("where statement completed in executequery function");
    console.log("myquerytask completed in executequery function");
var symbolPoint = new SimpleMarkerSymbol(SimpleMarkerSymbol.STYLE_X, 10,
    new SimpleLineSymbol(SimpleLineSymbol.STYLE_SOLID, new Color([255, 0, 0]), 1),
    new Color([0, 255, 0, 0.25]));
function showResults (results) {
    console.log("showresults started");
    console.log("total graphics in graphics layer: " +mainMap.graphics.graphics.length);
    dom.byId("info").innerHTML = results.features.length;
    for (var i=0; i<results.features.length; i++){
        var aGraphic = results.features[i];
        console.log("one feature launched, total graphics in graphics layer: " +mainMap.graphics.graphics.length);
    console.log("showresults finished");
mainMap.on("load", function () {
    var point = new Point([-112,34.3]);
    var pointGraphic = new Graphic(point, symbolPoint);
    console.log("one feature launched, total graphics in graphics layer: " +mainMap.graphics.graphics.length);

You can check the full code from the link.

1 Answer 1


you don't have graphics on map because :

1-the service returns feature without geometry attribute .

and this is due to a typing error in your above code :

Just rectify the line myQuery.returnGeomery = true; ( t letter missed ) to this myQuery.returnGeometry = true;

2- in the showResults function : inside the loop you didn't make instanciation of the Graphic object you are adding a feature object to map :

use esri/graphic to instanciate new graphic objectfor each returned feature :

function showResults (results) {
    dom.byId("info").innerHTML = results.features.length;
    var aGraphic
    for (var i=0; i<results.features.length; i++){
         aGraphic = new Graphic( results.features[i].geometry, //assigning geometry
                                 symbolPoint, //assigning symbol
                                 results.features[i].attributes, //assigning attributes
                                 BHInfoTemplate );//assigning template to graphic
        console.log("one feature launched, total graphics in graphics layer: " +mainMap.graphics.graphics.length);
    console.log("showresults finished");
  • Thanks for your help with the typing error! It was so stupid. However, I fixed it but the graphics still don't display. Is there any other error? I have updated the link to new version. Jun 7, 2016 at 17:23
  • ah yes you need to instantiate new Graphic I've add expalanation in my answer @DevilShankou hope it'll help Jun 7, 2016 at 20:17
  • I just realized that the code actually draws graphics but to wrong places. They are drew to west coast of Africa. I checked this question link and used the method mentioned in it. But it still doesn't work. Jun 7, 2016 at 20:43
  • @DevilShankou , does the query layer has the same coordinate system as your map ? ps : it seems that the gis server is not running ! Jun 8, 2016 at 8:50
  • The query layer has different coordinate system. I used NAD 1983. However, the map used the first layer's coordinate system, which is WGS 1984. Cause the base map is the first layer loaded to the map. It takes it as the map's coordinate system. I changed my coordinate system to WGS and republished map service. Now it works. But I am still curious about if there is way to change the map's coordinate system in code. I apologize for the server. I always turn it off when I leave my office. I will keep it on. Thanks very much! Jun 8, 2016 at 22:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.