1

I am trying to draw a polyLine to the center of the screen (as the second path, point B) ... I tried referencing the below to get center: any pointers?

  coordinatesBx = map.extent.getCenter().getLatitude();
  coordinatesBy = map.extent.getCenter().getLongitude();

The above errors with cannot getCenter() of undefined... should I try to get this in screenPoints first, then try to convert to lat long?

I am good with my first two start points as lat long coords, i.e. workingStartA and workingStartB; however I cannot get the second coordinatesBx and coordinatesBy to go to center of screen. I am in arcgis-JS 4.11 specifically.

i.e.

  var polyline = {
      type: "polyline",
      paths: [
          [workingStartA, workingStartB],
          [coordinatesBx, coordinatesBy]
      ]
  };

Update:

Here is my map; I essentially just want to call the center property lat and long; It works when I manually enter it as the below; but I would like to call it as a variable and have it update automatically when mapview is updated.

const view = new view ({
    center: [-93.70, 38.65], // can i grab this as two vars?
    container: 'mapview',
    map: esriMap,
    zoom: 5
  });
1

If you are using API 3 (I think this is the one you are using it), then what it might be happening is that you are not waiting for the map to load.

map.on("load", function () {console.log(map.extent);});

On the new API (API 4), you need to get the data from the view. Here, the view has a center property, something like this:

let coordinateBx = view.center.x;
let coordinateBy = view.center.y;

A full example using one from API docs:

<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8" />
    <meta
      name="viewport"
      content="initial-scale=1,maximum-scale=1,user-scalable=no"
    />
    <title>Intro to MapView - Create a 2D map - 4.14</title>
    <style>
      html,
      body,
      #viewDiv {
        padding: 0;
        margin: 0;
        height: 100%;
        width: 100%;
      }
    </style>

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

    <script>
      require(["esri/Map", "esri/views/MapView", "esri/Graphic"], function(
        Map,
        MapView,
        Graphic
      ) {
        var map = new Map({
          basemap: "streets"
        });

        var view = new MapView({
          container: "viewDiv",
          map: map,
          zoom: 4,
          center: [15, 65] // longitude, latitude
        });

        console.log(`x:${view.center.x} y:${view.center.y}`);
      });
    </script>
  </head>

  <body>
    <div id="viewDiv"></div>
  </body>
</html>
  • Thanks for taking a look; I am on version 4.11 unfortunately -- I've updated my question with more details. – emilio estevez Jan 14 at 20:55
  • Can you post the code when you create the map and the view? – cabesuon Jan 14 at 21:09
  • I have it in const like const view = app.mapview; const map = view.map; – emilio estevez Jan 14 at 21:43
  • I've added the initial map instance; can I call the center property as two vars? – emilio estevez Jan 14 at 23:05
  • Like I mention you need to use the center property of the view, I have updated the answer with an example. – cabesuon Jan 15 at 4:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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