1

How can I simply draw a line between two lat long coordinates values on a map using ESRI ArcGIS JS API?! This most basic task is taking a gruesome amount of effort.

I am able to draw a line with the below, but it's not reading my latitude and longitude coordinate values as such, instead it's taking the point to some arbitrary destination.

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: [-118.80500,34.02700],
    zoom: 13
  });

  var graphicsLayer = new GraphicsLayer();
  map.add(graphicsLayer);  

  // Create a point
   var point = {
   type: "point",
   longitude: -118.80657463861,
   latitude: 34.0005930608889
  };

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

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

  graphicsLayer.add(pointGraphic);

  // Create a line geometry
  var simpleLineSymbol = {
     type: "simple-line",
     color: [226, 119, 40], // orange
     width: 2
   };

   var polyline = {
     type: "polyline",
     paths: [
       [35.9411934679851, -80.96135253906438], 
       [-118.808878330345, 34.0016642996246]
     ]
   };

   var polylineGraphic = new Graphic({
     geometry: polyline,
     symbol: simpleLineSymbol
   })

   graphicsLayer.add(polylineGraphic);

  var polygonGraphic = new Graphic({
   geometry: polygon,
   symbol: simpleFillSymbol
  });

  graphicsLayer.add(polygonGraphic);

});

This block specifically, I simply just want to feed in two sets of lat and long coordinates values.... i.e. CoordinatesA and CoordinatesB (as the startpoint and endpoint, why is this so difficult)

   var polyline = {
     type: "polyline",
     paths: [
       [35.9411934679851, -80.96135253906438], 
       [-118.808878330345, 34.0016642996246]
     ]
   };

CodePen https://codepen.io/camerondevcam/pen/PowjVqq?editors=0010

1 Answer 1

2

Might be an issue with the order of LAT/LON. I tried by using mentioned code and it draws a line from EAST to WEST across USA.

var polyline = {
          type: "polyline", // autocasts as new Polyline()
         paths: [
       [-80.96135253906438,35.9411934679851], //interchanged the values
       [-118.808878330345, 34.0016642996246]
     ]

Sample: https://jsfiddle.net/n09czL2k/

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.