Show specific feature of feature layer on map using OnDemand mode

624
3
04-22-2013 07:49 AM
tonylife
New Contributor III
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;
                graphic.setSymbol(symbol);
                graphic.setInfoTemplate(infoTemplate);
                //Add graphic to the map graphics layer.
                map.graphics.add(graphic);
            }

        });
0 Kudos
3 Replies
tonylife
New Contributor III
Any comment would be very much appreciated.

Thanks,
Tony
0 Kudos
derekswingley1
Frequent Contributor
That looks like it should work as long as your feature layer is a collection of polylines. Any chance you can post a more complete example to repro this?
0 Kudos
tonylife
New Contributor III
Thank you swingley for your reply! The feature layer was a collection of points. But I was using SimpleLineSymbol to identify it.

I changed to test another feature layer with ploygons. And tried to use SimpleFillSymbol. It does show the feature now.

However, it only works if the feature layer is showing. If I hide the feature layer, although the graphic get added to map with customized symbol and info template, whatever I do, the graphic wouldn't show up. Any ideas?

Thanks,
Tony
0 Kudos