<?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: Sketch Widget keep Tooltip after graphic is created in ArcGIS JavaScript Maps SDK Questions</title>
    <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/sketch-widget-keep-tooltip-after-graphic-is/m-p/1477463#M84696</link>
    <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;here is our workaround:&lt;/P&gt;&lt;OL&gt;&lt;LI&gt;create new GraphicLayer for text symbols&lt;/LI&gt;&lt;LI&gt;catch the following events: "create":&amp;nbsp;&lt;SPAN&gt;ev&lt;/SPAN&gt;&lt;SPAN&gt;.&lt;/SPAN&gt;&lt;SPAN&gt;state&lt;/SPAN&gt; &lt;SPAN&gt;===&lt;/SPAN&gt; &lt;SPAN&gt;"complete"&lt;/SPAN&gt; &lt;SPAN&gt;||&lt;/SPAN&gt; &lt;SPAN&gt;ev&lt;/SPAN&gt;&lt;SPAN&gt;.&lt;/SPAN&gt;&lt;SPAN&gt;state&lt;/SPAN&gt; &lt;SPAN&gt;===&lt;/SPAN&gt; &lt;SPAN&gt;"cancel",&amp;nbsp;&lt;/SPAN&gt;"update"&amp;nbsp;&lt;SPAN&gt;ev&lt;/SPAN&gt;&lt;SPAN&gt;.&lt;/SPAN&gt;&lt;SPAN&gt;state&lt;/SPAN&gt; &lt;SPAN&gt;===&lt;/SPAN&gt; &lt;SPAN&gt;"active",&amp;nbsp;&lt;/SPAN&gt;"undo", "redo", "delete"&lt;/LI&gt;&lt;LI&gt;in event callback remove all graphics from text symbol layer and create every text symbol for all graphics in sketch graphic layer&lt;/LI&gt;&lt;/OL&gt;&lt;P&gt;3 can be achieved with this code:&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;const textLayer = new GraphicsLayer({
	id: "sketch1",
	title: "text symbols",
	internal: true,
});

export const defaultTextSymbol = {
	type: "text", // autocasts as new TextSymbol()
	color: "white",
	haloColor: "black",
	haloSize: "1px",
	font: {
		size: 10,
		weight: "bold",
	},
};

const drawLabel = (text, labelAnchor, symbolProps = null) =&amp;gt; {
	const labelSymbol = { ...defaultTextSymbol, text: text };
	const label = new Graphic({
		geometry: labelAnchor,
		symbol: symbolProps ? { ...labelSymbol, ...symbolProps } : labelSymbol,
	});
	textLayer.graphics.add(label);
};


export const redrawTextLayer = () =&amp;gt; {
	textLayer.graphics.removeAll();
	sketchLayer.graphics.forEach((graphic) =&amp;gt; {
		redrawLabel(graphic);
	});
};


const redrawLabel = (graphic) =&amp;gt; {
	let labelAnchor;
	let geom = graphic.geometry;
	let attr = graphic.attributes;
	if (geom.type === "point") {
		labelAnchor = geom;
	} else if (geom.type === "polyline") {
		labelAnchor = geom.extent.center;
	} else if (geom.type === "polygon") {
		labelAnchor = geom.centroid;
	}

	drawLabel(text, labelAnchor);
};&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 23 May 2024 05:27:11 GMT</pubDate>
    <dc:creator>AndreV</dc:creator>
    <dc:date>2024-05-23T05:27:11Z</dc:date>
    <item>
      <title>Sketch Widget keep Tooltip after graphic is created</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/sketch-widget-keep-tooltip-after-graphic-is/m-p/1477304#M84692</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;I included the sketch widget into my app enabling SketchTooltipOptions.&lt;BR /&gt;The shown label is great. Unfortunately this label will be gone after the graphic is created (doubleclick on last point).&lt;/P&gt;&lt;P&gt;Is it somehow possible to keep this label or to add a custom label to these graphics?&lt;BR /&gt;Until now I only find samples on how to for features but not for graphics on a graphicslayer as the sketch widget produces them.&lt;/P&gt;&lt;P&gt;Hope someone can help me.&lt;/P&gt;</description>
      <pubDate>Wed, 22 May 2024 20:57:32 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/sketch-widget-keep-tooltip-after-graphic-is/m-p/1477304#M84692</guid>
      <dc:creator>SebastianKrings</dc:creator>
      <dc:date>2024-05-22T20:57:32Z</dc:date>
    </item>
    <item>
      <title>Re: Sketch Widget keep Tooltip after graphic is created</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/sketch-widget-keep-tooltip-after-graphic-is/m-p/1477463#M84696</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;here is our workaround:&lt;/P&gt;&lt;OL&gt;&lt;LI&gt;create new GraphicLayer for text symbols&lt;/LI&gt;&lt;LI&gt;catch the following events: "create":&amp;nbsp;&lt;SPAN&gt;ev&lt;/SPAN&gt;&lt;SPAN&gt;.&lt;/SPAN&gt;&lt;SPAN&gt;state&lt;/SPAN&gt; &lt;SPAN&gt;===&lt;/SPAN&gt; &lt;SPAN&gt;"complete"&lt;/SPAN&gt; &lt;SPAN&gt;||&lt;/SPAN&gt; &lt;SPAN&gt;ev&lt;/SPAN&gt;&lt;SPAN&gt;.&lt;/SPAN&gt;&lt;SPAN&gt;state&lt;/SPAN&gt; &lt;SPAN&gt;===&lt;/SPAN&gt; &lt;SPAN&gt;"cancel",&amp;nbsp;&lt;/SPAN&gt;"update"&amp;nbsp;&lt;SPAN&gt;ev&lt;/SPAN&gt;&lt;SPAN&gt;.&lt;/SPAN&gt;&lt;SPAN&gt;state&lt;/SPAN&gt; &lt;SPAN&gt;===&lt;/SPAN&gt; &lt;SPAN&gt;"active",&amp;nbsp;&lt;/SPAN&gt;"undo", "redo", "delete"&lt;/LI&gt;&lt;LI&gt;in event callback remove all graphics from text symbol layer and create every text symbol for all graphics in sketch graphic layer&lt;/LI&gt;&lt;/OL&gt;&lt;P&gt;3 can be achieved with this code:&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;const textLayer = new GraphicsLayer({
	id: "sketch1",
	title: "text symbols",
	internal: true,
});

export const defaultTextSymbol = {
	type: "text", // autocasts as new TextSymbol()
	color: "white",
	haloColor: "black",
	haloSize: "1px",
	font: {
		size: 10,
		weight: "bold",
	},
};

const drawLabel = (text, labelAnchor, symbolProps = null) =&amp;gt; {
	const labelSymbol = { ...defaultTextSymbol, text: text };
	const label = new Graphic({
		geometry: labelAnchor,
		symbol: symbolProps ? { ...labelSymbol, ...symbolProps } : labelSymbol,
	});
	textLayer.graphics.add(label);
};


export const redrawTextLayer = () =&amp;gt; {
	textLayer.graphics.removeAll();
	sketchLayer.graphics.forEach((graphic) =&amp;gt; {
		redrawLabel(graphic);
	});
};


const redrawLabel = (graphic) =&amp;gt; {
	let labelAnchor;
	let geom = graphic.geometry;
	let attr = graphic.attributes;
	if (geom.type === "point") {
		labelAnchor = geom;
	} else if (geom.type === "polyline") {
		labelAnchor = geom.extent.center;
	} else if (geom.type === "polygon") {
		labelAnchor = geom.centroid;
	}

	drawLabel(text, labelAnchor);
};&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 23 May 2024 05:27:11 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/sketch-widget-keep-tooltip-after-graphic-is/m-p/1477463#M84696</guid>
      <dc:creator>AndreV</dc:creator>
      <dc:date>2024-05-23T05:27:11Z</dc:date>
    </item>
    <item>
      <title>Re: Sketch Widget keep Tooltip after graphic is created</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/sketch-widget-keep-tooltip-after-graphic-is/m-p/1477676#M84702</link>
      <description>&lt;BLOCKQUOTE&gt;catch the following events: "create": ev.state === "complete" || ev.state === "cancel", "update" ev.state === "active", "undo", "redo", "delete"&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;Hey AndreV! We're trying to do the same thing as the OP, but when you say the above, is this on the actual Sketch widget instance?&lt;/P&gt;&lt;P&gt;&lt;A href="https://developers.arcgis.com/javascript/latest/api-reference/esri-widgets-Sketch.html#events-summary" target="_blank" rel="noopener"&gt;https://developers.arcgis.com/javascript/latest/api-reference/esri-widgets-Sketch.html#events-summary&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;EDIT&lt;/STRONG&gt;: Also, part of the example you gave doesn't work as text is undefined:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;const redrawLabel = (graphic) =&amp;gt; {
	let labelAnchor;
	let geom = graphic.geometry;
	let attr = graphic.attributes;
	if (geom.type === "point") {
		labelAnchor = geom;
	} else if (geom.type === "polyline") {
		labelAnchor = geom.extent.center;
	} else if (geom.type === "polygon") {
		labelAnchor = geom.centroid;
	}
      // won't work since text is never defined
	drawLabel(text, labelAnchor);
}&lt;/LI-CODE&gt;</description>
      <pubDate>Thu, 23 May 2024 16:51:04 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/sketch-widget-keep-tooltip-after-graphic-is/m-p/1477676#M84702</guid>
      <dc:creator>DavidDrennan</dc:creator>
      <dc:date>2024-05-23T16:51:04Z</dc:date>
    </item>
    <item>
      <title>Re: Sketch Widget keep Tooltip after graphic is created</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/sketch-widget-keep-tooltip-after-graphic-is/m-p/1478211#M84711</link>
      <description>&lt;P&gt;Hi David,&lt;/P&gt;&lt;P&gt;yes we took the events from SketchWidget instance, as you described in your link. Alternatively, there are the same events on the SketchWidgetViewModel&lt;/P&gt;&lt;P&gt;&lt;A href="https://developers.arcgis.com/javascript/latest/api-reference/esri-widgets-Sketch-SketchViewModel.html#events-summary" target="_blank"&gt;https://developers.arcgis.com/javascript/latest/api-reference/esri-widgets-Sketch-SketchViewModel.html#events-summary&lt;/A&gt;&lt;/P&gt;&lt;P&gt;your right, the code snippet I provided, doesn't work from scratch. I took our code and deleted many lines for this post. You can define text by yourself and assign it to graphic's attributes, something like this:&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;const redrawLabel = (graphic) =&amp;gt; {
	let labelAnchor;
	let geom = graphic.geometry;
	let attr = graphic.attributes;
	if (geom.type === "point") {
		labelAnchor = geom;
	} else if (geom.type === "polyline") {
		labelAnchor = geom.extent.center;
	} else if (geom.type === "polygon") {
		labelAnchor = geom.centroid;
	}
        let text = attr.userInputText 
        //or any other attribute you defined and filled in ev.create (ev.state === "complete") 
	drawLabel(text, labelAnchor);
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 24 May 2024 08:47:20 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/sketch-widget-keep-tooltip-after-graphic-is/m-p/1478211#M84711</guid>
      <dc:creator>AndreV</dc:creator>
      <dc:date>2024-05-24T08:47:20Z</dc:date>
    </item>
    <item>
      <title>Re: Sketch Widget keep Tooltip after graphic is created</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/sketch-widget-keep-tooltip-after-graphic-is/m-p/1478223#M84712</link>
      <description>&lt;P&gt;hm unfortunately my reply wasnt sent, but luckily esri drafted it for me.&lt;/P&gt;&lt;P&gt;Heres my original post:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;this is awesome. Thank you very much.&lt;/P&gt;&lt;P&gt;Just did some small changes. Possibly due to api changes of methods one parameter wasnt there any more and may got a default now in the newest api version. I just removed it.&lt;BR /&gt;I also added m&lt;SPAN&gt;ap&lt;/SPAN&gt;&lt;SPAN&gt;.&lt;/SPAN&gt;&lt;SPAN&gt;add&lt;/SPAN&gt;&lt;SPAN&gt;(&lt;/SPAN&gt;&lt;SPAN&gt;textLayer&lt;/SPAN&gt;&lt;SPAN&gt;); to make the lextlayer visible.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;As text of course I put my thing:&lt;/SPAN&gt;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;const length = geometryEngine.geodesicLength(riverGeometry, "miles");&lt;/LI-CODE&gt;</description>
      <pubDate>Fri, 24 May 2024 09:05:26 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/sketch-widget-keep-tooltip-after-graphic-is/m-p/1478223#M84712</guid>
      <dc:creator>SebastianKrings</dc:creator>
      <dc:date>2024-05-24T09:05:26Z</dc:date>
    </item>
  </channel>
</rss>

