简体   繁体   中英

How to get graphics points after draw using arcgis api

I want to get Polygon Points, lines points in order to store them in a database. I am using arcgis api 3.26 and i am wondering how can i get the points. here is how i draw graphics

// markerSymbol is used for point and multipoint, see http://raphaeljs.com/icons/#talkq for more examples
    var markerSymbol = new SimpleMarkerSymbol();
    markerSymbol.setPath("M16,4.938c-7.732,0-14,4.701-14,10.5c0,1.981,0.741,3.833,2.016,5.414L2,25.272l5.613-1.44c2.339,1.316,5.237,2.106,8.387,2.106c7.732,0,14-4.701,14-10.5S23.732,4.938,16,4.938zM16.868,21.375h-1.969v-1.889h1.969V21.375zM16.772,18.094h-1.777l-0.176-8.083h2.113L16.772,18.094z");
    markerSymbol.setColor(new Color("#00FFFF"));

    // lineSymbol used for freehand polyline, polyline and line. 
    var lineSymbol = new CartographicLineSymbol(
      CartographicLineSymbol.STYLE_SOLID,
      new Color([255,0,0]), 10, 
      CartographicLineSymbol.CAP_ROUND,
      CartographicLineSymbol.JOIN_MITER, 5
    );

    // fill symbol used for extent, polygon and freehand polygon, use a picture fill symbol
    // the images folder contains additional fill images
    var fillSymbol = new PictureFillSymbol(
      new SimpleLineSymbol(
        SimpleLineSymbol.STYLE_SOLID,
        new Color('#000'), 
        1
      ), 
      42, 
      42
    );

I can display graphic using this function addGraphics

      // figure out which symbol to use
      var symbol;
      if ( evt.geometry.type === "point" || evt.geometry.type === "multipoint") {
        symbol = markerSymbol;
        //alert(markerSymbol.xoffset);
      } else if ( evt.geometry.type === "line" || evt.geometry.type === "polyline") {
        symbol = lineSymbol;
        //alert(lineSymbol.toJson());
      }
      else {
        symbol = fillSymbol;
        alert(fillSymbol);
      }

      map.graphics.add(new Graphic(evt.geometry, symbol));
      alert("X: " + evt.mapPoint.x.toString() + ", <br>Y: " + evt.mapPoint.y.toString());

    }

You can get the points from evt.geometry properties :

For point: evt.geometry.x and evt.geometry.y

For multipoint : evt.geometry.points returns an array points https://developers.arcgis.com/javascript/3/jsapi/multipoint-amd.html#points

For polyline : evt.geometry.path returns an array of paths, which contain an array of points https://developers.arcgis.com/javascript/3/jsapi/polyline-amd.html#paths

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM