<?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: Draw Point Line Poly and get its geometry in ArcGIS JavaScript Maps SDK Questions</title>
    <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/draw-point-line-poly-and-get-its-geometry/m-p/1210895#M78648</link>
    <description>&lt;P&gt;Got it... Sorry to waste your time... If anyone can benefit then great..&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&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;Draw polyline | Sample | ArcGIS API for JavaScript 4.24&amp;lt;/title&amp;gt;

    &amp;lt;link rel="stylesheet" href="https://js.arcgis.com/4.24/esri/themes/light/main.css" /&amp;gt;
    &amp;lt;script src="https://js.arcgis.com/4.24/"&amp;gt;&amp;lt;/script&amp;gt;

    &amp;lt;style&amp;gt;
      html,
      body,
      #viewDiv {
        height: 100%;
        width: 100%;
        margin: 0;
        padding: 0;
      }
    &amp;lt;/style&amp;gt;
    &amp;lt;script&amp;gt;
  require([
    "esri/Map",
    "esri/views/MapView",
    "esri/views/draw/Draw",
    "esri/Graphic",
    "esri/geometry/geometryEngine"
  ], (Map, MapView, Draw, Graphic, geometryEngine) =&amp;gt; {
    const map = new Map({
      basemap: "gray-vector"
    });

    const view = new MapView({
      container: "viewDiv",
      map: map,
      zoom: 15,
      center: [18.06, 59.34]
    });

    // add the button for the draw tool
    view.ui.add("line-button", "top-left");
    view.ui.add("point-button", "top-left");
    view.ui.add("polygon-button", "top-left");
    
    const draw = new Draw({
      view: view
    });

   document.getElementById("point-button").onclick = () =&amp;gt; {
      view.graphics.removeAll();

      // creates and returns an instance of PolyLineDrawAction
      const action = draw.create("point");

      // focus the view to activate keyboard shortcuts for sketching
      view.focus();

     // PointDrawAction.cursor-update
      // Give a visual feedback to users as they move the pointer over the view
      action.on("cursor-update", function (evt) {
        updateVerticesPoint(evt.coordinates);
      });

      // PointDrawAction.draw-complete
      // Create a point when user clicks on the view or presses "C" key.
      action.on("draw-complete", function (evt) {
        updateVerticesPoint(evt.coordinates);
      });
     
    };
    
    document.getElementById("polygon-button").onclick = () =&amp;gt; {
      view.graphics.removeAll();

      // creates and returns an instance of PolyLineDrawAction
      const action = draw.create("polygon");

      // focus the view to activate keyboard shortcuts for sketching
      view.focus();

      // listen polylineDrawAction events to give immediate visual feedback
      // to users as the line is being drawn on the view.
      action.on(
        [
          "vertex-add",
          "vertex-remove",
          "cursor-update",
          "redo",
          "undo",
          "draw-complete"
        ],
        updateVerticesPolygon
      );
    };
    
    // draw polyline button
    document.getElementById("line-button").onclick = () =&amp;gt; {
      view.graphics.removeAll();

      // creates and returns an instance of PolyLineDrawAction
      const action = draw.create("polyline");

      // focus the view to activate keyboard shortcuts for sketching
      view.focus();

      // listen polylineDrawAction events to give immediate visual feedback
      // to users as the line is being drawn on the view.
      action.on(
        [
          "vertex-add",
          "vertex-remove",
          "cursor-update",
          "redo",
          "undo",
          "draw-complete"
        ],
        updateVerticesLine
      );
    };

    
    function updateVerticesPoint(coordinates) {
      //// create a polyline from returned vertices
      //if (event.vertices.length &amp;gt; 0) {
      //  const result = createGraphicPoint(event);
      //}
   view.graphics.removeAll();
  let point = {
    type: "point", // autocasts as /Point
    x: coordinates[0],
    y: coordinates[1],
    spatialReference: view.spatialReference
  };

      let graphic = new Graphic({
        geometry: point,
        symbol: {
          type: "simple-marker", // autocasts as SimpleMarkerSymbol
      style: "square",
      color: "red",
      size: "16px",
      outline: { // autocasts as SimpleLineSymbol
        color: [255, 255, 0],
        width: 3
      }
    }
  });
  view.graphics.add(graphic);     

    }
    // Checks if the last vertex is making the line intersect itself.
    function updateVerticesPolygon(event) {
      // create a polyline from returned vertices
      if (event.vertices.length &amp;gt; 1) {
        const result = createGraphicPolygon(event);
      }
    }
    function updateVerticesLine(event) {
      // create a polyline from returned vertices
      if (event.vertices.length &amp;gt; 1) {
        const result = createGraphicLine(event);

        // if the last vertex is making the line intersects itself,
        // prevent the events from firing
        if (result.selfIntersects) {
          event.preventDefault();
        }
      }
    }

    
    function createGraphicPoint(event) {
      const vertices = event.vertices;
      view.graphics.removeAll();

      // a graphic representing the polyline that is being drawn
      const graphicPoly = new Graphic({
        geometry: {
          type: "point",
          spatialReference: view.spatialReference
        },
        symbol: {
          type: "simple-marker", // autocasts as new SimpleFillSymbol
          color: [227, 139, 79, 0.8],
          outline: {
             color: [255, 255, 255],
             width: 1
          }
        }

      });
     
      view.graphics.add(graphicPoly);
    }
    
    
    // create a new graphic presenting the polyline that is being drawn on the view
    function createGraphicPolygon(event) {
      const vertices = event.vertices;
      view.graphics.removeAll();

      // a graphic representing the polyline that is being drawn
      const graphicPoly = new Graphic({
        geometry: {
          type: "polygon",
          rings: vertices,
          spatialReference: view.spatialReference
        },
        symbol: {
          type: "simple-fill", // autocasts as new SimpleFillSymbol
          color: [227, 139, 79, 0.8],
          outline: {
             color: [255, 255, 255],
             width: 1
          }
        }

      });
     
      view.graphics.add(graphicPoly);
    }
    
    function createGraphicLine(event) {
      const vertices = event.vertices;
      view.graphics.removeAll();

      // a graphic representing the polyline that is being drawn
      const graphicLine = new Graphic({
        geometry: {
          type: "polyline",
          paths: vertices,
          spatialReference: view.spatialReference
        },
        symbol: {
          type: "simple-line", // autocasts as new SimpleFillSymbol
          color: [4, 90, 141],
          width: 4,
          cap: "round",
          join: "round"
        }
      });

      // check if the polyline intersects itself.
      const intersectingSegment = getIntersectingSegment(graphicLine.geometry);

      // Add a new graphic for the intersecting segment.
      if (intersectingSegment) {
        view.graphics.addMany([graphicLine, intersectingSegment]);
      }
      // Just add the graphic representing the polyline if no intersection
      else {
        view.graphics.add(graphicLine);
      }

      // return intersectingSegment
      return {
        selfIntersects: intersectingSegment
      };
    }

    // function that checks if the line intersects itself
    function isSelfIntersecting(polyline) {
      if (polyline.paths[0].length &amp;lt; 3) {
        return false;
      }
      const line = polyline.clone();

      //get the last segment from the polyline that is being drawn
      const lastSegment = getLastSegment(polyline);
      line.removePoint(0, line.paths[0].length - 1);

      // returns true if the line intersects itself, false otherwise
      return geometryEngine.crosses(lastSegment, line);
    }

    // Checks if the line intersects itself. If yes, change the last
    // segment's symbol giving a visual feedback to the user.
    function getIntersectingSegment(polyline) {
      if (isSelfIntersecting(polyline)) {
        return new Graphic({
          geometry: getLastSegment(polyline),
          symbol: {
            type: "simple-line", // autocasts as new SimpleLineSymbol
            style: "short-dot",
            width: 3.5,
            color: "yellow"
          }
        });
      }
      return null;
    }

    // Get the last segment of the polyline that is being drawn
    function getLastSegment(polyline) {
      const line = polyline.clone();
      const lastXYPoint = line.removePoint(0, line.paths[0].length - 1);
      const existingLineFinalPoint = line.getPoint(
        0,
        line.paths[0].length - 1
      );

      return {
        type: "polyline",
        spatialReference: view.spatialReference,
        hasZ: false,
        paths: [
          [
            [existingLineFinalPoint.x, existingLineFinalPoint.y],
            [lastXYPoint.x, lastXYPoint.y]
          ]
        ]
      };
    }
  });
&amp;lt;/script&amp;gt;
  &amp;lt;/head&amp;gt;

  &amp;lt;body&amp;gt;
    &amp;lt;!-- https://developers.arcgis.com/javascript/latest/esri-icon-font/ --&amp;gt;
    &amp;lt;div id="viewDiv"&amp;gt;
      &amp;lt;div id="point-button" class="esri-widget esri-widget--button esri-interactive" title="Draw point"&amp;gt;
        &amp;lt;span class="esri-icon-map-pin"&amp;gt;&amp;lt;/span&amp;gt;           
      &amp;lt;/div&amp;gt; 
      &amp;lt;div id="line-button" class="esri-widget esri-widget--button esri-interactive" title="Draw polyline"&amp;gt;
        &amp;lt;span class="esri-icon-polyline"&amp;gt;&amp;lt;/span&amp;gt;           
      &amp;lt;/div&amp;gt;
      &amp;lt;div id="polygon-button" class="esri-widget esri-widget--button esri-interactive" title="Draw polygon"&amp;gt;
        &amp;lt;span class="esri-icon-polygon"&amp;gt;&amp;lt;/span&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;</description>
    <pubDate>Thu, 08 Sep 2022 18:00:37 GMT</pubDate>
    <dc:creator>jaykapalczynski</dc:creator>
    <dc:date>2022-09-08T18:00:37Z</dc:date>
    <item>
      <title>Draw Point Line Poly and get its geometry</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/draw-point-line-poly-and-get-its-geometry/m-p/1210865#M78644</link>
      <description>&lt;P&gt;I am trying to have a simple map and:&lt;/P&gt;&lt;OL&gt;&lt;LI&gt;Allow the user to draw a point, line, or polygon.&amp;nbsp; Although just 1.&lt;/LI&gt;&lt;LI&gt;I then need to buffer this feature&lt;/LI&gt;&lt;LI&gt;I then need to capture its geometry so I can send that as a parameter to a GP Tool&lt;/LI&gt;&lt;/OL&gt;&lt;P&gt;I looked at this widget &lt;A href="https://developers.arcgis.com/javascript/latest/sample-code/sketch-geometries/" target="_blank"&gt;https://developers.arcgis.com/javascript/latest/sample-code/sketch-geometries/&lt;/A&gt;&amp;nbsp; but could not figure out how to limit it to one geometry in the graphics layer.&amp;nbsp; I assume that I could just remove all features every time the user clicks the map.&amp;nbsp; Or someway to disable the widget after each feature creation in the map (Then deleting all features next time the widget is used?)&lt;/P&gt;&lt;P&gt;I am not sure the widget is the way to go and looking for some thoughts or examples for this.&lt;/P&gt;&lt;P&gt;The widget stores geometry in the graphics layer so If I could control the layer to only have 1 feature at a time I could query the graphics layer for its geometry....&lt;/P&gt;&lt;P&gt;Thoughts?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 08 Sep 2022 17:01:42 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/draw-point-line-poly-and-get-its-geometry/m-p/1210865#M78644</guid>
      <dc:creator>jaykapalczynski</dc:creator>
      <dc:date>2022-09-08T17:01:42Z</dc:date>
    </item>
    <item>
      <title>Re: Draw Point Line Poly and get its geometry</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/draw-point-line-poly-and-get-its-geometry/m-p/1210883#M78646</link>
      <description>&lt;P&gt;OK I am trying this solution... It has the Line working I am now trying to incorporate the Polygon add...&lt;/P&gt;&lt;P&gt;Not sure where I am failing&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&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;Draw polyline | Sample | ArcGIS API for JavaScript 4.24&amp;lt;/title&amp;gt;

    &amp;lt;link rel="stylesheet" href="https://js.arcgis.com/4.24/esri/themes/light/main.css" /&amp;gt;
    &amp;lt;script src="https://js.arcgis.com/4.24/"&amp;gt;&amp;lt;/script&amp;gt;

    &amp;lt;style&amp;gt;
      html,
      body,
      #viewDiv {
        height: 100%;
        width: 100%;
        margin: 0;
        padding: 0;
      }
    &amp;lt;/style&amp;gt;
    &amp;lt;script&amp;gt;
  require([
    "esri/Map",
    "esri/views/MapView",
    "esri/views/draw/Draw",
    "esri/Graphic",
    "esri/geometry/geometryEngine"
  ], (Map, MapView, Draw, Graphic, geometryEngine) =&amp;gt; {
    const map = new Map({
      basemap: "gray-vector"
    });

    const view = new MapView({
      container: "viewDiv",
      map: map,
      zoom: 15,
      center: [18.06, 59.34]
    });

    // add the button for the draw tool
    view.ui.add("line-button", "top-left");
    view.ui.add("point-button", "top-left");
    view.ui.add("polygon-button", "top-left");
    
    const draw = new Draw({
      view: view
    });
    
    document.getElementById("polygon-button").onclick = () =&amp;gt; {
      view.graphics.removeAll();

      // creates and returns an instance of PolyLineDrawAction
      const action = draw.create("polygon");

      // focus the view to activate keyboard shortcuts for sketching
      view.focus();

      // listen polylineDrawAction events to give immediate visual feedback
      // to users as the line is being drawn on the view.
      action.on(
        [
          "vertex-add",
          "vertex-remove",
          "cursor-update",
          "redo",
          "undo",
          "draw-complete"
        ],
        updateVerticesPolygon
      );
    };
    
    // draw polyline button
    document.getElementById("line-button").onclick = () =&amp;gt; {
      view.graphics.removeAll();

      // creates and returns an instance of PolyLineDrawAction
      const action = draw.create("polyline");

      // focus the view to activate keyboard shortcuts for sketching
      view.focus();

      // listen polylineDrawAction events to give immediate visual feedback
      // to users as the line is being drawn on the view.
      action.on(
        [
          "vertex-add",
          "vertex-remove",
          "cursor-update",
          "redo",
          "undo",
          "draw-complete"
        ],
        updateVerticesLine
      );
    };

    // Checks if the last vertex is making the line intersect itself.
    function updateVerticesPolygon(event) {
      // create a polyline from returned vertices
      if (event.vertices.length &amp;gt; 1) {
        const result = createGraphicPolygon(event);
      }
    }
    function updateVerticesLine(event) {
      // create a polyline from returned vertices
      if (event.vertices.length &amp;gt; 1) {
        const result = createGraphicLine(event);

        // if the last vertex is making the line intersects itself,
        // prevent the events from firing
        if (result.selfIntersects) {
          event.preventDefault();
        }
      }
    }

    // create a new graphic presenting the polyline that is being drawn on the view
    function createGraphicPolygon(event) {
      const vertices = event.vertices;
      view.graphics.removeAll();

      // a graphic representing the polyline that is being drawn
      const graphicPoly = new Graphic({
        geometry: {
          type: "polygon",
          paths: vertices,
          spatialReference: view.spatialReference
        },
        symbol: {
          type: "simple-fill", // autocasts as new SimpleFillSymbol
          color: [227, 139, 79, 0.8],
          outline: {
             color: [255, 255, 255],
             width: 1
          }
        }

      });
     
      view.graphics.add(graphicPoly);
    }
    
    function createGraphicLine(event) {
      const vertices = event.vertices;
      view.graphics.removeAll();

      // a graphic representing the polyline that is being drawn
      const graphicLine = new Graphic({
        geometry: {
          type: "polyline",
          paths: vertices,
          spatialReference: view.spatialReference
        },
        symbol: {
          type: "simple-line", // autocasts as new SimpleFillSymbol
          color: [4, 90, 141],
          width: 4,
          cap: "round",
          join: "round"
        }
      });

      // check if the polyline intersects itself.
      const intersectingSegment = getIntersectingSegment(graphicLine.geometry);

      // Add a new graphic for the intersecting segment.
      if (intersectingSegment) {
        view.graphics.addMany([graphicLine, intersectingSegment]);
      }
      // Just add the graphic representing the polyline if no intersection
      else {
        view.graphics.add(graphicLine);
      }

      // return intersectingSegment
      return {
        selfIntersects: intersectingSegment
      };
    }

    // function that checks if the line intersects itself
    function isSelfIntersecting(polyline) {
      if (polyline.paths[0].length &amp;lt; 3) {
        return false;
      }
      const line = polyline.clone();

      //get the last segment from the polyline that is being drawn
      const lastSegment = getLastSegment(polyline);
      line.removePoint(0, line.paths[0].length - 1);

      // returns true if the line intersects itself, false otherwise
      return geometryEngine.crosses(lastSegment, line);
    }

    // Checks if the line intersects itself. If yes, change the last
    // segment's symbol giving a visual feedback to the user.
    function getIntersectingSegment(polyline) {
      if (isSelfIntersecting(polyline)) {
        return new Graphic({
          geometry: getLastSegment(polyline),
          symbol: {
            type: "simple-line", // autocasts as new SimpleLineSymbol
            style: "short-dot",
            width: 3.5,
            color: "yellow"
          }
        });
      }
      return null;
    }

    // Get the last segment of the polyline that is being drawn
    function getLastSegment(polyline) {
      const line = polyline.clone();
      const lastXYPoint = line.removePoint(0, line.paths[0].length - 1);
      const existingLineFinalPoint = line.getPoint(
        0,
        line.paths[0].length - 1
      );

      return {
        type: "polyline",
        spatialReference: view.spatialReference,
        hasZ: false,
        paths: [
          [
            [existingLineFinalPoint.x, existingLineFinalPoint.y],
            [lastXYPoint.x, lastXYPoint.y]
          ]
        ]
      };
    }
  });
&amp;lt;/script&amp;gt;
  &amp;lt;/head&amp;gt;

  &amp;lt;body&amp;gt;
    &amp;lt;!-- https://developers.arcgis.com/javascript/latest/esri-icon-font/ --&amp;gt;
    &amp;lt;div id="viewDiv"&amp;gt;
      &amp;lt;div id="point-button" class="esri-widget esri-widget--button esri-interactive" title="Draw point"&amp;gt;
        &amp;lt;span class="esri-icon-map-pin"&amp;gt;&amp;lt;/span&amp;gt;           
      &amp;lt;/div&amp;gt; 
      &amp;lt;div id="line-button" class="esri-widget esri-widget--button esri-interactive" title="Draw polyline"&amp;gt;
        &amp;lt;span class="esri-icon-polyline"&amp;gt;&amp;lt;/span&amp;gt;           
      &amp;lt;/div&amp;gt;
      &amp;lt;div id="polygon-button" class="esri-widget esri-widget--button esri-interactive" title="Draw polygon"&amp;gt;
        &amp;lt;span class="esri-icon-polygon"&amp;gt;&amp;lt;/span&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;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 08 Sep 2022 17:44:24 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/draw-point-line-poly-and-get-its-geometry/m-p/1210883#M78646</guid>
      <dc:creator>jaykapalczynski</dc:creator>
      <dc:date>2022-09-08T17:44:24Z</dc:date>
    </item>
    <item>
      <title>Re: Draw Point Line Poly and get its geometry</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/draw-point-line-poly-and-get-its-geometry/m-p/1210888#M78647</link>
      <description>&lt;P&gt;OK I got the polygon to draw...&amp;nbsp; Needed&amp;nbsp; &amp;nbsp;&lt;FONT color="#FF0000"&gt;&lt;STRONG&gt; RINGS: vertices,&amp;nbsp;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;Just need to figure out the point&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;geometry: {
type: "polygon",
rings: vertices,
spatialReference: view.spatialReference
},&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 08 Sep 2022 17:48:51 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/draw-point-line-poly-and-get-its-geometry/m-p/1210888#M78647</guid>
      <dc:creator>jaykapalczynski</dc:creator>
      <dc:date>2022-09-08T17:48:51Z</dc:date>
    </item>
    <item>
      <title>Re: Draw Point Line Poly and get its geometry</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/draw-point-line-poly-and-get-its-geometry/m-p/1210895#M78648</link>
      <description>&lt;P&gt;Got it... Sorry to waste your time... If anyone can benefit then great..&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&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;Draw polyline | Sample | ArcGIS API for JavaScript 4.24&amp;lt;/title&amp;gt;

    &amp;lt;link rel="stylesheet" href="https://js.arcgis.com/4.24/esri/themes/light/main.css" /&amp;gt;
    &amp;lt;script src="https://js.arcgis.com/4.24/"&amp;gt;&amp;lt;/script&amp;gt;

    &amp;lt;style&amp;gt;
      html,
      body,
      #viewDiv {
        height: 100%;
        width: 100%;
        margin: 0;
        padding: 0;
      }
    &amp;lt;/style&amp;gt;
    &amp;lt;script&amp;gt;
  require([
    "esri/Map",
    "esri/views/MapView",
    "esri/views/draw/Draw",
    "esri/Graphic",
    "esri/geometry/geometryEngine"
  ], (Map, MapView, Draw, Graphic, geometryEngine) =&amp;gt; {
    const map = new Map({
      basemap: "gray-vector"
    });

    const view = new MapView({
      container: "viewDiv",
      map: map,
      zoom: 15,
      center: [18.06, 59.34]
    });

    // add the button for the draw tool
    view.ui.add("line-button", "top-left");
    view.ui.add("point-button", "top-left");
    view.ui.add("polygon-button", "top-left");
    
    const draw = new Draw({
      view: view
    });

   document.getElementById("point-button").onclick = () =&amp;gt; {
      view.graphics.removeAll();

      // creates and returns an instance of PolyLineDrawAction
      const action = draw.create("point");

      // focus the view to activate keyboard shortcuts for sketching
      view.focus();

     // PointDrawAction.cursor-update
      // Give a visual feedback to users as they move the pointer over the view
      action.on("cursor-update", function (evt) {
        updateVerticesPoint(evt.coordinates);
      });

      // PointDrawAction.draw-complete
      // Create a point when user clicks on the view or presses "C" key.
      action.on("draw-complete", function (evt) {
        updateVerticesPoint(evt.coordinates);
      });
     
    };
    
    document.getElementById("polygon-button").onclick = () =&amp;gt; {
      view.graphics.removeAll();

      // creates and returns an instance of PolyLineDrawAction
      const action = draw.create("polygon");

      // focus the view to activate keyboard shortcuts for sketching
      view.focus();

      // listen polylineDrawAction events to give immediate visual feedback
      // to users as the line is being drawn on the view.
      action.on(
        [
          "vertex-add",
          "vertex-remove",
          "cursor-update",
          "redo",
          "undo",
          "draw-complete"
        ],
        updateVerticesPolygon
      );
    };
    
    // draw polyline button
    document.getElementById("line-button").onclick = () =&amp;gt; {
      view.graphics.removeAll();

      // creates and returns an instance of PolyLineDrawAction
      const action = draw.create("polyline");

      // focus the view to activate keyboard shortcuts for sketching
      view.focus();

      // listen polylineDrawAction events to give immediate visual feedback
      // to users as the line is being drawn on the view.
      action.on(
        [
          "vertex-add",
          "vertex-remove",
          "cursor-update",
          "redo",
          "undo",
          "draw-complete"
        ],
        updateVerticesLine
      );
    };

    
    function updateVerticesPoint(coordinates) {
      //// create a polyline from returned vertices
      //if (event.vertices.length &amp;gt; 0) {
      //  const result = createGraphicPoint(event);
      //}
   view.graphics.removeAll();
  let point = {
    type: "point", // autocasts as /Point
    x: coordinates[0],
    y: coordinates[1],
    spatialReference: view.spatialReference
  };

      let graphic = new Graphic({
        geometry: point,
        symbol: {
          type: "simple-marker", // autocasts as SimpleMarkerSymbol
      style: "square",
      color: "red",
      size: "16px",
      outline: { // autocasts as SimpleLineSymbol
        color: [255, 255, 0],
        width: 3
      }
    }
  });
  view.graphics.add(graphic);     

    }
    // Checks if the last vertex is making the line intersect itself.
    function updateVerticesPolygon(event) {
      // create a polyline from returned vertices
      if (event.vertices.length &amp;gt; 1) {
        const result = createGraphicPolygon(event);
      }
    }
    function updateVerticesLine(event) {
      // create a polyline from returned vertices
      if (event.vertices.length &amp;gt; 1) {
        const result = createGraphicLine(event);

        // if the last vertex is making the line intersects itself,
        // prevent the events from firing
        if (result.selfIntersects) {
          event.preventDefault();
        }
      }
    }

    
    function createGraphicPoint(event) {
      const vertices = event.vertices;
      view.graphics.removeAll();

      // a graphic representing the polyline that is being drawn
      const graphicPoly = new Graphic({
        geometry: {
          type: "point",
          spatialReference: view.spatialReference
        },
        symbol: {
          type: "simple-marker", // autocasts as new SimpleFillSymbol
          color: [227, 139, 79, 0.8],
          outline: {
             color: [255, 255, 255],
             width: 1
          }
        }

      });
     
      view.graphics.add(graphicPoly);
    }
    
    
    // create a new graphic presenting the polyline that is being drawn on the view
    function createGraphicPolygon(event) {
      const vertices = event.vertices;
      view.graphics.removeAll();

      // a graphic representing the polyline that is being drawn
      const graphicPoly = new Graphic({
        geometry: {
          type: "polygon",
          rings: vertices,
          spatialReference: view.spatialReference
        },
        symbol: {
          type: "simple-fill", // autocasts as new SimpleFillSymbol
          color: [227, 139, 79, 0.8],
          outline: {
             color: [255, 255, 255],
             width: 1
          }
        }

      });
     
      view.graphics.add(graphicPoly);
    }
    
    function createGraphicLine(event) {
      const vertices = event.vertices;
      view.graphics.removeAll();

      // a graphic representing the polyline that is being drawn
      const graphicLine = new Graphic({
        geometry: {
          type: "polyline",
          paths: vertices,
          spatialReference: view.spatialReference
        },
        symbol: {
          type: "simple-line", // autocasts as new SimpleFillSymbol
          color: [4, 90, 141],
          width: 4,
          cap: "round",
          join: "round"
        }
      });

      // check if the polyline intersects itself.
      const intersectingSegment = getIntersectingSegment(graphicLine.geometry);

      // Add a new graphic for the intersecting segment.
      if (intersectingSegment) {
        view.graphics.addMany([graphicLine, intersectingSegment]);
      }
      // Just add the graphic representing the polyline if no intersection
      else {
        view.graphics.add(graphicLine);
      }

      // return intersectingSegment
      return {
        selfIntersects: intersectingSegment
      };
    }

    // function that checks if the line intersects itself
    function isSelfIntersecting(polyline) {
      if (polyline.paths[0].length &amp;lt; 3) {
        return false;
      }
      const line = polyline.clone();

      //get the last segment from the polyline that is being drawn
      const lastSegment = getLastSegment(polyline);
      line.removePoint(0, line.paths[0].length - 1);

      // returns true if the line intersects itself, false otherwise
      return geometryEngine.crosses(lastSegment, line);
    }

    // Checks if the line intersects itself. If yes, change the last
    // segment's symbol giving a visual feedback to the user.
    function getIntersectingSegment(polyline) {
      if (isSelfIntersecting(polyline)) {
        return new Graphic({
          geometry: getLastSegment(polyline),
          symbol: {
            type: "simple-line", // autocasts as new SimpleLineSymbol
            style: "short-dot",
            width: 3.5,
            color: "yellow"
          }
        });
      }
      return null;
    }

    // Get the last segment of the polyline that is being drawn
    function getLastSegment(polyline) {
      const line = polyline.clone();
      const lastXYPoint = line.removePoint(0, line.paths[0].length - 1);
      const existingLineFinalPoint = line.getPoint(
        0,
        line.paths[0].length - 1
      );

      return {
        type: "polyline",
        spatialReference: view.spatialReference,
        hasZ: false,
        paths: [
          [
            [existingLineFinalPoint.x, existingLineFinalPoint.y],
            [lastXYPoint.x, lastXYPoint.y]
          ]
        ]
      };
    }
  });
&amp;lt;/script&amp;gt;
  &amp;lt;/head&amp;gt;

  &amp;lt;body&amp;gt;
    &amp;lt;!-- https://developers.arcgis.com/javascript/latest/esri-icon-font/ --&amp;gt;
    &amp;lt;div id="viewDiv"&amp;gt;
      &amp;lt;div id="point-button" class="esri-widget esri-widget--button esri-interactive" title="Draw point"&amp;gt;
        &amp;lt;span class="esri-icon-map-pin"&amp;gt;&amp;lt;/span&amp;gt;           
      &amp;lt;/div&amp;gt; 
      &amp;lt;div id="line-button" class="esri-widget esri-widget--button esri-interactive" title="Draw polyline"&amp;gt;
        &amp;lt;span class="esri-icon-polyline"&amp;gt;&amp;lt;/span&amp;gt;           
      &amp;lt;/div&amp;gt;
      &amp;lt;div id="polygon-button" class="esri-widget esri-widget--button esri-interactive" title="Draw polygon"&amp;gt;
        &amp;lt;span class="esri-icon-polygon"&amp;gt;&amp;lt;/span&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;</description>
      <pubDate>Thu, 08 Sep 2022 18:00:37 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/draw-point-line-poly-and-get-its-geometry/m-p/1210895#M78648</guid>
      <dc:creator>jaykapalczynski</dc:creator>
      <dc:date>2022-09-08T18:00:37Z</dc:date>
    </item>
  </channel>
</rss>

