Select to view content in your preferred language

How to Get Polygon Graphic UID

352
0
07-11-2023 06:13 AM
SaihaniIdaffieSaidin
New Contributor II

Hello can you guys help me with this problem
I got some problems that I cant get the polygon graphic uid
I want to set attributes for the textsymbol with it get the id from the polygon graphic uid
Here the coding:

          if (graphic['geometry'].type == 'polygon') {
            const rings = graphic['geometry'].rings;
            const polygon = new Polygon({
              hasZ: true,
              hasM: true,
              rings: rings,
              spatialReference: graphic['geometry'].spatialReference
            });

            const fillSymbol = {
              type: "simple-fill", // autocasts as new SimpleFillSymbol()
              color: [0, 0, 0, 0.1],
              style: 'solid',
              outline: {
                color: 'red',
                width: 2
              }
            };

            // Add the geometry and symbol to a new graphic
            const polygonGraphic = new Graphic({
              geometry: polygon,
              symbol: fillSymbol,
              attributes: lineAtt,
              popupTemplate: popup
            });

            // Add text symbol
            const textSymbol = new TextSymbol({
              text: graphic['attributes'].name, // or any other attribute you want to display as text
              color: 'red',
              font: {
                family: 'Arial Unicode MS',
                size: 15
              },
            });

            const point = new Point({
              longitude: graphic['attributes'].centroid.x,
              latitude: graphic['attributes'].centroid.y
            })

            const textGraphic = new Graphic({
              geometry: point,
              symbol: textSymbol,
              attributes: {
                // id: polygonGraphic.uid // Use the UID of polygonGraphic as the value for the 'id' attribute
              }
            });

            this.graphicsLayerPolyNaiTai.add(polygonGraphic);
            this.graphicsLayerNaiTai.add(textGraphic);

          }

I try to get it polygonGraphic.uid but it get error on the uid
hope you guys can help me with it
0 Kudos
0 Replies