Hi, I'm trying to find a way to detect the event of feature selection of a ArcGISMapServiceLayer loaded in a map. Or get the features selected by user using the Query or Attribute Table widgets.
I don't know how to get the FeatureLayer collection of the ArcGISMapServiceLayer instance to attach their 'selection-change'/'selection-clear' events. I see the 'layersInfo' member successfully but the method 'map.getLayer(id)' always return null to these sublayer collection.
Is it possible? How I do it?
Thanks in advance
Alvaro
Solved! Go to Solution.
Hi Robert, thanks for your review.
Finally I implemented the third option overriding the original methods where the widgets manage the query results. And It works fine!
My code for Query widget....
var widgetConfigs = null; if ((widgetConfigs = widget.appConfig.getConfigElementsByName("Query")) != null && widgetConfigs.length > 0) { var connectFunction = null; var queryWidget = widget.widgetManager.getWidgetById(widgetConfigs[0].id); // ... override methods. connectFunction = function (currentWidget) { var theWidget = currentWidget; var theOriginalResultItemsFunction = theWidget._addResultItems; var theOriginalClearResultPageFunction = theWidget._clearResultPage; if (!theOriginalResultItemsFunction || !theOriginalClearResultPageFunction) return; theWidget._addResultItems = function (features, resultLayer, relatedResults, relatedTableIds) { var self = this; theOriginalResultItemsFunction.call(self, features, resultLayer, relatedResults, relatedTableIds); ... my bla bla }; theWidget._clearResultPage = function () { var self = this; theOriginalClearResultPageFunction.call(self); ... my bla bla }; }; if (!queryWidget) { widget.widgetManager.loadWidget(widgetConfigs[0]).then(lang.hitch(widget, function (currentWidget) { connectFunction(currentWidget); })); } else { connectFunction(queryWidget); } }
🙂 Thanks Robert!
Alvaro
Alvaro,
A ArcGISMapServiceLayer is just an image from the server and does not have geometries returned to the map. The query widget and the AT widget are able to select features because they use a QueryTask on the map service or create a FeatureLayer fro the query results. The query widget adds the QueryTask results as a FeatureLayer using a FeatureCollection.
Hi Robert, sorry I wrote a wrong name class, I have a ArcGISDynamicMapServiceLayer instance. Its layerinfos member contains the layers I want attach, but I looked that AT and Query widgets create their own "private" FeatureLayer and QueryTask instances.
I see four options:
First and second options force to me to deploy new "rewrited" widgets, I don't like it 😞
Alvaro,
I have looked into this a few minutes and all I can say is you have your work cut out for you. Option 1 and 2 are definitely the easy route initially but like you said maintainability. Good luck on this venture.
Hi Robert, thanks for your review.
Finally I implemented the third option overriding the original methods where the widgets manage the query results. And It works fine!
My code for Query widget....
var widgetConfigs = null; if ((widgetConfigs = widget.appConfig.getConfigElementsByName("Query")) != null && widgetConfigs.length > 0) { var connectFunction = null; var queryWidget = widget.widgetManager.getWidgetById(widgetConfigs[0].id); // ... override methods. connectFunction = function (currentWidget) { var theWidget = currentWidget; var theOriginalResultItemsFunction = theWidget._addResultItems; var theOriginalClearResultPageFunction = theWidget._clearResultPage; if (!theOriginalResultItemsFunction || !theOriginalClearResultPageFunction) return; theWidget._addResultItems = function (features, resultLayer, relatedResults, relatedTableIds) { var self = this; theOriginalResultItemsFunction.call(self, features, resultLayer, relatedResults, relatedTableIds); ... my bla bla }; theWidget._clearResultPage = function () { var self = this; theOriginalClearResultPageFunction.call(self); ... my bla bla }; }; if (!queryWidget) { widget.widgetManager.loadWidget(widgetConfigs[0]).then(lang.hitch(widget, function (currentWidget) { connectFunction(currentWidget); })); } else { connectFunction(queryWidget); } }
🙂 Thanks Robert!
Alvaro