<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: operationalLayers: selecting features with drawtool in Web AppBuilder Custom Widgets Questions</title>
    <link>https://community.esri.com/t5/web-appbuilder-custom-widgets-questions/operationallayers-selecting-features-with-drawtool/m-p/1016472#M14352</link>
    <description>&lt;P&gt;I think I got it.&amp;nbsp; Instead of adding a New FeatureLayer, I simply needed to get a reference to the desired operationalLayer.&amp;nbsp; But one missing thing was to make sure the reference on the opLayer object's "layerObject" and not just the layer itself.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;From this function the selection is performed using the geometry of the extent drawn.&amp;nbsp; However, I am setting the reference to this.selectionLayer in another function that controls layer visibility by the user.&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;selectParcelsFromExtent: function (drawResults) {
            var extent = drawResults.geometry;
            var query = new Query();
            query.geometry = extent;
            
            this.selectionLayer.selectFeatures(query, FeatureLayer.SELECTION_NEW);
            var selectedFeatures = this.selectionLayer.getSelectedFeatures();

            for (var i in selectedFeatures) {
                console.log("Asset Name: " + selectedFeatures[i].attributes.NAME)
            }


        },&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;A different function provides user interaction with the various operationalLayers from the webmap source (don't ask, there's a ton of layers and this just allows for easy display that makes sense).&amp;nbsp; In any event, I am setting that this.selectedFeatures reference at this level which makes a lot of sense for UI flow:&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;_operLayers = this.map.itemInfo.itemData.operationalLayers;
            array.map(_operLayers, lang.hitch(this, function (lyr) {
                if (lyr.layerObject) {
                    if (lyr.title === "Alert 24hr - Hydraulic Element Set (Active)") {
                        if (chkHES == true &amp;amp;&amp;amp; selectedAlertValue === "Active24") {
                            lyr.layerObject.setVisibility(true);
                            lyr.visibility = true;
                            this.selectionLayer = lyr.layerObject;
                        }
                        else if (chkHES == true &amp;amp;&amp;amp; selectedAlertValue === "All24") {
                            lyr.layerObject.setVisibility(true);
                            lyr.visibility = true;
                        }
                        else {
                            lyr.layerObject.setVisibility(false);
                            lyr.visibility = false;
                        }
                    }&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 13 Jan 2021 18:09:26 GMT</pubDate>
    <dc:creator>JamesCrandall</dc:creator>
    <dc:date>2021-01-13T18:09:26Z</dc:date>
    <item>
      <title>operationalLayers: selecting features with drawtool</title>
      <link>https://community.esri.com/t5/web-appbuilder-custom-widgets-questions/operationallayers-selecting-features-with-drawtool/m-p/1016396#M14351</link>
      <description>&lt;P&gt;I'm looking for simple example to select features of an operationalLayer by dragging an extent box.&amp;nbsp; I'm attempting to build a new widget with a button that will activate the drawtool and allow the user to drag a box to select features and deactivate when completed.&lt;/P&gt;&lt;P&gt;Javascript API 3x&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Edit to add current code.&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;div on the widget's html:&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;&amp;lt;div class="jimu-btn finish-select" data-dojo-attach-event="click:activateAcknowledgeTool" id="btnActivateSelection"&amp;gt;Activate&amp;lt;/div&amp;gt;&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;        activateAcknowledgeTool: function () {

            if (!this.drawToolbar) {
                this.setupDrawToolbar();
            }
            this.enableDrawToolbar();
        },
        setupDrawToolbar: function () {
            this.createDrawToolbar();
            this.setupDrawToolbarListener();

        },
        createDrawToolbar: function () {            
            this.drawToolbar = new Draw(this.map, { showTooltips: false });
        },
        setupDrawToolbarListener: function () {
            on(this.drawToolbar, "draw-complete", lang.hitch(this, this.selectParcelsFromExtent));

        },
        selectParcelsFromExtent: function (drawResults) {
            var extent = drawResults.geometry;
            var query = new Query();
            query.geometry = extent;
            parcelLayer = new FeatureLayer("https://somedomain.com/someagssite/rest/services/somemapservice/MapServer/0", {
                outFields: ["*"],
                mode: FeatureLayer.MODE_SELECTION
            });
            this.map.addLayer(parcelLayer);
            parcelLayer.selectFeatures(query, FeatureLayer.SELECTION_ADD);
            var selectedFeatures = parcelLayer.getSelectedFeatures();

            for (var i in selectedFeatures) {
                console.log(selectedFeatures[i].attributes.OBJECTID)                
            }
        },
        enableDrawToolbar: function () {
            this.drawToolbar.activate(Draw.EXTENT);
            
        }&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;it doesn't appear to select anything within the extent box drawn, the selectedFeatures array is empty.&lt;/P&gt;</description>
      <pubDate>Wed, 13 Jan 2021 17:38:30 GMT</pubDate>
      <guid>https://community.esri.com/t5/web-appbuilder-custom-widgets-questions/operationallayers-selecting-features-with-drawtool/m-p/1016396#M14351</guid>
      <dc:creator>JamesCrandall</dc:creator>
      <dc:date>2021-01-13T17:38:30Z</dc:date>
    </item>
    <item>
      <title>Re: operationalLayers: selecting features with drawtool</title>
      <link>https://community.esri.com/t5/web-appbuilder-custom-widgets-questions/operationallayers-selecting-features-with-drawtool/m-p/1016472#M14352</link>
      <description>&lt;P&gt;I think I got it.&amp;nbsp; Instead of adding a New FeatureLayer, I simply needed to get a reference to the desired operationalLayer.&amp;nbsp; But one missing thing was to make sure the reference on the opLayer object's "layerObject" and not just the layer itself.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;From this function the selection is performed using the geometry of the extent drawn.&amp;nbsp; However, I am setting the reference to this.selectionLayer in another function that controls layer visibility by the user.&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;selectParcelsFromExtent: function (drawResults) {
            var extent = drawResults.geometry;
            var query = new Query();
            query.geometry = extent;
            
            this.selectionLayer.selectFeatures(query, FeatureLayer.SELECTION_NEW);
            var selectedFeatures = this.selectionLayer.getSelectedFeatures();

            for (var i in selectedFeatures) {
                console.log("Asset Name: " + selectedFeatures[i].attributes.NAME)
            }


        },&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;A different function provides user interaction with the various operationalLayers from the webmap source (don't ask, there's a ton of layers and this just allows for easy display that makes sense).&amp;nbsp; In any event, I am setting that this.selectedFeatures reference at this level which makes a lot of sense for UI flow:&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;_operLayers = this.map.itemInfo.itemData.operationalLayers;
            array.map(_operLayers, lang.hitch(this, function (lyr) {
                if (lyr.layerObject) {
                    if (lyr.title === "Alert 24hr - Hydraulic Element Set (Active)") {
                        if (chkHES == true &amp;amp;&amp;amp; selectedAlertValue === "Active24") {
                            lyr.layerObject.setVisibility(true);
                            lyr.visibility = true;
                            this.selectionLayer = lyr.layerObject;
                        }
                        else if (chkHES == true &amp;amp;&amp;amp; selectedAlertValue === "All24") {
                            lyr.layerObject.setVisibility(true);
                            lyr.visibility = true;
                        }
                        else {
                            lyr.layerObject.setVisibility(false);
                            lyr.visibility = false;
                        }
                    }&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 13 Jan 2021 18:09:26 GMT</pubDate>
      <guid>https://community.esri.com/t5/web-appbuilder-custom-widgets-questions/operationallayers-selecting-features-with-drawtool/m-p/1016472#M14352</guid>
      <dc:creator>JamesCrandall</dc:creator>
      <dc:date>2021-01-13T18:09:26Z</dc:date>
    </item>
  </channel>
</rss>

