<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Esri GIS setting to the same ViewPoint yields different result in ArcGIS JavaScript Maps SDK Questions</title>
    <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/esri-gis-setting-to-the-same-viewpoint-yields/m-p/1176762#M77457</link>
    <description>&lt;P&gt;I'm trying to implement some&amp;nbsp;zoom-in-zoom&amp;nbsp;out feature in my program, for this I'm using two&amp;nbsp;ViewPoints&amp;nbsp;with&amp;nbsp;Wgs84&amp;nbsp;projection, one is default and other one is current, when I return to the default one it seems to "drift" by ~ 0.1 degrees(P.s the logic working as intended)&lt;/P&gt;&lt;P&gt;so on the first time&amp;nbsp;_currentViewPoint&amp;nbsp;,XMin&amp;nbsp;for example, is&amp;nbsp;4.77075...&amp;nbsp;which is&amp;nbsp;exactly&amp;nbsp;as&amp;nbsp;_defaultViewPoint&amp;nbsp;XMin&lt;/P&gt;&lt;P&gt;but on the second time(after some panning and zooming the&amp;nbsp;else&amp;nbsp;condition is met and returning to&amp;nbsp;_defaultViewPoint) the&amp;nbsp;&lt;A href="https://tommypetrussia.com/" target="_self"&gt;_&lt;/A&gt;currentViewPoint&amp;nbsp;XMin&amp;nbsp;is&amp;nbsp;4.62159...&lt;/P&gt;&lt;P&gt;why this so called drift happens?&lt;/P&gt;&lt;PRE&gt;public void Click()
{
    if(_firstClick)
    {
        _firstClick = false;
        _mapService = GetMapService();
        _defaultViewPoint = _mapService.IntialViewPoint;
    }
    
    _currentViewPoint = _mapService.GetViewPoint();
    if(ArePointsEqual(_defaultViewPoint,_currentViewPoint)
    {
        if(_viewPointToZoom != null)
        {
            _mapService.SetViewPointAsync(_viewPointToZoom)
        }
    }
    else
    {
        _viewPointToZoom = _mapService.GetViewPoint();
        _mainMapService.SetViewPointAsync(_defaultViewPoint);
    }
}

public ViewPoint GetViewPoint()
{
    ViewPoint current = null;
    try
    {
        current = EsriGeoView.GetCurrentViewPoint(ViewpointType.BoundingGeomerty);
        return ProjectToWgs84(current.TargetGeometry);
    }
    catch(...)
    {
        //catch
    }
    return current;
}

private ViewPoint ProjectToWgs94(Geometry targetGeometry)
{
    try
    {       
        var geometry = GeometryEngine.Project(targetGeometry, SpatialReefernces.Wgs84);
        return new ViewPoint(geometry);
    }
    catch(...)
    {
        //catch
    }
    
}

private async Task SetViewPointAsync(ViewPoint viewpoint)
{
    //some non relevent code
    await EsriGeoView.SetViewPointAsync(viewpoint);
}


private bool AreViewPointsEqual(Viewpoint vp1, Viewpoint vp2, double tolerance = 1e-4)
{

    Envelope r1 = vp1.TargetGeometry.Extent,  r2 = vp2.TargetGeometry.Extent;
    var x1 = (r1.XMax + r1.XMin) / 2;
    var x2 = (r1.YMax + r1.YMin) / 2;
    var y1 = (r2.XMax + r2.XMin) / 2;
    var y2 = (r2.YMax + r2.YMin) / 2;

    return Math.abs(x1-x2) &amp;lt; tolerance &amp;amp;&amp;amp; Math.abs(y1-y2) &amp;lt; tolerance);

} &lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Sat, 02 Jul 2022 08:30:27 GMT</pubDate>
    <dc:creator>WorldZone</dc:creator>
    <dc:date>2022-07-02T08:30:27Z</dc:date>
    <item>
      <title>Esri GIS setting to the same ViewPoint yields different result</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/esri-gis-setting-to-the-same-viewpoint-yields/m-p/1176762#M77457</link>
      <description>&lt;P&gt;I'm trying to implement some&amp;nbsp;zoom-in-zoom&amp;nbsp;out feature in my program, for this I'm using two&amp;nbsp;ViewPoints&amp;nbsp;with&amp;nbsp;Wgs84&amp;nbsp;projection, one is default and other one is current, when I return to the default one it seems to "drift" by ~ 0.1 degrees(P.s the logic working as intended)&lt;/P&gt;&lt;P&gt;so on the first time&amp;nbsp;_currentViewPoint&amp;nbsp;,XMin&amp;nbsp;for example, is&amp;nbsp;4.77075...&amp;nbsp;which is&amp;nbsp;exactly&amp;nbsp;as&amp;nbsp;_defaultViewPoint&amp;nbsp;XMin&lt;/P&gt;&lt;P&gt;but on the second time(after some panning and zooming the&amp;nbsp;else&amp;nbsp;condition is met and returning to&amp;nbsp;_defaultViewPoint) the&amp;nbsp;&lt;A href="https://tommypetrussia.com/" target="_self"&gt;_&lt;/A&gt;currentViewPoint&amp;nbsp;XMin&amp;nbsp;is&amp;nbsp;4.62159...&lt;/P&gt;&lt;P&gt;why this so called drift happens?&lt;/P&gt;&lt;PRE&gt;public void Click()
{
    if(_firstClick)
    {
        _firstClick = false;
        _mapService = GetMapService();
        _defaultViewPoint = _mapService.IntialViewPoint;
    }
    
    _currentViewPoint = _mapService.GetViewPoint();
    if(ArePointsEqual(_defaultViewPoint,_currentViewPoint)
    {
        if(_viewPointToZoom != null)
        {
            _mapService.SetViewPointAsync(_viewPointToZoom)
        }
    }
    else
    {
        _viewPointToZoom = _mapService.GetViewPoint();
        _mainMapService.SetViewPointAsync(_defaultViewPoint);
    }
}

public ViewPoint GetViewPoint()
{
    ViewPoint current = null;
    try
    {
        current = EsriGeoView.GetCurrentViewPoint(ViewpointType.BoundingGeomerty);
        return ProjectToWgs84(current.TargetGeometry);
    }
    catch(...)
    {
        //catch
    }
    return current;
}

private ViewPoint ProjectToWgs94(Geometry targetGeometry)
{
    try
    {       
        var geometry = GeometryEngine.Project(targetGeometry, SpatialReefernces.Wgs84);
        return new ViewPoint(geometry);
    }
    catch(...)
    {
        //catch
    }
    
}

private async Task SetViewPointAsync(ViewPoint viewpoint)
{
    //some non relevent code
    await EsriGeoView.SetViewPointAsync(viewpoint);
}


private bool AreViewPointsEqual(Viewpoint vp1, Viewpoint vp2, double tolerance = 1e-4)
{

    Envelope r1 = vp1.TargetGeometry.Extent,  r2 = vp2.TargetGeometry.Extent;
    var x1 = (r1.XMax + r1.XMin) / 2;
    var x2 = (r1.YMax + r1.YMin) / 2;
    var y1 = (r2.XMax + r2.XMin) / 2;
    var y2 = (r2.YMax + r2.YMin) / 2;

    return Math.abs(x1-x2) &amp;lt; tolerance &amp;amp;&amp;amp; Math.abs(y1-y2) &amp;lt; tolerance);

} &lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 02 Jul 2022 08:30:27 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/esri-gis-setting-to-the-same-viewpoint-yields/m-p/1176762#M77457</guid>
      <dc:creator>WorldZone</dc:creator>
      <dc:date>2022-07-02T08:30:27Z</dc:date>
    </item>
  </channel>
</rss>

