<?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 Putting text on a marker symbol in ArcGIS JavaScript Maps SDK Questions</title>
    <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/putting-text-on-a-marker-symbol/m-p/1054306#M72883</link>
    <description>&lt;P&gt;I'm having trouble putting text on a marker symbol (a simple circle) on maps using the &lt;FONT face="courier new,courier"&gt;@arcgis/core&lt;/FONT&gt;&amp;nbsp;module from npm. What's a simple way to do that? What we used to do with v4.16 via ESRI loader isn't working reliably anymore with v4.19 and the npm module (old and new below). Sometimes the text shows up, other times it doesn't.&lt;/P&gt;&lt;P&gt;Here's our old code using the&amp;nbsp;"ESRI loader" stuff and v4.16. To have text on top of a marker symbol (for instance, a circle), we were adding a circle then adding text:&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;// A worker function we had
function addGraphic(graphicsLayer, graphic, opacity) {
    graphicsLayer.graphics.add(graphic);
    graphic.symbol.color.a = opacity;
    return graphic;
}

// Using it to add a circle and then text
addGraphic(view, new Graphic({
    geometry, // A Point
    symbol: {
        type: "simple-marker",
        style: "circle",
        color: /*...*/,
        size: /*...*/,
        outline: {
            width: 0,
        },
    },
    popupTemplate,
}), 1);
addGraphic(view, new Graphic({
    geometry, // The same Point
    symbol: {
        text: /*...*/,
        type: "text",
        color: "white",
        horizontalAlignment: "center",
        verticalAlignment: "middle",
        font: {
            size: 12,
            weight: "bold",
        }
    },
    popupTemplate,
}), 1);&lt;/LI-CODE&gt;&lt;P&gt;It felt a bit kludgy but worked reliably.&lt;/P&gt;&lt;P&gt;In our newer code using v4.19.1 from npm, we're using TypeScript and imported the constructors and updated the code (minimally) to look like this instead:&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;// The utility function
function addGraphic(graphicsLayer: MapView | GraphicsLayer, graphic: Graphic, opacity?: number) {
    graphicsLayer.graphics.add(graphic);
    if (typeof opacity !== "undefined") {
        graphic.symbol.color.a = opacity;
    }
    return graphic;
}

// Using it
addGraphic(this.view, new Graphic({
    geometry, // A Point
    symbol: new SimpleMarkerSymbol({
        style: "circle",
        color: /*...*/,
        size: /*...*/,
        outline: {
            width: 0,
        },
    }),
    popupTemplate,
}), 1);
addGraphic(this.view, new Graphic({
    geometry, // The same Point
    symbol: new TextSymbol({
        text: /*...*/,
        color: "white",
        horizontalAlignment: "center",
        verticalAlignment: "middle",
        font: {
            size: 12,
            weight: "bold",
        }
    }),
    popupTemplate,
}), 1);&lt;/LI-CODE&gt;&lt;P&gt;As you can see, the only difference in the code is that we're using the constructors (and allowing for the opacity to be left off, but it's included in both of these calls). We switched to using the constructors because the TypeScript types didn't include the &lt;FONT face="courier new,courier"&gt;type&lt;/FONT&gt; property that autocasting (?) uses.&lt;/P&gt;&lt;P&gt;Using the constructors isn't the problem, though -- if I add make TypeScript ignore the error on the&amp;nbsp;&lt;FONT face="courier new,courier"&gt;type&lt;/FONT&gt; property, we get exactly the same result we get with the constructors: The text sometimes appears, other times it doesn't.&lt;/P&gt;&lt;P&gt;It always seemed overcomplicated to add two graphics just to put some text in a circle. Is there a better way to do this, and if not, is there a way to make this more reliable?&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;-- T.J.&lt;/P&gt;</description>
    <pubDate>Tue, 04 May 2021 17:33:47 GMT</pubDate>
    <dc:creator>TJ_Crowder</dc:creator>
    <dc:date>2021-05-04T17:33:47Z</dc:date>
    <item>
      <title>Putting text on a marker symbol</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/putting-text-on-a-marker-symbol/m-p/1054306#M72883</link>
      <description>&lt;P&gt;I'm having trouble putting text on a marker symbol (a simple circle) on maps using the &lt;FONT face="courier new,courier"&gt;@arcgis/core&lt;/FONT&gt;&amp;nbsp;module from npm. What's a simple way to do that? What we used to do with v4.16 via ESRI loader isn't working reliably anymore with v4.19 and the npm module (old and new below). Sometimes the text shows up, other times it doesn't.&lt;/P&gt;&lt;P&gt;Here's our old code using the&amp;nbsp;"ESRI loader" stuff and v4.16. To have text on top of a marker symbol (for instance, a circle), we were adding a circle then adding text:&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;// A worker function we had
function addGraphic(graphicsLayer, graphic, opacity) {
    graphicsLayer.graphics.add(graphic);
    graphic.symbol.color.a = opacity;
    return graphic;
}

// Using it to add a circle and then text
addGraphic(view, new Graphic({
    geometry, // A Point
    symbol: {
        type: "simple-marker",
        style: "circle",
        color: /*...*/,
        size: /*...*/,
        outline: {
            width: 0,
        },
    },
    popupTemplate,
}), 1);
addGraphic(view, new Graphic({
    geometry, // The same Point
    symbol: {
        text: /*...*/,
        type: "text",
        color: "white",
        horizontalAlignment: "center",
        verticalAlignment: "middle",
        font: {
            size: 12,
            weight: "bold",
        }
    },
    popupTemplate,
}), 1);&lt;/LI-CODE&gt;&lt;P&gt;It felt a bit kludgy but worked reliably.&lt;/P&gt;&lt;P&gt;In our newer code using v4.19.1 from npm, we're using TypeScript and imported the constructors and updated the code (minimally) to look like this instead:&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;// The utility function
function addGraphic(graphicsLayer: MapView | GraphicsLayer, graphic: Graphic, opacity?: number) {
    graphicsLayer.graphics.add(graphic);
    if (typeof opacity !== "undefined") {
        graphic.symbol.color.a = opacity;
    }
    return graphic;
}

// Using it
addGraphic(this.view, new Graphic({
    geometry, // A Point
    symbol: new SimpleMarkerSymbol({
        style: "circle",
        color: /*...*/,
        size: /*...*/,
        outline: {
            width: 0,
        },
    }),
    popupTemplate,
}), 1);
addGraphic(this.view, new Graphic({
    geometry, // The same Point
    symbol: new TextSymbol({
        text: /*...*/,
        color: "white",
        horizontalAlignment: "center",
        verticalAlignment: "middle",
        font: {
            size: 12,
            weight: "bold",
        }
    }),
    popupTemplate,
}), 1);&lt;/LI-CODE&gt;&lt;P&gt;As you can see, the only difference in the code is that we're using the constructors (and allowing for the opacity to be left off, but it's included in both of these calls). We switched to using the constructors because the TypeScript types didn't include the &lt;FONT face="courier new,courier"&gt;type&lt;/FONT&gt; property that autocasting (?) uses.&lt;/P&gt;&lt;P&gt;Using the constructors isn't the problem, though -- if I add make TypeScript ignore the error on the&amp;nbsp;&lt;FONT face="courier new,courier"&gt;type&lt;/FONT&gt; property, we get exactly the same result we get with the constructors: The text sometimes appears, other times it doesn't.&lt;/P&gt;&lt;P&gt;It always seemed overcomplicated to add two graphics just to put some text in a circle. Is there a better way to do this, and if not, is there a way to make this more reliable?&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;-- T.J.&lt;/P&gt;</description>
      <pubDate>Tue, 04 May 2021 17:33:47 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/putting-text-on-a-marker-symbol/m-p/1054306#M72883</guid>
      <dc:creator>TJ_Crowder</dc:creator>
      <dc:date>2021-05-04T17:33:47Z</dc:date>
    </item>
  </channel>
</rss>

