<?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: Experience builder custom widget in ArcGIS Experience Builder Questions</title>
    <link>https://community.esri.com/t5/arcgis-experience-builder-questions/experience-builder-custom-widget/m-p/1359747#M9848</link>
    <description>&lt;P&gt;Can you explain more about what problems you are having? Are you seeing any errors in the console?&lt;/P&gt;&lt;P&gt;I strongly recommend writing your widgets in function based React, rather than class based. Function based React is the modern style with much simpler syntax.&lt;/P&gt;&lt;P&gt;Here is some starter code for a function based widget that uses API components. &lt;A href="https://community.esri.com/t5/experience-builder-tips-and-tricks/boilerplate-for-a-map-related-custom-widget/ta-p/1340980" target="_blank"&gt;https://community.esri.com/t5/experience-builder-tips-and-tricks/boilerplate-for-a-map-related-custom-widget/ta-p/1340980&lt;/A&gt;&lt;/P&gt;</description>
    <pubDate>Tue, 12 Dec 2023 16:16:30 GMT</pubDate>
    <dc:creator>JeffreyThompson2</dc:creator>
    <dc:date>2023-12-12T16:16:30Z</dc:date>
    <item>
      <title>Experience builder custom widget</title>
      <link>https://community.esri.com/t5/arcgis-experience-builder-questions/experience-builder-custom-widget/m-p/1359694#M9846</link>
      <description>&lt;P&gt;I'm trying to make a simple custom widget that on the button press adds a random point on the map and I'm stuck, this is how my code looks:&lt;/P&gt;&lt;P&gt;import React from 'react';&lt;/P&gt;&lt;P&gt;import { JimuMapView } from 'jimu-arcgis';&lt;BR /&gt;import SimpleMarkerSymbol from '@arcgis/core/symbols/SimpleMarkerSymbol';&lt;BR /&gt;import { AllWidgetProps } from 'jimu-core';&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;export interface State{&lt;BR /&gt;jimuMapView: JimuMapView | undefined;&lt;BR /&gt;}&lt;BR /&gt;export default class Widget extends React.PureComponent&amp;lt;AllWidgetProps&amp;lt;any&amp;gt;, State&amp;gt; {&lt;BR /&gt;Graphic: any;&lt;BR /&gt;Point: any;&lt;BR /&gt;GraphicsLayer: any;&lt;BR /&gt;constructor(props) {&lt;BR /&gt;super(props);&lt;BR /&gt;this.state = {&lt;BR /&gt;jimuMapView : undefined,&lt;BR /&gt;};&lt;BR /&gt;}&lt;BR /&gt;addPointToMap = () =&amp;gt; {&lt;/P&gt;&lt;P&gt;const pointSymbol = new SimpleMarkerSymbol({&lt;BR /&gt;type: 'simple-marker',&lt;BR /&gt;style: 'square',&lt;BR /&gt;color: 'blue',&lt;BR /&gt;size: '8px',&lt;BR /&gt;outline: {&lt;BR /&gt;color: [255, 255, 0],&lt;BR /&gt;width: 3,&lt;BR /&gt;},&lt;BR /&gt;});&lt;BR /&gt;const graphicB = new this.Graphic({&lt;BR /&gt;geometry: new this.Point({ x: 42.34123, y: 21.12341 }),&lt;BR /&gt;symbol: pointSymbol&lt;BR /&gt;});&lt;/P&gt;&lt;P&gt;const layer = new this.GraphicsLayer({&lt;BR /&gt;graphics: [graphicB]&lt;BR /&gt;});&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;this.state.jimuMapView.view.map.add(layer);&lt;BR /&gt;};&lt;/P&gt;&lt;P&gt;render() {&lt;BR /&gt;return (&lt;BR /&gt;&amp;lt;div&amp;gt;&lt;BR /&gt;&amp;lt;button onClick={this.addPointToMap}&amp;gt;Add Point&amp;lt;/button&amp;gt;&lt;BR /&gt;&amp;lt;/div&amp;gt;&lt;BR /&gt;);&lt;BR /&gt;}&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 12 Dec 2023 15:14:04 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-experience-builder-questions/experience-builder-custom-widget/m-p/1359694#M9846</guid>
      <dc:creator>ErsiLover</dc:creator>
      <dc:date>2023-12-12T15:14:04Z</dc:date>
    </item>
    <item>
      <title>Re: Experience builder custom widget</title>
      <link>https://community.esri.com/t5/arcgis-experience-builder-questions/experience-builder-custom-widget/m-p/1359747#M9848</link>
      <description>&lt;P&gt;Can you explain more about what problems you are having? Are you seeing any errors in the console?&lt;/P&gt;&lt;P&gt;I strongly recommend writing your widgets in function based React, rather than class based. Function based React is the modern style with much simpler syntax.&lt;/P&gt;&lt;P&gt;Here is some starter code for a function based widget that uses API components. &lt;A href="https://community.esri.com/t5/experience-builder-tips-and-tricks/boilerplate-for-a-map-related-custom-widget/ta-p/1340980" target="_blank"&gt;https://community.esri.com/t5/experience-builder-tips-and-tricks/boilerplate-for-a-map-related-custom-widget/ta-p/1340980&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 12 Dec 2023 16:16:30 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-experience-builder-questions/experience-builder-custom-widget/m-p/1359747#M9848</guid>
      <dc:creator>JeffreyThompson2</dc:creator>
      <dc:date>2023-12-12T16:16:30Z</dc:date>
    </item>
    <item>
      <title>Re: Experience builder custom widget</title>
      <link>https://community.esri.com/t5/arcgis-experience-builder-questions/experience-builder-custom-widget/m-p/1359802#M9849</link>
      <description>&lt;P&gt;There are a few issues here.&lt;/P&gt;&lt;P&gt;First you need to import Graphic, GraphicsLayer and Point.&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;import Graphic from 'esri/Graphic'
import GraphicsLayer from 'esri/layers/GraphicsLayer'
import Point from 'esri/geometry/Point'&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Remove the declaration of Graphic, Point and GraphicsLayer at the start of your class&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;export default class Widget extends React.PureComponent&amp;lt;AllWidgetProps&amp;lt;any&amp;gt;, State&amp;gt; {

constructor(props) {
    super(props);
    this.state = {
      jimuMapView : undefined,
    };
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Next when creating the new point and graphic, don't use the this. prefix.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;const graphicB = new Graphic({
    geometry: new Point({ x: 42.34123, y: 21.12341 }),
    symbol: pointSymbol
});

const layer = new GraphicsLayer({
   graphics: [graphicB]
});&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Finally, you are trying to add the graphic to the map view, but there is nowhere, where you are getting a reference to it. You need to let the widget know which map to add the graphics too. Have a look at this sample &lt;A href="https://github.com/Esri/arcgis-experience-builder-sdk-resources/blob/master/widgets/get-map-coordinates-class/src/runtime/widget.tsx" target="_self"&gt;here&lt;/A&gt;, This shows how to create a settings page so you can assign your widget a map, then it has a handle within the render method which will get the map when it loaded and ready.&lt;/P&gt;&lt;P&gt;Also, you do not need to export your state interface. You only need to export something from a file if you intend to use it in other parts of your project or in an another file. Otherwise you do not need need the export statement.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 12 Dec 2023 17:32:03 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-experience-builder-questions/experience-builder-custom-widget/m-p/1359802#M9849</guid>
      <dc:creator>Grant-S-Carroll</dc:creator>
      <dc:date>2023-12-12T17:32:03Z</dc:date>
    </item>
    <item>
      <title>Re: Experience builder custom widget</title>
      <link>https://community.esri.com/t5/arcgis-experience-builder-questions/experience-builder-custom-widget/m-p/1364368#M10015</link>
      <description>&lt;P&gt;Hi, Grant.&lt;BR /&gt;&lt;BR /&gt;How do I actually add graphics to a Jimu Map View? Several tutorials on the JS Api propose something like "view.graphics.add()", but JMV.view doesn't seem to have any "graphics" property. I have something similar to the OP, but can't for the life of me figure out how to throw a graphic on top of the point generated by the handler.&lt;/P&gt;</description>
      <pubDate>Tue, 26 Dec 2023 22:06:42 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-experience-builder-questions/experience-builder-custom-widget/m-p/1364368#M10015</guid>
      <dc:creator>BluntBSE</dc:creator>
      <dc:date>2023-12-26T22:06:42Z</dc:date>
    </item>
    <item>
      <title>Re: Experience builder custom widget</title>
      <link>https://community.esri.com/t5/arcgis-experience-builder-questions/experience-builder-custom-widget/m-p/1364381#M10016</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;Without seeing the code, I suspect whats happening is that maybe you have done something like this when you set the JimuMapView.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;activeViewChangeHandler = (jmv: JimuMapView) =&amp;gt; {
    if (!(jmv &amp;amp;&amp;amp; jmv.view)) {
        return;
    }
    this.setState({jimuMapView:jmv});
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Or alternatively, you have set the view in state, eg&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;activeViewChangeHandler = (jmv: JimuMapView) =&amp;gt; {
    if (!(jmv &amp;amp;&amp;amp; jmv.view)) {
        return;
    }
    this.setState({jimuMapView:jmv.view});
}&lt;/LI-CODE&gt;&lt;P&gt;In which case you have a JimuMapView in state, a JimuMapView is not the same as a MapView or a SceneView, you need to access the view property on the JimuMapView, in the example above where we set the JimuMapView in to state, it would then be,&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;//do this.
this.state.jimuMapView.view.graphics.add(graphic);

//not this
this.state.jimuMapView.graphics.add(graphic);&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Or if you have set the view in to state, then its.:&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;//do this.
this.state.jimuMapView.graphics.add(graphic);

//not this
this.state.jimuMapView.view.graphics.add(graphic);&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The details of the properties on a JimuMapView are &lt;A href="https://developers.arcgis.com/experience-builder/api-reference/jimu-arcgis/JimuMapView/" target="_self"&gt;here&lt;/A&gt;&lt;/P&gt;&lt;P&gt;If you see a message saying the a property doesn't exist, then I would recommend setting a breakpoint at the point where you are trying to access the object, and inspect it using the debugging tools in the browser. See an example below, where I have a breakpoint set as the JimuMapView is being checked. In the right hand pane, under&amp;nbsp;&lt;EM&gt;Local&lt;/EM&gt; section, you can see the details of the JimuMapView, you can see the methods and properties it has, you can see it has a &lt;EM&gt;view&lt;/EM&gt; property, but not a&amp;nbsp;&lt;EM&gt;graphics &lt;/EM&gt;property&lt;EM&gt;.&amp;nbsp;&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="GrantSCarroll_0-1703632011228.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/89978i508E6BC6BAC422CB/image-size/medium?v=v2&amp;amp;px=400" role="button" title="GrantSCarroll_0-1703632011228.png" alt="GrantSCarroll_0-1703632011228.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The other thing I do a lot, is log stuff to the console so I can check the values of properties that have been set or to track my progress through code, simple as:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;console.log(this.state.jimuMapView)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This way you can check that the value expect to be there, is the value you expect.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Hope that helps&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 26 Dec 2023 23:11:14 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-experience-builder-questions/experience-builder-custom-widget/m-p/1364381#M10016</guid>
      <dc:creator>Grant-S-Carroll</dc:creator>
      <dc:date>2023-12-26T23:11:14Z</dc:date>
    </item>
    <item>
      <title>Re: Experience builder custom widget</title>
      <link>https://community.esri.com/t5/arcgis-experience-builder-questions/experience-builder-custom-widget/m-p/1371231#M10376</link>
      <description>&lt;P&gt;Hi there, I just wanted to say thank you for your helpful response and (somewhat belatedly) let you know that I've since gotten graphics working in my application, and will refer to your post again in the future for sure.&lt;/P&gt;</description>
      <pubDate>Wed, 17 Jan 2024 20:09:38 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-experience-builder-questions/experience-builder-custom-widget/m-p/1371231#M10376</guid>
      <dc:creator>BluntBSE</dc:creator>
      <dc:date>2024-01-17T20:09:38Z</dc:date>
    </item>
  </channel>
</rss>

