How to add point on a map with marker and get coordinates

534
1
Jump to solution
09-11-2019 11:01 PM
KafilBaig
New Contributor III

I want to add a point with marker on map and get coordinates . How can I achieve this on JavaScript api 4.12 . Please suggest if any example 

0 Kudos
1 Solution

Accepted Solutions
RobertScheitlin__GISP
MVP Esteemed Contributor

Here is a sample for that:

<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8" />
    <meta
      name="viewport"
      content="initial-scale=1,maximum-scale=1,user-scalable=no"
    />
    <title>Sketch widget - 4.12</title>

    <link
      rel="stylesheet"
      href="https://js.arcgis.com/4.12/esri/themes/light/main.css"
    />
    <script src="https://js.arcgis.com/4.12/"></script>

    <style>
      html,
      body,
      #viewDiv {
        padding: 0;
        margin: 0;
        height: 100%;
        width: 100%;
      }
    </style>
    <script>
      require([
        "esri/widgets/Sketch",
        "esri/Map",
        "esri/layers/GraphicsLayer",
        "esri/views/MapView"
      ], function(Sketch, Map, GraphicsLayer, MapView) {
        const layer = new GraphicsLayer();

        const map = new Map({
          basemap: "streets",
          layers: [layer]
        });

        const view = new MapView({
          container: "viewDiv",
          map: map,
          zoom: 5,
          center: [90, 45]
        });

        const sketch = new Sketch({
          layer: layer,
          view: view,
          availableCreateTools: ["point"]
        });

        view.ui.add(sketch, "top-right");
        
        sketch.on('create', function(evt){
          console.info(evt.graphic.geometry);
        });
      });
    </script>
  </head>

  <body>
    <div id="viewDiv"></div>
  </body>
</html>

View solution in original post

0 Kudos
1 Reply
RobertScheitlin__GISP
MVP Esteemed Contributor

Here is a sample for that:

<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8" />
    <meta
      name="viewport"
      content="initial-scale=1,maximum-scale=1,user-scalable=no"
    />
    <title>Sketch widget - 4.12</title>

    <link
      rel="stylesheet"
      href="https://js.arcgis.com/4.12/esri/themes/light/main.css"
    />
    <script src="https://js.arcgis.com/4.12/"></script>

    <style>
      html,
      body,
      #viewDiv {
        padding: 0;
        margin: 0;
        height: 100%;
        width: 100%;
      }
    </style>
    <script>
      require([
        "esri/widgets/Sketch",
        "esri/Map",
        "esri/layers/GraphicsLayer",
        "esri/views/MapView"
      ], function(Sketch, Map, GraphicsLayer, MapView) {
        const layer = new GraphicsLayer();

        const map = new Map({
          basemap: "streets",
          layers: [layer]
        });

        const view = new MapView({
          container: "viewDiv",
          map: map,
          zoom: 5,
          center: [90, 45]
        });

        const sketch = new Sketch({
          layer: layer,
          view: view,
          availableCreateTools: ["point"]
        });

        view.ui.add(sketch, "top-right");
        
        sketch.on('create', function(evt){
          console.info(evt.graphic.geometry);
        });
      });
    </script>
  </head>

  <body>
    <div id="viewDiv"></div>
  </body>
</html>
0 Kudos