tonylife

Show specific feature of feature layer on map using OnDemand mode

Discussion created by tonylife on Apr 22, 2013
Latest reply on Apr 23, 2013 by tonylife
Is there a way to just show specific feature on the map based on query under OnDemand mode?

Our app creates map from ArcGIS online webmap only.
From my understanding, webmap loads featurelayers in OnDemand mode without a way to change the mode.
In this case, once web map get loaded, I hide all of feature layers, and try to show feature based on conditions.
Based on query result, I copied feature to a graphic and add the graphic to the map.
The graphic does get added to the map JSON object.
But it seems graphic is not showing on UI.

Please help!

/Tony

 
        var query = new esri.tasks.Query();
        query.where = "CMMS_ID = 45";
        query.outFields = ["*"];
        map.getLayer('Flap_Gate').queryFeatures(query, function (featureSet) {
            
            map.graphics.clear();
            var symbol = new esri.symbol.SimpleLineSymbol(esri.symbol.SimpleLineSymbol.STYLE_SOLID, new dojo.Color([255, 0, 0]), 20);
            var infoTemplate = new esri.InfoTemplate("Attributes", "${*}");
            //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];
                graphic.setSymbol(symbol);
                graphic.setInfoTemplate(infoTemplate);
                //Add graphic to the map graphics layer.
                map.graphics.add(graphic);
            }

        });

Outcomes