AnsweredAssumed Answered

How to get lat/long from drag event

Question asked by bcanseco on Jan 30, 2017
Latest reply on Jan 30, 2017 by rscheitlin

Hello!

 

I'm using the Esri JS API version 4.2 with angular-esri-map and I'm working with a 2D map.

I notice that the default behavior for when a user holds Shift and then clicks+drags on the map is that a rectangular bounding box is drawn, which then becomes the bounds of the view when the user lets go.

 

I'm trying to implement a new behavior in which doing the same thing but with the CTRL key instead of Shift will simply draw a rectangular box on the map without changing the view, and then store the latitude and longitude of both the Northwest and Southeast corners in some JavaScript variables (in my case, variables tied to my angularjs controller).

 

My question: How do I get lat/long from this? I'm only able to see x/y from both the origin and destination points using the drag event.

 

$ctrl.onViewCreated = function(view) {
    $ctrl.mapView = view;

    $ctrl.mapView.on('click', function(e) {
      $ctrl.clickCoordinates = {
        lat: e.mapPoint.latitude,
        lng: e.mapPoint.longitude,
      };
      // I can get lat/long here...
    });

    $ctrl.mapView.on('drag', ['Ctrl'], function(e) {
      // ...but not here!
      e.stopPropagation();
    });
};

 

Thanks!

Outcomes