<?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: Set Extent based on Polygon in ArcGIS JavaScript Maps SDK Questions</title>
    <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/set-extent-based-on-polygon/m-p/1085391#M74122</link>
    <description>&lt;P&gt;I'm not sure what wasn't working with the geometry I was generating before, but the Sketch widget got me to the answer I was looking for.&lt;BR /&gt;&lt;BR /&gt;If anyone else is looking for a solution, I made a codepen with the core functionality described above. You can view it &lt;A href="https://codepen.io/cmenikheim-geojobe/pen/XWRBBMx" target="_blank" rel="noopener"&gt;here&lt;/A&gt;. (This is basically a rubber-band zoom widget for any user who can't zoom to a map extent by holding ctrl while clicking and drawing a rectangle due to accessibility concerns).&lt;/P&gt;</description>
    <pubDate>Tue, 03 Aug 2021 16:33:27 GMT</pubDate>
    <dc:creator>CourtneyMenikheim</dc:creator>
    <dc:date>2021-08-03T16:33:27Z</dc:date>
    <item>
      <title>Set Extent based on Polygon</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/set-extent-based-on-polygon/m-p/1084590#M74080</link>
      <description>&lt;P&gt;I am working trying to write a custom widget for Experience Builder using with the Javascript 4.x API. The user should be able to draw a rectangle, then the map (working in 2d here, 3d comes later) should update to the extent of the rectangle drawn.&lt;/P&gt;&lt;P&gt;I can get the rectangle from the user and draw it on the map as a visual display of the area that will be the new extent, I just can't get the view to actually&amp;nbsp;&lt;EM&gt;move&lt;/EM&gt; to that extent. I thought the &lt;A href="https://developers.arcgis.com/javascript/latest/api-reference/esri-views-MapView.html#goTo" target="_blank" rel="noopener"&gt;goTo&lt;/A&gt; method of the MapView would be my answer, but I can't quite seem to get it right. Any advice?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;/** @jsx jsx */
import {React, AllWidgetProps,  jsx } from 'jimu-core';
import {JimuMapView, JimuMapViewComponent } from 'jimu-arcgis';

import { Point, Polygon } from 'esri/geometry';
import * as Graphic from "esri/Graphic";
import * as GraphicsLayer from "esri/layers/GraphicsLayer";

import {getStyle} from './lib/style';
import { jimuMapViewAdded } from 'jimu-core/lib/app-actions';

export default class Widget extends React.PureComponent&amp;lt;AllWidgetProps&amp;lt;any&amp;gt;, any&amp;gt; {
  
  /** code for creating graphics layer, activating button for user
   * to be able to draw the rectangle, etc.
   */

  setNewExtent(evt) {
    //get the point for the last corner on the rectangle
    let crossPoint: Point = this.state.jimuMapView.view.toMap({
      x: evt.x,
      y: evt.y
    });

    //draw the rectangle
    let extentRectangle = new Polygon({
      rings: [
        [ this.state.startingPoint.x, this.state.startingPoint.y ], // starting point
        [ this.state.startingPoint.x, crossPoint.y ], // corner 1
        [ crossPoint.x, crossPoint.y ], // diagonal to starting point (current cursor location)
        [ crossPoint.x, this.state.startingPoint.y ], //corner 2
        [ this.state.startingPoint.x, this.state.startingPoint.y ] // starting point (close rectangle)
      ],
      spatialReference: { wkid: this.state.jimuMapView.view.map.spatialReference }
    });
    //turn the geometry into a graphic
    let extentGraphic = new Graphic({
      geometry: extentRectangle,
      symbol: this.state.extentSymbol // simple fill symbol
    });
    //add the graphic to the map
    this.state.graphicsLayer.add(extentGraphic);

    //set the mapview to the extent of the user's rectangle
    this.state.jimuMapView.view.goTo(extentRectangle);
    //it works the same with goTo(extentGraphic)

    /**
     * Later code for deactivating button, removing 
     * stylings for edit mode, etc.
     */
  }
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;There are no errors in the console. Any advice on what I'm missing?&lt;/P&gt;</description>
      <pubDate>Fri, 30 Jul 2021 20:09:40 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/set-extent-based-on-polygon/m-p/1084590#M74080</guid>
      <dc:creator>CourtneyMenikheim</dc:creator>
      <dc:date>2021-07-30T20:09:40Z</dc:date>
    </item>
    <item>
      <title>Re: Set Extent based on Polygon</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/set-extent-based-on-polygon/m-p/1084610#M74082</link>
      <description>&lt;P&gt;I'm not using Jimu, but since jimuMapView.view equates to an ArcGIS Javascript View, I would just use 'extent', as in this.state.jimuMapView.view.extent = extentRectangle.&lt;/P&gt;</description>
      <pubDate>Fri, 30 Jul 2021 20:37:19 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/set-extent-based-on-polygon/m-p/1084610#M74082</guid>
      <dc:creator>JeffreyWilkerson</dc:creator>
      <dc:date>2021-07-30T20:37:19Z</dc:date>
    </item>
    <item>
      <title>Re: Set Extent based on Polygon</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/set-extent-based-on-polygon/m-p/1085087#M74106</link>
      <description>&lt;P&gt;extentRectangle is a polygon.&lt;BR /&gt;I can do&lt;BR /&gt;this.state.jimMapView.view.extent = extentRectangle.extent, but I get an error in the console saying:&lt;BR /&gt;&lt;BR /&gt;[esri.views.MapView] #extent invalid extent size&lt;BR /&gt;&lt;BR /&gt;I can output the extentRectangle's extent just before that line runs (using a debugger to be sure), and it has a valid center, xmin, xmax, ymin, ymax, and spatialReference.&lt;/P&gt;</description>
      <pubDate>Mon, 02 Aug 2021 20:05:01 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/set-extent-based-on-polygon/m-p/1085087#M74106</guid>
      <dc:creator>CourtneyMenikheim</dc:creator>
      <dc:date>2021-08-02T20:05:01Z</dc:date>
    </item>
    <item>
      <title>Re: Set Extent based on Polygon</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/set-extent-based-on-polygon/m-p/1085098#M74107</link>
      <description>&lt;P&gt;Doesn't make sense why it won't work.&amp;nbsp; The API reference for MapView says the 'extent' is just an Extent object with xmax, xmin, ymax, ymin, center, and spatialReference which it has.&amp;nbsp; Maybe there needs to be a conversion to a jimuMapView.extent, or maybe import the ArcGIS API Extent object and set a new one equal to extentRectangle.extent, then use that.&amp;nbsp; Seems unnecessary but it's all I can think of.&lt;/P&gt;</description>
      <pubDate>Mon, 02 Aug 2021 20:28:46 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/set-extent-based-on-polygon/m-p/1085098#M74107</guid>
      <dc:creator>JeffreyWilkerson</dc:creator>
      <dc:date>2021-08-02T20:28:46Z</dc:date>
    </item>
    <item>
      <title>Re: Set Extent based on Polygon</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/set-extent-based-on-polygon/m-p/1085119#M74110</link>
      <description>&lt;P&gt;But what types of values are you getting and how do they compare to the current MapView extent and SR?&amp;nbsp; Setting a MapView extent to your specific extent is something you should be able to test via&amp;nbsp; a simple codepen that doesn't use ExB or widgets.&amp;nbsp; Also, you should check out the SketchViewModel as it will provides a way for the user to interactively create an extent that you could then zoom to.&lt;/P&gt;</description>
      <pubDate>Mon, 02 Aug 2021 22:13:34 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/set-extent-based-on-polygon/m-p/1085119#M74110</guid>
      <dc:creator>JohnGrayson</dc:creator>
      <dc:date>2021-08-02T22:13:34Z</dc:date>
    </item>
    <item>
      <title>Re: Set Extent based on Polygon</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/set-extent-based-on-polygon/m-p/1085391#M74122</link>
      <description>&lt;P&gt;I'm not sure what wasn't working with the geometry I was generating before, but the Sketch widget got me to the answer I was looking for.&lt;BR /&gt;&lt;BR /&gt;If anyone else is looking for a solution, I made a codepen with the core functionality described above. You can view it &lt;A href="https://codepen.io/cmenikheim-geojobe/pen/XWRBBMx" target="_blank" rel="noopener"&gt;here&lt;/A&gt;. (This is basically a rubber-band zoom widget for any user who can't zoom to a map extent by holding ctrl while clicking and drawing a rectangle due to accessibility concerns).&lt;/P&gt;</description>
      <pubDate>Tue, 03 Aug 2021 16:33:27 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/set-extent-based-on-polygon/m-p/1085391#M74122</guid>
      <dc:creator>CourtneyMenikheim</dc:creator>
      <dc:date>2021-08-03T16:33:27Z</dc:date>
    </item>
  </channel>
</rss>

