@DaleBecker
Here is a sample for that:
<html>
<head>
<meta charset="utf-8" />
<meta
name="viewport"
content="initial-scale=1,maximum-scale=1,user-scalable=no"
/>
<title>Draw point | Sample | ArcGIS API for JavaScript 4.21</title>
<link
rel="stylesheet"
href="https://js.arcgis.com/4.21/esri/themes/light/main.css"
/>
<script src="https://js.arcgis.com/4.21/"></script>
<style>
html,
body,
#viewDiv {
height: 100%;
width: 100%;
margin: 0;
padding: 0;
}
</style>
<script>
require([
"esri/Map",
"esri/views/MapView",
"esri/views/draw/Draw",
"esri/Graphic",
"esri/layers/GraphicsLayer"
], (Map, MapView, Draw, Graphic, GraphicsLayer) => {
const drawGL = new GraphicsLayer({
id: "draw Graphics Layer"
});
const map = new Map({
basemap: "gray-vector",
layers:[drawGL]
});
const view = new MapView({
container: "viewDiv",
map: map,
zoom: 15,
center: [18.06, 59.34]
});
//map.addLayer(drawGL)
const draw = new Draw({
view: view
});
view.when(()=>{
setDrawAction();
});
function setDrawAction() {
let action = draw.create("point");
// PointDrawAction.cursor-update
// Give a visual feedback to users as they move the pointer over the view
action.on("cursor-update", function (evt) {
createPointGraphic(evt.coordinates);
});
// PointDrawAction.draw-complete
// Create a point when user clicks on the view or presses "C" key.
action.on("draw-complete", function (evt) {
createPointGraphic(evt.coordinates, true);
setDrawAction();
});
}
function createPointGraphic(coordinates, addToGL){
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
}
}
});
if(addToGL){
drawGL.removeAll();
drawGL.add(graphic);
}else{
view.graphics.add(graphic);
}
}
});
</script>
</head>
<body>
<div id="viewDiv"></div>
</body>
</html>