Select to view content in your preferred language

graphics Multiple clicks will cause errors

715
4
10-31-2022 01:28 AM
MrLei
by
Emerging Contributor

graphics Multiple clicks will cause errors

Uncaught TypeError: Object.defineProperty called on non-object

leisheng_0-1667204546299.png

 

0 Kudos
4 Replies
JayakumarPD
Frequent Contributor

Is it possible to share the code.  It will be easy to understand

0 Kudos
MrLei
by
Emerging Contributor

Hi  thanks

code

showPopupInfo(data){
      let graphics = this.graphicsLayer.graphics.items
      let graphic = graphics.find(item => item.attributes.id == data.id)
      if(graphic != undefined){
        // .centroid
        this.mapView.popup.open({
               location: this.getCentrePoint(graphic.geometry),
               features: [graphic]
             })

      }else{
        this.ssmap.mapView.popup.close()
      }

    },
getCentrePoint(geometry) {
    if (geometry.type === "polygon") {
      return geometry.centroid;
    }
    if (geometry.type === "polyline") {
      return geometry.extent.center;
    }
    return geometry;
  }
 
The first display is normal
when change show popup or  more click others marker     this error can occur,
 
what's why
 
0 Kudos
JayakumarPD
Frequent Contributor

I am unable to create the exact your use case, but tried with point creation.

Popup is coming with exact latitude and longitude for each point I have clicked.

Screen shot enclosed.

<html>
  <head>
    <meta charset="utf-8" />
    <meta
      name="viewport"
      content="initial-scale=1,maximum-scale=1,user-scalable=no"
    />
    <title>Draw polyline | Sample | ArcGIS API for JavaScript 4.24</title>

    <link
      rel="stylesheet"
      href="https://js.arcgis.com/4.24/esri/themes/light/main.css"
    />
    <script src="https://js.arcgis.com/4.24/"></script>

    <style>
      html,
      body,
      #viewDiv {
        height: 100%;
        width: 100%;
        margin: 0;
        padding: 0;
      }
    </style>
    <script>
      require([
        "esri/Map",
        "esri/views/MapView",
        "esri/views/draw/Draw",
        "esri/Graphic",
        "esri/views/draw/PointDrawAction",
        "esri/widgets/Popup",
      ], (Map, MapView, Draw, Graphic, PointDrawAction, Popup) => {
        const map = new Map({
          basemap: "gray-vector",
        });

        const view = new MapView({
          container: "viewDiv",
          map: map,
          zoom: 15,
          center: [75, 14],
        });

        view.ui.add("point-button", "top-left");

        const draw = new Draw({
          view: view,
        });

        document.getElementById("point-button").onclick = () => {
          const action = draw.create("point");
          view.focus();
          action.on(["draw-complete"], updateVertices);
        };

        function updateVertices(event) {
          if (event.coordinates.length > 1) {
            const result = createGraphic(event);
          }
        }

        function createGraphic(event) {
          let point = {
            type: "point",
            x: event.coordinates[0],
            y: event.coordinates[1],
            spatialReference: view.spatialReference,
          };

          let graphic = new Graphic({
            geometry: point,
            symbol: {
              type: "simple-marker",
              style: "circle",
              color: "red",
              size: "16px",
              outline: {
                color: [255, 255, 0],
                width: 3,
              },
            },
          });
          view.graphics.add(graphic);

          showPopup(graphic);
        }
        function showPopup(graphic) {
          console.log(
            graphic.geometry.latitude + " - " + graphic.geometry.longitude
          );
          view.popup.open({
            location: graphic.geometry,
            content: `<b>latitude: ${graphic.geometry.latitude} <br/> latitude: ${graphic.geometry.longitude}<b>`,
          });
        }
      });
    </script>
  </head>

  <body>
    <div id="viewDiv">
      <div
        id="point-button"
        class="esri-widget esri-widget--button esri-interactive"
        title="Draw Point"
      >
        <span class="esri-icon-map-pin"></span>
      </div>
    </div>
  </body>
</html>

 

MrLei
by
Emerging Contributor

ok  thank you !     

sometimes this happens,I don't know if it is caused by different versions ,I also use new version

0 Kudos