<?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 Clear 2D measurement graphics when using components instead of widgets in ArcGIS JavaScript Maps SDK Questions</title>
    <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/clear-2d-measurement-graphics-when-using/m-p/1594365#M86665</link>
    <description>&lt;P&gt;In the 4.32 SDK, the 3D measurement components have both &lt;STRONG&gt;clear&lt;/STRONG&gt; and&amp;nbsp;&lt;STRONG&gt;start&lt;/STRONG&gt; methods - along with componentReady and destroy methods. But the 2D measurement components (both Area and Distance) only have the latter two methods - I do not see a &lt;STRONG&gt;clear&lt;/STRONG&gt; or a &lt;STRONG&gt;start&lt;/STRONG&gt; method. I am looking for a way to clear the graphics that are created when measuring distance/area in 2D. In the 3D sample code, it uses components; the 2D sample code is still using widgets (rather than arcgis-distance-measurement-2d or arcgis-area-measurement-2d). I already have a way to remove graphics when 2D widgets are used; I'm looking for a way to clear when using components. I already have a button in place that could do the clearing (vs clearing when the tools are no longer expanded). But I'm just not seeing the methods for the actual action.&lt;/P&gt;</description>
    <pubDate>Tue, 11 Mar 2025 17:16:02 GMT</pubDate>
    <dc:creator>LMFGeospatial</dc:creator>
    <dc:date>2025-03-11T17:16:02Z</dc:date>
    <item>
      <title>Clear 2D measurement graphics when using components instead of widgets</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/clear-2d-measurement-graphics-when-using/m-p/1594365#M86665</link>
      <description>&lt;P&gt;In the 4.32 SDK, the 3D measurement components have both &lt;STRONG&gt;clear&lt;/STRONG&gt; and&amp;nbsp;&lt;STRONG&gt;start&lt;/STRONG&gt; methods - along with componentReady and destroy methods. But the 2D measurement components (both Area and Distance) only have the latter two methods - I do not see a &lt;STRONG&gt;clear&lt;/STRONG&gt; or a &lt;STRONG&gt;start&lt;/STRONG&gt; method. I am looking for a way to clear the graphics that are created when measuring distance/area in 2D. In the 3D sample code, it uses components; the 2D sample code is still using widgets (rather than arcgis-distance-measurement-2d or arcgis-area-measurement-2d). I already have a way to remove graphics when 2D widgets are used; I'm looking for a way to clear when using components. I already have a button in place that could do the clearing (vs clearing when the tools are no longer expanded). But I'm just not seeing the methods for the actual action.&lt;/P&gt;</description>
      <pubDate>Tue, 11 Mar 2025 17:16:02 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/clear-2d-measurement-graphics-when-using/m-p/1594365#M86665</guid>
      <dc:creator>LMFGeospatial</dc:creator>
      <dc:date>2025-03-11T17:16:02Z</dc:date>
    </item>
    <item>
      <title>Re: Clear 2D measurement graphics when using components instead of widgets</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/clear-2d-measurement-graphics-when-using/m-p/1595276#M86683</link>
      <description>&lt;P&gt;For 2D widgets it used to be distanceMeasurement2D.viewModel.start() and distanceMeasurement2D.viewModel.clear()&lt;/P&gt;&lt;P&gt;Equivalent web components do not have these methods or the viewModel exposed. I think it's best to use widgets in this case. These specific web components use widgets behind the scenes anyway.&lt;/P&gt;&lt;P&gt;If you are interested, you can see current (4.32) web component implementation for Distance Measurement 2D here:&amp;nbsp;&lt;A href="https://js.arcgis.com/map-components/4.32/6XQYH356.js" target="_blank"&gt;js.arcgis.com/map-components/4.32/6XQYH356.js&lt;/A&gt;&lt;/P&gt;&lt;P&gt;Note that it imports the widget from widgets/DistanceMeasurement2D. The component has this.widget.viewModel in it, but it is not exposed as an external attribute that you could change/read.&lt;/P&gt;</description>
      <pubDate>Thu, 13 Mar 2025 17:18:24 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/clear-2d-measurement-graphics-when-using/m-p/1595276#M86683</guid>
      <dc:creator>Edvinas_S</dc:creator>
      <dc:date>2025-03-13T17:18:24Z</dc:date>
    </item>
    <item>
      <title>Re: Clear 2D measurement graphics when using components instead of widgets</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/clear-2d-measurement-graphics-when-using/m-p/1595480#M86690</link>
      <description>&lt;P&gt;Thank you for responding. Though I am not inclined to use a widget when - it would seem - it should be unnecessary. I have already worked through migrating 4.22 widgets to 4.32 components, and in every single instance I was successful - except for this situation. I find it strange that in the 3D measurement component example, both &lt;STRONG&gt;clear&lt;/STRONG&gt; and &lt;STRONG&gt;start&lt;/STRONG&gt; methods are exposed. And they work as expected:&lt;/P&gt;&lt;P&gt;&lt;A href="https://developers.arcgis.com/javascript/latest/sample-code/sandbox/?sample=measurement-3d" target="_self"&gt;https://developers.arcgis.com/javascript/latest/sample-code/sandbox/?sample=measurement-3d&lt;/A&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Moreover, check out the 2D measurement component Demo:&lt;/P&gt;&lt;P&gt;&lt;A href="https://developers.arcgis.com/javascript/latest/storybook/map-components/iframe.html?singleStory=true&amp;amp;globals=&amp;amp;id=arcgis-distance-measurement-2d--demo&amp;amp;viewMode=story" target="_self"&gt;https://developers.arcgis.com/javascript/latest/storybook/map-components/iframe.html?singleStory=true&amp;amp;globals=&amp;amp;id=arcgis-distance-measurement-2d--demo&amp;amp;viewMode=story&lt;/A&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Each click of the &lt;STRONG&gt;New measurement&lt;/STRONG&gt; button clears the first measurement graphic, allowing the user to start a new measurement. In my case, I'd like to fire the same action as that button - at least in so far as clearing the graphics. If I could see how &lt;EM&gt;that&lt;/EM&gt; action is carried out with the push of the &lt;STRONG&gt;New measurement&lt;/STRONG&gt; button, I could easily enough set up my calcite button to clear those same graphics.&lt;/P&gt;&lt;P&gt;It seems odd that &lt;STRONG&gt;clear&lt;/STRONG&gt; and &lt;STRONG&gt;start&lt;/STRONG&gt; methods would exist for 3D measurement but not 2D measurement.&lt;/P&gt;</description>
      <pubDate>Fri, 14 Mar 2025 01:38:00 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/clear-2d-measurement-graphics-when-using/m-p/1595480#M86690</guid>
      <dc:creator>LMFGeospatial</dc:creator>
      <dc:date>2025-03-14T01:38:00Z</dc:date>
    </item>
    <item>
      <title>Re: Clear 2D measurement graphics when using components instead of widgets</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/clear-2d-measurement-graphics-when-using/m-p/1595532#M86692</link>
      <description>&lt;P&gt;It should be there, but I think they just forgot to expose those methods. The reason they exist in 3D components is probably because those were used in live demos, so they got more attention.&lt;/P&gt;&lt;P&gt;Anyway, here is a workaround. Get a reference to the loaded component and access viewModel via _store&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;const arcgisMeasure = document.querySelector("arcgis-distance-measurement-2d");
arcgisMeasure.addEventListener("arcgisReady", (event) =&amp;gt; {
    event.target._store.viewModel.start()
    // this also works
    // arcgisMeasure._store.viewModel.start()

    // clearing
    // event.target._store.viewModel.clear()
})&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This automatically starts drawing when component is loaded. viewModel doesn't exist before component fully loads.&lt;/P&gt;</description>
      <pubDate>Fri, 14 Mar 2025 09:54:11 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/clear-2d-measurement-graphics-when-using/m-p/1595532#M86692</guid>
      <dc:creator>Edvinas_S</dc:creator>
      <dc:date>2025-03-14T09:54:11Z</dc:date>
    </item>
    <item>
      <title>Re: Clear 2D measurement graphics when using components instead of widgets</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/clear-2d-measurement-graphics-when-using/m-p/1595796#M86701</link>
      <description>&lt;P&gt;I appreciate the tip. Unfortunately, I have not been able to get the result I'm looking for. Not certain if I have your code in the right place or not. Honestly, it&amp;nbsp;would be infinitely easier and more elegant if Esri simply exposed the &lt;STRONG&gt;clear&amp;nbsp;&lt;/STRONG&gt;and&amp;nbsp;&lt;STRONG&gt;start&lt;/STRONG&gt; methods for 2D measurement. In the 3D sample code sandbox, I've actually tested these methods successfully. I grouped the measurement tools together with a calcite-button into the &amp;lt;arcgis-placement&amp;gt; component:&lt;/P&gt;&lt;LI-CODE lang="c"&gt;&amp;lt;arcgis-placement position="top-right"&amp;gt;
      &amp;lt;arcgis-expand id="expand-line" position="top-right" group="top-right"&amp;gt;
        &amp;lt;arcgis-directline-measurement-3d&amp;gt;
        &amp;lt;/arcgis-directline-measurement-3d&amp;gt;
      &amp;lt;/arcgis-expand&amp;gt;
      &amp;lt;arcgis-expand id="expand-area" position="top-right" group="top-right"&amp;gt;
        &amp;lt;arcgis-area-measurement-3d&amp;gt;
        &amp;lt;/arcgis-area-measurement-3d&amp;gt;
      &amp;lt;/arcgis-expand&amp;gt;
      &amp;lt;calcite-button icon-start="trash"&amp;gt;&amp;lt;/calcite-button&amp;gt;
&amp;lt;/arcgis-placement&amp;gt;&lt;/LI-CODE&gt;&lt;P&gt;Then I added a very simple event listener within the arcScene.arcgisViewReadyChange even listener. Works like a charm - I can clear both linear and area measurements with the click of my calcite-button:&lt;/P&gt;&lt;LI-CODE lang="c"&gt;arcgisScene.addEventListener("arcgisViewReadyChange", () =&amp;gt; {
    trash.addEventListener("click", () =&amp;gt; {
        // If I want to clear only on a specific state
        /*if(areaMeasurement3d.state == "measured") {
            areaMeasurement3d.clear();
        }*/
     directlineMeasurement3d.clear();
     areaMeasurement3d.clear();
});&lt;/LI-CODE&gt;&lt;P&gt;Hopefully those methods get exposed for 2D - and &lt;EM&gt;before&lt;/EM&gt; SDK v4.33 is release (~June 2025)&lt;/P&gt;</description>
      <pubDate>Sat, 15 Mar 2025 02:46:02 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/clear-2d-measurement-graphics-when-using/m-p/1595796#M86701</guid>
      <dc:creator>LMFGeospatial</dc:creator>
      <dc:date>2025-03-15T02:46:02Z</dc:date>
    </item>
    <item>
      <title>Re: Clear 2D measurement graphics when using components instead of widgets</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/clear-2d-measurement-graphics-when-using/m-p/1595847#M86702</link>
      <description>&lt;P&gt;Thank you again &lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/413145"&gt;@Edvinas_S&lt;/a&gt; - you definitely helped get me on my way. I additionally want to thank a Penn State University instructor - Jim Detwiler - who taught me web mapping some years ago (and still proves to be a valuable resource when I am stuck). These users' insights helped immensely, as did this Esri page regarding watching for component changes:&lt;/P&gt;&lt;P&gt;&lt;A href="https://developers.arcgis.com/javascript/latest/watch-for-changes/" target="_self"&gt;https://developers.arcgis.com/javascript/latest/watch-for-changes/&lt;/A&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;There is in fact a specific example of the 2D measurement tool. Ultimately, I look for any property change in the tool's state. Once that happens - eg. with a push of the 'New measurement' button - the state will change ("measuring", "measured", etc.). Regardless, as soon as that happens, I can set an EventListener on my calcite-button that allows me to clear the measurement graphics:&lt;/P&gt;&lt;LI-CODE lang="c"&gt;// ****** MEASUREMENT TOOLS ******
	const expandMeasurement_line = document.getElementById("line-measure");
	const expandMeasurement_area = document.getElementById("area-measure");
	const measureLine = document.querySelector("arcgis-distance-measurement-2d");
	const measureArea = document.querySelector("arcgis-area-measurement-2d");
	const trashCan = document.querySelector("calcite-button");

	measureLine.addEventListener("arcgisPropertyChange", (e) =&amp;gt; {
		if (e.detail.name === "state") {
			console.log("Measurement state:", e.target[e.detail.name]);
			trashCan.addEventListener("click", () =&amp;gt;  {
				e.target._store.viewModel.clear();
				if (expandMeasurement_line.expanded === true) {
					expandMeasurement_line.collapse();
				}
			});
		}
	});

	measureArea.addEventListener("arcgisPropertyChange", (e) =&amp;gt; {
		if (e.detail.name === "state") {
			console.log("Measurement state:", e.target[e.detail.name]);
			trashCan.addEventListener("click", () =&amp;gt;  {
				e.target._store.viewModel.clear();
				if (expandMeasurement_area.expanded === true) {
					expandMeasurement_area.collapse();
				}
			});
		}
	});
	// ****** MEASUREMENT TOOLS ******&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;Until the &lt;STRONG&gt;clear&lt;/STRONG&gt; and&amp;nbsp;&lt;STRONG&gt;start&lt;/STRONG&gt; methods are exposed for 2D measurement as they are with 3D measurement, this should do the trick.&lt;/P&gt;</description>
      <pubDate>Sat, 15 Mar 2025 19:07:44 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/clear-2d-measurement-graphics-when-using/m-p/1595847#M86702</guid>
      <dc:creator>LMFGeospatial</dc:creator>
      <dc:date>2025-03-15T19:07:44Z</dc:date>
    </item>
    <item>
      <title>Re: Clear 2D measurement graphics when using components instead of widgets</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/clear-2d-measurement-graphics-when-using/m-p/1596677#M86726</link>
      <description>&lt;P&gt;Thank you so much for sharing this conversation&amp;nbsp;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/886030"&gt;@LMFGeospatial&lt;/a&gt;&amp;nbsp;and&amp;nbsp;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/413145"&gt;@Edvinas_S&lt;/a&gt;. We are looking at enhancing the 2D measurement components for this workflow.&lt;/P&gt;</description>
      <pubDate>Tue, 18 Mar 2025 17:23:50 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/clear-2d-measurement-graphics-when-using/m-p/1596677#M86726</guid>
      <dc:creator>Noah-Sager</dc:creator>
      <dc:date>2025-03-18T17:23:50Z</dc:date>
    </item>
    <item>
      <title>Re: Clear 2D measurement graphics when using components instead of widgets</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/clear-2d-measurement-graphics-when-using/m-p/1597373#M86734</link>
      <description>&lt;P&gt;Excellent, &lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/169842"&gt;@Noah-Sager&lt;/a&gt; - looking forward to the enhancement.&lt;/P&gt;</description>
      <pubDate>Thu, 20 Mar 2025 01:28:06 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/clear-2d-measurement-graphics-when-using/m-p/1597373#M86734</guid>
      <dc:creator>LMFGeospatial</dc:creator>
      <dc:date>2025-03-20T01:28:06Z</dc:date>
    </item>
    <item>
      <title>Re: Clear 2D measurement graphics when using components instead of widgets</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/clear-2d-measurement-graphics-when-using/m-p/1665554#M87857</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/169842"&gt;@Noah-Sager&lt;/a&gt;.&amp;nbsp; I noticed that clear and start are now exposed with the 2D measurement components in the newest release of the SDK.&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I’m working in a React application and want to know the correct way to call this method. Here’s what I’ve tried so far:&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;I am listening for the &lt;STRONG&gt;arcgisPropertyChange&lt;/STRONG&gt; event.&lt;/LI&gt;&lt;LI&gt;When triggered, I use a ref for the measurement component and call &lt;STRONG&gt;ref.current.clear()&lt;/STRONG&gt;.&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;However, I get the error:&amp;nbsp;clear is not a function&lt;/P&gt;&lt;P&gt;Is there a recommended pattern for invoking &lt;STRONG&gt;clear()&lt;/STRONG&gt;?&lt;/P&gt;&lt;P&gt;Any examples or best practices would be greatly appreciated!&lt;/P&gt;</description>
      <pubDate>Thu, 13 Nov 2025 16:58:00 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/clear-2d-measurement-graphics-when-using/m-p/1665554#M87857</guid>
      <dc:creator>EricErtl</dc:creator>
      <dc:date>2025-11-13T16:58:00Z</dc:date>
    </item>
    <item>
      <title>Re: Clear 2D measurement graphics when using components instead of widgets</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/clear-2d-measurement-graphics-when-using/m-p/1665766#M87865</link>
      <description>&lt;P&gt;Try debugging and see if ref.current is loaded and has the object you expect. Also check if you are actually importing the latest version of components library. If you copy pasted some older code, you might still be using an older one.&lt;/P&gt;&lt;P&gt;In js playground, .clear method works fine:&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;&amp;lt;!doctype html&amp;gt;
&amp;lt;html lang="en"&amp;gt;
  &amp;lt;head&amp;gt;
    &amp;lt;meta charset="utf-8" /&amp;gt;
    &amp;lt;meta name="viewport" content="initial-scale=1, maximum-scale=1,user-scalable=no" /&amp;gt;
    &amp;lt;title&amp;gt;Basemap Gallery component | Sample | ArcGIS Maps SDK for JavaScript&amp;lt;/title&amp;gt;

    &amp;lt;!-- Load Calcite components from CDN --&amp;gt;
    &amp;lt;script type="module" src="https://js.arcgis.com/calcite-components/3.3.3/calcite.esm.js"&amp;gt;&amp;lt;/script&amp;gt;

    &amp;lt;!-- Load the ArcGIS Maps SDK for JavaScript from CDN --&amp;gt;
    &amp;lt;script src="https://js.arcgis.com/4.34/"&amp;gt;&amp;lt;/script&amp;gt;

    &amp;lt;!-- Load Map components from CDN--&amp;gt;
    &amp;lt;script type="module" src="https://js.arcgis.com/4.34/map-components/"&amp;gt;&amp;lt;/script&amp;gt;
    &amp;lt;script type="module"&amp;gt;
      const measureLine = document.querySelector("arcgis-distance-measurement-2d");
      const clearButton = document.querySelector("calcite-button");
      clearButton.addEventListener("click", () =&amp;gt;  {
				measureLine.clear();
			});
    &amp;lt;/script&amp;gt;

    &amp;lt;style&amp;gt;
      html,
      body {
        margin: 0;
        height: 100%;
      }
    &amp;lt;/style&amp;gt;
  &amp;lt;/head&amp;gt;

  &amp;lt;body&amp;gt;
    &amp;lt;arcgis-map
      basemap="topo"
      camera-position="-74.034237, 40.691732, 1620"
      camera-tilt="57"
      camera-heading="57"&amp;gt;
      &amp;lt;arcgis-zoom slot="top-left"&amp;gt;&amp;lt;/arcgis-zoom&amp;gt;
      
      &amp;lt;arcgis-distance-measurement-2d slot="top-right"&amp;gt;&amp;lt;/arcgis-distance-measurement-2d&amp;gt;
        &amp;lt;calcite-button slot="bottom-right"&amp;gt;Clear measurement&amp;lt;/calcite-button&amp;gt;
    &amp;lt;/arcgis-map&amp;gt;
  &amp;lt;/body&amp;gt;
&amp;lt;/html&amp;gt;&lt;/LI-CODE&gt;</description>
      <pubDate>Fri, 14 Nov 2025 07:27:47 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/clear-2d-measurement-graphics-when-using/m-p/1665766#M87865</guid>
      <dc:creator>Edvinas_S</dc:creator>
      <dc:date>2025-11-14T07:27:47Z</dc:date>
    </item>
    <item>
      <title>Re: Clear 2D measurement graphics when using components instead of widgets</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/clear-2d-measurement-graphics-when-using/m-p/1665887#M87869</link>
      <description>&lt;P&gt;Nice, thanks for sharing that&amp;nbsp;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/413145"&gt;@Edvinas_S&lt;/a&gt;! You beat me to it.&lt;/P&gt;&lt;P&gt;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/75713"&gt;@EricErtl&lt;/a&gt;&amp;nbsp;maybe you were doing what I was doing with watching the&amp;nbsp;&lt;STRONG&gt;arcgisPropertyChange&lt;/STRONG&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;event. I'm not sure if you need that as part of your workflow, or if the clear button approach works. But let us know as there may be more room for improvements with events etc. and components.&lt;/P&gt;</description>
      <pubDate>Fri, 14 Nov 2025 16:10:29 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/clear-2d-measurement-graphics-when-using/m-p/1665887#M87869</guid>
      <dc:creator>Noah-Sager</dc:creator>
      <dc:date>2025-11-14T16:10:29Z</dc:date>
    </item>
  </channel>
</rss>

