AnsweredAssumed Answered

Create Point Graphic from Input boxes values

Question asked by roci_helix on Oct 17, 2019
Latest reply on Oct 18, 2019 by rscheitlin

Hello all,

I'm having trouble creating point graphic on a map from input values box.  Below are the code that I have.  I'm trying to get the lat and long values that is entered to plot on the map after the button is clicked.  Any help on how to get the global input values into the require() to generate the point graphic would be appreciated.  Thanks,

 

<html>
<head>
     <meta charset="utf-8">
     <meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no">
     <title>Create Point Graphic</title>
     <style>
           #viewDiv {
               padding: 0;
               margin: 0;
               height: 600px;
               width: 100%;
            }
            #getInput{
               margin-left: 100px;
               height: 100px;
               
            }
     </style>

     <link rel="stylesheet" href="https://js.arcgis.com/4.12/esri/css/main.css">
     <script src="https://js.arcgis.com/4.12/"></script>
 
     <script>
          var longi = -96.867;
          var lati = 40.228;
          var lontest;
          var lattest;

          function plotPoint()
          {
               lontest = document.getElementById("longInput").value;
               lattest = document.getElementById("latInput").value;
               alert("Long: "+lontest +" Lat: "+lattest);
          }
          require([
            "esri/Map",
            "esri/views/MapView",
            "esri/Graphic",
            "esri/layers/GraphicsLayer"
          ], function(Map, MapView, Graphic, GraphicsLayer)
          {
      
               var map = new Map({
                    basemap: "topo-vector"
               });

               var view = new MapView({
                    container: "viewDiv", 
                    map: map,
                    center: [-96.8670, 40.228],
                    zoom: 6
               });

               var graphicsLayer = new GraphicsLayer();
               map.add(graphicsLayer); 
               
               
               // Create a point
               var point = {
                    type: "point",
                    longitude: lontest ,
                    latitude: lattest
               };

               var simpleMarkerSymbol = {
                    type: "simple-marker",
                    color: [226, 119, 40],  // orange
                    outline: {
                          color: [12, 137, 148],
                          width: 1
                    }
               };

               var pointGraphic = new Graphic({
                    geometry: point,
                    symbol: simpleMarkerSymbol
               });

               graphicsLayer.add(pointGraphic);
               
          });
     </script>

</head>
<body>
     <div id="getInput">
          Latitude:<br>
          <input id="latInput" type="text" name="latpoint">
          <br>
          Longitude:<br>
          <input id="longInput" type="text" name="longpoint">
          <button onclick="plotPoint()"> Click Me</button>
     </div>
  <div id="viewDiv"></div>
</body>
</html>

Outcomes