kdoman

unable to get geometry of featureset from query result

Discussion created by kdoman on Dec 9, 2010
Latest reply on Dec 20, 2010 by kdoman
I'm trying to figure out what is going wrong.  This function posts the results of a query on the map, and provides different symbology based on whether it is a point, line, or polygon.  The problem is, my code stops working when I try to access the geometry type of the features in the featureset.  All attempts to get either the geometryType or the geometry.type either return undefined, or don't return at all.

function queryShowResults(featureSet) {
    //show results on map
    map.graphics.clear();
    var markerSymbol = new esri.symbol.SimpleMarkerSymbol(esri.symbol.SimpleMarkerSymbol.STYLE_SQUARE, 10, new esri.symbol.SimpleLineSymbol(esri.symbol.SimpleLineSymbol.STYLE_SOLID, new dojo.Color([255, 0, 0]), 1), new dojo.Color([0, 255, 0, 0.25]));
    var lineSymbol = new esri.symbol.SimpleLineSymbol(esri.symbol.SimpleLineSymbol.STYLE_DASH, new dojo.Color([255, 0, 0]), 1);
    var polygonSymbol = new esri.symbol.SimpleFillSymbol(esri.symbol.SimpleFillSymbol.STYLE_SOLID, new esri.symbol.SimpleLineSymbol(esri.symbol.SimpleLineSymbol.STYLE_DASHDOT, new dojo.Color([255, 0, 0]), 2), new dojo.Color([255, 255, 0, 0.25]));
    //QueryTask returns a featureSet.  Loop through features in the featureSet and add them to the map.
    for (var i = 0, il = featureSet.features.length; i < il; i++) {
        //Get the current feature from the featureSet.
        //Feature is a graphic
        var graphic = featureSet.features[i];
        switch (graphic.geometry.type) {
            case "point":
                alert("point");
                graphic.setSymbol(markerSymbol);
                break;
            case "polyline":
                alert("polyline");
                graphic.setSymbol(lineSymbol);
                break;
            case "polygon":
                alert("polygon");
                graphic.setSymbol(polygonSymbol);
                break;
        }
        //Add graphic to the map graphics layer.
        map.graphics.add(graphic);
    }
        
}

Outcomes