<?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 Re: SketchViewModel geometry editing bug 4.19 in ArcGIS JavaScript Maps SDK Questions</title>
    <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/sketchviewmodel-geometry-editing-bug-4-19/m-p/1067633#M73470</link>
    <description>&lt;P&gt;As a revision to what I said about the issue earlier, the problem occurs whenever the geometry being edited isn't normalized to the view.&amp;nbsp; That is, it occurs in cases where the geometry's x values don't fall within the range of the view's xmin and xmax, but because of wrapping, the geometry still displays within the view.&lt;/P&gt;&lt;P&gt;As a result, I gave up on trying workarounds, and went straight to the heart of the issue, which turns out to be the &lt;A href="http://toScreen" target="_self"&gt;toScreen&lt;/A&gt; function of the &lt;A href="https://developers.arcgis.com/javascript/latest/api-reference/esri-views-MapView.html" target="_self"&gt;MapView&lt;/A&gt;.&amp;nbsp; When using interactive geometry editing with the &lt;A href="https://developers.arcgis.com/javascript/latest/api-reference/esri-widgets-Sketch-SketchViewModel.html" target="_self"&gt;SketchViewModel&lt;/A&gt;, it uses an internal &lt;A href="https://developers.arcgis.com/javascript/latest/api-reference/esri-layers-GraphicsLayer.html" target="_self"&gt;GraphicsLayer&lt;/A&gt; to display the rotation and resizing handles (etc).&amp;nbsp; As you move the mouse, it constantly checks to see if the mouse is over one of those handles, and it does so in part by using the _intersectDistance2D function of the esri/views/interactive/GraphicManipulator class.&amp;nbsp; Within this function is a call to &lt;A href="https://developers.arcgis.com/javascript/latest/api-reference/esri-views-MapView.html" target="_self"&gt;MapView&lt;/A&gt;.&lt;A href="https://developers.arcgis.com/javascript/latest/api-reference/esri-views-MapView.html#toScreen" target="_self"&gt;toScreen&lt;/A&gt;.&amp;nbsp; If the geographic coordinates of those handles are not within the xmin and xmax of the view's extent, the returned &lt;A href="https://developers.arcgis.com/javascript/latest/api-reference/esri-views-MapView.html#ScreenPoint" target="_self"&gt;ScreenPoint&lt;/A&gt;'s x value will be off the charts (i.e. well outside of your screen's width).&amp;nbsp; It shouldn't work this way since the handle is clearly on the screen.&amp;nbsp; As a result, _intersectDistance2D concludes the mouse pointer is nowhere near the handle, and so you ultimately can't use it.&lt;/P&gt;&lt;P&gt;As it turns out, I was already dealing with this kind of issue elsewhere, so I had a custom function added directly to the Point prototype called normalizeToView.&amp;nbsp; Here is the implementation (note that spatialReferenceUtils is the module esri/geometry/support/spatialReferenceUtils):&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;Point.prototype.normalizeToView = function(view) {
    var point = this.clone();

    if ((view) &amp;amp;&amp;amp; (view.extent) &amp;amp;&amp;amp; (!view.extent.intersects(this))) {
        var info = spatialReferenceUtils.getInfo(view.spatialReference);

        if (info) {
            var extents = view.extent.clone().normalize();
            var nPoint = this.clone().normalize();
            var intersects = false;

            for (var x = 0; x &amp;lt; extents.length; x++) {
                if (extents[x].intersects(nPoint)) {
                    intersects = true;
                    break;
                }
            }

            if (intersects) {
                var worldWidth = info.valid[1] * 2;

                while (point.x &amp;lt; view.extent.xmin)
                    point.x += worldWidth;

                while (point.x &amp;gt; view.extent.xmax)
                    point.x -= worldWidth;
            }
        }
    }

    return point;
};&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Therefore, I just revised the &lt;A href="https://developers.arcgis.com/javascript/latest/api-reference/esri-views-MapView.html#toScreen" target="_self"&gt;toScreen&lt;/A&gt; function to use this if it was available.&amp;nbsp; In the file&amp;nbsp;esri/views/MapView.js, I did the following:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Search for:&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;U=this._normalizeInput(U);&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Replace with:&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;U=this._normalizeInput((((U)&amp;amp;&amp;amp;(typeof U.normalizeToView=="function"))?U.normalizeToView(this):U));&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Sat, 12 Jun 2021 02:45:35 GMT</pubDate>
    <dc:creator>JoelBennett</dc:creator>
    <dc:date>2021-06-12T02:45:35Z</dc:date>
    <item>
      <title>SketchViewModel geometry editing bug 4.19</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/sketchviewmodel-geometry-editing-bug-4-19/m-p/1064958#M73395</link>
      <description>&lt;P&gt;The interactive geometry-editing utility of the &lt;A href="https://developers.arcgis.com/javascript/latest/api-reference/esri-widgets-Sketch-SketchViewModel.html" target="_self"&gt;SketchViewModel&lt;/A&gt; will not work if the view's &lt;A href="https://developers.arcgis.com/javascript/latest/api-reference/esri-views-MapView.html#extent" target="_self"&gt;extent&lt;/A&gt; is not normalized. This can be verified in the sample "&lt;A href="https://developers.arcgis.com/javascript/latest/sample-code/widgets-editor-basic/" target="_self"&gt;Edit features with the Editor widget&lt;/A&gt;" with the following steps:&lt;/P&gt;&lt;OL&gt;&lt;LI&gt;&lt;SPAN&gt;Load the sample.&lt;/SPAN&gt;&lt;/LI&gt;&lt;LI&gt;&lt;SPAN&gt;Pan east (or west) until you go all the way around the world. This will go much faster if you zoom way out, pan, and then zoom back in to the editable features.&lt;/SPAN&gt;&lt;/LI&gt;&lt;LI&gt;In the "Editor" widget, click "Edit feature".&lt;/LI&gt;&lt;LI&gt;Click on a polygon feature; this puts the feature into interactive geometry-editing mode.&lt;/LI&gt;&lt;LI&gt;Move the mouse cursor over the rotation handle; note that rotation handle doesn't become highlighted like it should.&lt;/LI&gt;&lt;LI&gt;Click and drag on the rotation handle; the feature is not rotated, and the map is panned instead. The same occurs if you attempt to use the resize handles or drag the feature to a new location.&lt;/LI&gt;&lt;/OL&gt;&lt;P&gt;This was observed in 4.18 and 4.19; I don't know if it worked in previous versions or not.&lt;/P&gt;&lt;P&gt;I haven't attempted to troubleshoot the API code itself. Instead, my current workaround is to detect if the view's extent is normalized before using the &lt;A href="https://developers.arcgis.com/javascript/latest/api-reference/esri-widgets-Sketch-SketchViewModel.html" target="_self"&gt;SketchViewModel&lt;/A&gt;, and if it is not, to &lt;A href="https://developers.arcgis.com/javascript/latest/api-reference/esri-geometry-Extent.html#normalize" target="_self"&gt;normalize&lt;/A&gt; it before allowing further action to take place.&lt;/P&gt;</description>
      <pubDate>Fri, 04 Jun 2021 01:09:48 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/sketchviewmodel-geometry-editing-bug-4-19/m-p/1064958#M73395</guid>
      <dc:creator>JoelBennett</dc:creator>
      <dc:date>2021-06-04T01:09:48Z</dc:date>
    </item>
    <item>
      <title>Re: SketchViewModel geometry editing bug 4.19</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/sketchviewmodel-geometry-editing-bug-4-19/m-p/1067633#M73470</link>
      <description>&lt;P&gt;As a revision to what I said about the issue earlier, the problem occurs whenever the geometry being edited isn't normalized to the view.&amp;nbsp; That is, it occurs in cases where the geometry's x values don't fall within the range of the view's xmin and xmax, but because of wrapping, the geometry still displays within the view.&lt;/P&gt;&lt;P&gt;As a result, I gave up on trying workarounds, and went straight to the heart of the issue, which turns out to be the &lt;A href="http://toScreen" target="_self"&gt;toScreen&lt;/A&gt; function of the &lt;A href="https://developers.arcgis.com/javascript/latest/api-reference/esri-views-MapView.html" target="_self"&gt;MapView&lt;/A&gt;.&amp;nbsp; When using interactive geometry editing with the &lt;A href="https://developers.arcgis.com/javascript/latest/api-reference/esri-widgets-Sketch-SketchViewModel.html" target="_self"&gt;SketchViewModel&lt;/A&gt;, it uses an internal &lt;A href="https://developers.arcgis.com/javascript/latest/api-reference/esri-layers-GraphicsLayer.html" target="_self"&gt;GraphicsLayer&lt;/A&gt; to display the rotation and resizing handles (etc).&amp;nbsp; As you move the mouse, it constantly checks to see if the mouse is over one of those handles, and it does so in part by using the _intersectDistance2D function of the esri/views/interactive/GraphicManipulator class.&amp;nbsp; Within this function is a call to &lt;A href="https://developers.arcgis.com/javascript/latest/api-reference/esri-views-MapView.html" target="_self"&gt;MapView&lt;/A&gt;.&lt;A href="https://developers.arcgis.com/javascript/latest/api-reference/esri-views-MapView.html#toScreen" target="_self"&gt;toScreen&lt;/A&gt;.&amp;nbsp; If the geographic coordinates of those handles are not within the xmin and xmax of the view's extent, the returned &lt;A href="https://developers.arcgis.com/javascript/latest/api-reference/esri-views-MapView.html#ScreenPoint" target="_self"&gt;ScreenPoint&lt;/A&gt;'s x value will be off the charts (i.e. well outside of your screen's width).&amp;nbsp; It shouldn't work this way since the handle is clearly on the screen.&amp;nbsp; As a result, _intersectDistance2D concludes the mouse pointer is nowhere near the handle, and so you ultimately can't use it.&lt;/P&gt;&lt;P&gt;As it turns out, I was already dealing with this kind of issue elsewhere, so I had a custom function added directly to the Point prototype called normalizeToView.&amp;nbsp; Here is the implementation (note that spatialReferenceUtils is the module esri/geometry/support/spatialReferenceUtils):&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;Point.prototype.normalizeToView = function(view) {
    var point = this.clone();

    if ((view) &amp;amp;&amp;amp; (view.extent) &amp;amp;&amp;amp; (!view.extent.intersects(this))) {
        var info = spatialReferenceUtils.getInfo(view.spatialReference);

        if (info) {
            var extents = view.extent.clone().normalize();
            var nPoint = this.clone().normalize();
            var intersects = false;

            for (var x = 0; x &amp;lt; extents.length; x++) {
                if (extents[x].intersects(nPoint)) {
                    intersects = true;
                    break;
                }
            }

            if (intersects) {
                var worldWidth = info.valid[1] * 2;

                while (point.x &amp;lt; view.extent.xmin)
                    point.x += worldWidth;

                while (point.x &amp;gt; view.extent.xmax)
                    point.x -= worldWidth;
            }
        }
    }

    return point;
};&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Therefore, I just revised the &lt;A href="https://developers.arcgis.com/javascript/latest/api-reference/esri-views-MapView.html#toScreen" target="_self"&gt;toScreen&lt;/A&gt; function to use this if it was available.&amp;nbsp; In the file&amp;nbsp;esri/views/MapView.js, I did the following:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Search for:&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;U=this._normalizeInput(U);&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Replace with:&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;U=this._normalizeInput((((U)&amp;amp;&amp;amp;(typeof U.normalizeToView=="function"))?U.normalizeToView(this):U));&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 12 Jun 2021 02:45:35 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/sketchviewmodel-geometry-editing-bug-4-19/m-p/1067633#M73470</guid>
      <dc:creator>JoelBennett</dc:creator>
      <dc:date>2021-06-12T02:45:35Z</dc:date>
    </item>
    <item>
      <title>Re: SketchViewModel geometry editing bug 4.19</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/sketchviewmodel-geometry-editing-bug-4-19/m-p/1128382#M75661</link>
      <description>&lt;P&gt;This was fixed in version 4.22, presumably as a result of the "MapView.hitTest improvements for GraphicsLayer" mentioned in the release notes.&lt;/P&gt;</description>
      <pubDate>Wed, 22 Dec 2021 18:04:42 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/sketchviewmodel-geometry-editing-bug-4-19/m-p/1128382#M75661</guid>
      <dc:creator>JoelBennett</dc:creator>
      <dc:date>2021-12-22T18:04:42Z</dc:date>
    </item>
  </channel>
</rss>

