get angle between two points to rotate the map View

106
4
a week ago
SaiPeketi
New Contributor III

Hi, 

Is there any way to rotate the map view properly based on the two-point angle? Currently, I'm using Geodesic Distance but I'm not getting correct angle to rotate the map view https://developers.arcgis.com/javascript/latest/api-reference/esri-geometry-support-geodesicUtils.ht...

 

 

Thanks for help in advance

0 Kudos
4 Replies
JohnGrayson
Esri Regular Contributor

Can you share a Codepen or similar showing why you can't use the results of this method?

0 Kudos
SaiPeketi
New Contributor III

@JohnGrayson Here is the Codepen example(https://codepen.io/Andy0206/pen/mdYJBEX?editors=1000) in which I'm trying to rotate the map view to make the polygon 90 degrees for one of my requirements. But the angle is not coming right as the second screenshot

I have a polygon like this 

SaiPeketi_0-1715702721381.png

and want to make the polygon to 90 degrees with it.

SaiPeketi_1-1715702816668.png

 

 

0 Kudos
JohnGrayson
Esri Regular Contributor

The error message when calling the method with your coordinates is:
message
: "input geometry spatial reference is not supported"

Here's a slightly updated version that doesn't throw the error message:
https://codepen.io/john-grayson/pen/LYoVmXG

I hope this helps.

0 Kudos
mleahy_cl
New Contributor III

If I understand the docs correctly, geodesicDistance expects longitude/latitude coordinates, so you may need to project the point coordinates to get a correct azimuth between the points.  However (someone correct me if I'm mistaken), I don't think the azimuth you get from the geodesicDistance method will produce the expected result when applied to the web map that is displayed using the basemap's web mercator projection.

Maybe it is sufficient to just calculate the 2D angle between the two web mercator point coordinates?  For example, this stackoverflow post covers how to do that.  I'm not aware of a method in the ArcGIS SDK provides a convenient way to calculate that.

0 Kudos