<?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: Invoke sketch widget tool from button click? in ArcGIS JavaScript Maps SDK Questions</title>
    <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/invoke-sketch-widget-tool-from-button-click/m-p/1059481#M73186</link>
    <description>&lt;P&gt;Thanks for the hint Robert.&amp;nbsp; I've throw together some code, but I'm missing the drawing on the map part....&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;&amp;lt;html&amp;gt;
  &amp;lt;head&amp;gt;
    &amp;lt;meta charset="utf-8" /&amp;gt;
    &amp;lt;meta name="viewport"
      content="initial-scale=1,maximum-scale=1,user-scalable=no" /&amp;gt;
    &amp;lt;title&amp;gt;Sketch update validation | Sample | ArcGIS API for JavaScript 4.19&amp;lt;/title&amp;gt;

    &amp;lt;link rel="stylesheet" href="https://js.arcgis.com/4.19/esri/themes/light/main.css" /&amp;gt;
    &amp;lt;script src="https://js.arcgis.com/4.19/"&amp;gt;&amp;lt;/script&amp;gt;

    &amp;lt;style&amp;gt;
      html,
      body,
      #viewDiv {
        padding: 0;
        margin: 0;
        height: 100%;
        width: 100%;
      }

      #instructions {
        width: 225px;
        background: #fff;
        padding: 10px;
      }
      
      .esri-button {
        display: inline-block;
        width: 75px;
      }

      .relative {
        padding: 10px;
        position: relative;
        margin: 10px;
      }
    &amp;lt;/style&amp;gt;

    &amp;lt;script&amp;gt;
      require([
        "esri/widgets/Sketch/SketchViewModel",
        "esri/Graphic",
        "esri/Map",
        "esri/views/MapView",
        "esri/layers/GraphicsLayer",
        "esri/geometry/Polygon",
        "esri/widgets/Expand"
      ], function(
        SketchViewModel,
        Graphic,
        Map,
        MapView,
        GraphicsLayer,
        Polygon,
        Expand
      ) {
        let sketchViewModel,
          instructionsExpand;

        const graphicsLayer = new GraphicsLayer();

        const map = new Map({
          basemap: "streets",
          layers: [graphicsLayer]
        });

        const view = new MapView({
          container: "viewDiv",
          map: map,
          zoom: 6,
          center: [-82, 35]
        });

        setUpInstructions();

        view.when(function() {
           sketchViewModel = new SketchViewModel({
            view: view,
            layer: graphicsLayer,
            polygonSymbol: {
              type: "simple-fill",
              color: "rgba(255,0,0, 0.8)",
              style: "solid",
              outline: {
                color: "black",
                width: 1
              }
            }
          });

          sketchViewModel.on("create", function(evt) {
            graphicsLayer.add(evt.graphic);
          });
        });

        const drawBtn = document.getElementById("draw");
        drawBtn.addEventListener("click", function() {
          console.log("draw button");
          graphicsLayer.removeAll();
          sketchViewModel.create("polygon");
        });

        const resetBtn = document.getElementById("reset");
        resetBtn.addEventListener("click", function() {
          console.log("reset button");
          graphicsLayer.removeAll();
        });

        function setUpInstructions() {
          const sampleInstructions = document.getElementById("instructions");
          instructionsExpand = new Expand({
            expandIconClass: "esri-icon-question",
            expandTooltip: "How to use this sample",
            expanded: true,
            view: view,
            content: sampleInstructions
          });
          view.ui.add(instructionsExpand, "top-left");

          // hide the instructions expand widget when the view becomes focused
          view.watch("focused", function(newValue, oldValue, property, object) {
            if (newValue) {
              instructionsExpand.expanded = false;
            }
          });
        }
      });
    &amp;lt;/script&amp;gt;
  &amp;lt;/head&amp;gt;

  &amp;lt;body&amp;gt;
    &amp;lt;div id="viewDiv"&amp;gt;&amp;lt;/div&amp;gt;
    &amp;lt;div id="instructions" class="esri-widget"&amp;gt;
      &amp;lt;div class="relative"&amp;gt;
        &amp;lt;button class="esri-button" id="draw"&amp;gt;Draw&amp;lt;/button&amp;gt;
        &amp;lt;button class="esri-button" id="reset"&amp;gt;Reset&amp;lt;/button&amp;gt;
      &amp;lt;/div&amp;gt;
    &amp;lt;/div&amp;gt;
  &amp;lt;/body&amp;gt;
&amp;lt;/html&amp;gt;&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 19 May 2021 16:24:29 GMT</pubDate>
    <dc:creator>GWReid</dc:creator>
    <dc:date>2021-05-19T16:24:29Z</dc:date>
    <item>
      <title>Invoke sketch widget tool from button click?</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/invoke-sketch-widget-tool-from-button-click/m-p/1058950#M73155</link>
      <description>&lt;P&gt;I'd like to invoke a sketch widget tool from a button click as opposed to the widget itself.&amp;nbsp; Can this be done?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;const sketch = new Sketch({
        layer: graphicsLayer,
        view: view,
        creationMode: 'update',
        availableCreateTools: ['rectangle'],
        defaultUpdateOptions: {
            enableRotation: false,
            toggleToolOnClick: false
        },
        visibleElements: {
            selectionTools: {
              "lasso-selection": false,
              "rectangle-selection": false,
            },
            undoRedoMenu: false
        }
    });
    view.ui.add(sketch, "top-right");&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks.&lt;/P&gt;</description>
      <pubDate>Tue, 18 May 2021 14:26:22 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/invoke-sketch-widget-tool-from-button-click/m-p/1058950#M73155</guid>
      <dc:creator>GWReid</dc:creator>
      <dc:date>2021-05-18T14:26:22Z</dc:date>
    </item>
    <item>
      <title>Re: Invoke sketch widget tool from button click?</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/invoke-sketch-widget-tool-from-button-click/m-p/1058953#M73156</link>
      <description>&lt;P&gt;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/422784"&gt;@GWReid&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp; I do this using the SketchViewModel instead of the Sketch widget.&amp;nbsp;&lt;BR /&gt;&lt;A href="https://developers.arcgis.com/javascript/latest/api-reference/esri-widgets-Sketch-SketchViewModel.html" target="_blank"&gt;https://developers.arcgis.com/javascript/latest/api-reference/esri-widgets-Sketch-SketchViewModel.html&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 18 May 2021 14:29:44 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/invoke-sketch-widget-tool-from-button-click/m-p/1058953#M73156</guid>
      <dc:creator>RobertScheitlin__GISP</dc:creator>
      <dc:date>2021-05-18T14:29:44Z</dc:date>
    </item>
    <item>
      <title>Re: Invoke sketch widget tool from button click?</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/invoke-sketch-widget-tool-from-button-click/m-p/1059481#M73186</link>
      <description>&lt;P&gt;Thanks for the hint Robert.&amp;nbsp; I've throw together some code, but I'm missing the drawing on the map part....&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;&amp;lt;html&amp;gt;
  &amp;lt;head&amp;gt;
    &amp;lt;meta charset="utf-8" /&amp;gt;
    &amp;lt;meta name="viewport"
      content="initial-scale=1,maximum-scale=1,user-scalable=no" /&amp;gt;
    &amp;lt;title&amp;gt;Sketch update validation | Sample | ArcGIS API for JavaScript 4.19&amp;lt;/title&amp;gt;

    &amp;lt;link rel="stylesheet" href="https://js.arcgis.com/4.19/esri/themes/light/main.css" /&amp;gt;
    &amp;lt;script src="https://js.arcgis.com/4.19/"&amp;gt;&amp;lt;/script&amp;gt;

    &amp;lt;style&amp;gt;
      html,
      body,
      #viewDiv {
        padding: 0;
        margin: 0;
        height: 100%;
        width: 100%;
      }

      #instructions {
        width: 225px;
        background: #fff;
        padding: 10px;
      }
      
      .esri-button {
        display: inline-block;
        width: 75px;
      }

      .relative {
        padding: 10px;
        position: relative;
        margin: 10px;
      }
    &amp;lt;/style&amp;gt;

    &amp;lt;script&amp;gt;
      require([
        "esri/widgets/Sketch/SketchViewModel",
        "esri/Graphic",
        "esri/Map",
        "esri/views/MapView",
        "esri/layers/GraphicsLayer",
        "esri/geometry/Polygon",
        "esri/widgets/Expand"
      ], function(
        SketchViewModel,
        Graphic,
        Map,
        MapView,
        GraphicsLayer,
        Polygon,
        Expand
      ) {
        let sketchViewModel,
          instructionsExpand;

        const graphicsLayer = new GraphicsLayer();

        const map = new Map({
          basemap: "streets",
          layers: [graphicsLayer]
        });

        const view = new MapView({
          container: "viewDiv",
          map: map,
          zoom: 6,
          center: [-82, 35]
        });

        setUpInstructions();

        view.when(function() {
           sketchViewModel = new SketchViewModel({
            view: view,
            layer: graphicsLayer,
            polygonSymbol: {
              type: "simple-fill",
              color: "rgba(255,0,0, 0.8)",
              style: "solid",
              outline: {
                color: "black",
                width: 1
              }
            }
          });

          sketchViewModel.on("create", function(evt) {
            graphicsLayer.add(evt.graphic);
          });
        });

        const drawBtn = document.getElementById("draw");
        drawBtn.addEventListener("click", function() {
          console.log("draw button");
          graphicsLayer.removeAll();
          sketchViewModel.create("polygon");
        });

        const resetBtn = document.getElementById("reset");
        resetBtn.addEventListener("click", function() {
          console.log("reset button");
          graphicsLayer.removeAll();
        });

        function setUpInstructions() {
          const sampleInstructions = document.getElementById("instructions");
          instructionsExpand = new Expand({
            expandIconClass: "esri-icon-question",
            expandTooltip: "How to use this sample",
            expanded: true,
            view: view,
            content: sampleInstructions
          });
          view.ui.add(instructionsExpand, "top-left");

          // hide the instructions expand widget when the view becomes focused
          view.watch("focused", function(newValue, oldValue, property, object) {
            if (newValue) {
              instructionsExpand.expanded = false;
            }
          });
        }
      });
    &amp;lt;/script&amp;gt;
  &amp;lt;/head&amp;gt;

  &amp;lt;body&amp;gt;
    &amp;lt;div id="viewDiv"&amp;gt;&amp;lt;/div&amp;gt;
    &amp;lt;div id="instructions" class="esri-widget"&amp;gt;
      &amp;lt;div class="relative"&amp;gt;
        &amp;lt;button class="esri-button" id="draw"&amp;gt;Draw&amp;lt;/button&amp;gt;
        &amp;lt;button class="esri-button" id="reset"&amp;gt;Reset&amp;lt;/button&amp;gt;
      &amp;lt;/div&amp;gt;
    &amp;lt;/div&amp;gt;
  &amp;lt;/body&amp;gt;
&amp;lt;/html&amp;gt;&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 19 May 2021 16:24:29 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/invoke-sketch-widget-tool-from-button-click/m-p/1059481#M73186</guid>
      <dc:creator>GWReid</dc:creator>
      <dc:date>2021-05-19T16:24:29Z</dc:date>
    </item>
    <item>
      <title>Re: Invoke sketch widget tool from button click?</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/invoke-sketch-widget-tool-from-button-click/m-p/1059544#M73188</link>
      <description>&lt;P&gt;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/422784"&gt;@GWReid&lt;/a&gt;&amp;nbsp; The code you provided works fine. Once you click on the Draw button then you just click on the map to start drawing the polygon.&lt;/P&gt;</description>
      <pubDate>Wed, 19 May 2021 17:25:03 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/invoke-sketch-widget-tool-from-button-click/m-p/1059544#M73188</guid>
      <dc:creator>RobertScheitlin__GISP</dc:creator>
      <dc:date>2021-05-19T17:25:03Z</dc:date>
    </item>
    <item>
      <title>Re: Invoke sketch widget tool from button click?</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/invoke-sketch-widget-tool-from-button-click/m-p/1059850#M73203</link>
      <description>&lt;P&gt;Oops, I was thinking "rectangle", but had "polygon" in there.&amp;nbsp; Thanks Robert.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 20 May 2021 11:14:02 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/invoke-sketch-widget-tool-from-button-click/m-p/1059850#M73203</guid>
      <dc:creator>GWReid</dc:creator>
      <dc:date>2021-05-20T11:14:02Z</dc:date>
    </item>
  </channel>
</rss>

