AnsweredAssumed Answered

Updates Graphics(graphicsLayer) to Feature Layer use ApplyEdits

Question asked by vakhtang_zuba on Jan 24, 2020
Latest reply on Jan 29, 2020 by vakhtang_zuba

Hi all,

Robert Scheitlin, GISP, Ken Buja


I have web map with editable featureLayer. After click on my feature i get atrributes (using hitTest), and after click button "Query" query result displays as graphicsLayer and after another click graphic adds to graphicLayer. Idea of doing that is to merge several features in to one feature and update featreLayer after click on button.

Now after click button "Update" i want to update graphicLayer features in my featureLayer, but it does not update.

I paste full code to show how it  is done:


<!DOCTYPE html>
  <meta charset="utf-8">
  <meta name="viewport" content="initial-scale=1,maximum-scale=1,user-scalable=no">
  <title>GWP - მილი და სამისამართო ერთეული</title>

    #viewDiv {
      padding: 0;
      margin: 0;
      height: 100%;
      width: 100%;
<link rel="stylesheet" href="">
<link rel="stylesheet" href="" />
<link rel="stylesheet" href="">
<script src=""></script>
<script src=""></script>
<script src=""></script>
    ], function(
      Map, ScaleBar, Home, Compass, BasemapToggle, SimpleMarkerSymbol, SimpleFillSymbol, SimpleLineSymbol, UniqueValueRenderer, QueryTask, Query, BasemapToggle, DistanceMeasurement2D,
        AreaMeasurement2D, ScaleBar, Home, Compass, MapView,Legend, Expand, GroupLayer, MapImageLayer,
        on, dom, domConstruct
    ) {
      let editFeature, highlight;

      var fLpolygonSymbol = {
        type: "simple-fill", // autocasts as new SimpleFillSymbol()
        color: "yellow",
        style: "solid",
        outline: {
          color: "red",
          width: 1

      const featureLayer = new FeatureLayer({
          outFields: ["*"],
          popupEnabled: false,
          id: "incidentsLayer",  
          listMode: "hide",
          legendEnabled: false
        // GraphicsLayer to hold graphics created via sketch view model
      const graphicsLayer = new GraphicsLayer({
        id: "tempGraphics",
        listMode: "hide"
    const labelClass = {
          // autocasts as new LabelClass()
          symbol: {
            type: "text", // autocasts as new TextSymbol()
            color: "black",
            haloColor: "black",
            font: {
              // autocast as new Font()
              family: "sans-serif",
              size: 8,
              weight: "bold"
          labelPlacement: "center-along",
          labelExpressionInfo: {
          expression: "$feature.g_dasaxeleba_ka"

      var renderer = {
        type: "simple", // autocasts as new SimpleRenderer()
             symbol: {
                 type: "simple-fill", // autocasts as new SimpleFillSymbol()
                 style: "none",
              outline: {
      // makes the outlines of all features consistently light gray
      color: "grey",
      width: 0.5
layer2popup =  {
      title: "ქუჩა",
      content: [{
         type: "fields",
         fieldInfos: [{
           fieldName: "g_dasaxeleba_ka",
            label: "ქუჩის დასახელება",
           visible: true
          fieldName: "SE_ID_new",
            label: "SE ID new",
           visible: true
          fieldName: "zd_donis_ID",
            label: "ზედა ზონის ID",
           visible: true

      var layer2 = new FeatureLayer({
        url: "http://localhost:6080/arcgis/rest/services/test/Tbilisi_wyalmomarageba_vaxo/MapServer/15",
        title: "სამისამართო ერთეული",
        popupTemplate: layer2popup,
        popupEnabled: false,
        outFields: ["*"],
        labelingInfo: [labelClass],
        renderer: renderer
       //saZiebo sistema
        var HWUrl =       "";
        // magistraluri arxi
        var HWLayer = new FeatureLayer({
          url: HWUrl,
          outFields: ["*"],
          visible: false
        // GraphicsLayer for displaying results
        var resultsLayer = new GraphicsLayer({
          title: "ძიების რეზულტატი"  

      var map = new Map({
        basemap: "osm",
        layers: [layer2, featureLayer, graphicsLayer]

      var view = new MapView({
        container: "viewDiv",
        map: map,
        center: [44.7502, 41.725524],
          zoom: 12,
          highlightOptions: {
            color: "red"
       // Double-Click-ზე Zoom შეჩერება
      view.on("double-click", function(evt) {
       // Add a basemap toggle widget to toggle between basemaps
       var toggle = new BasemapToggle({
            titleVisible: true,
            view: view,
            nextBasemap: "satellite"
        // Toggle რუკისთვის
        view.ui.add(toggle, "top-left");
  // Click-ზე graphicsLayer შექმნა და მისი რუკაზე დამატება

        view.on("click", function (event) {
               // Search for graphics at the clicked location. View events can be used
                // as screen locations as they expose an x,y coordinate that conforms
               // to the ScreenPoint definition.
               view.hitTest(event).then(function (response) {
                 if (response.results.length) {
                 var graphic = response.results.filter(function (result) {
                    // check if the graphic belongs to the layer of interest
                         return result.graphic.layer === layer2;

                var attributes = graphic.attributes;
                var name = attributes.g_dasaxeleba_ka;
                var SE_ID = attributes.SE_ID_new;
          var queryZebna = dom.byId("query-Zebna");
          on(queryZebna, "click", function() {
        function queryMagistraluri() {
        var query = HWLayer.createQuery();
         //query.returnGeometry = true;
         //query.outFields = ["*"];
         query.where = "g_dasaxeleba_ka LIKE N'%"+ name +"%'";
         query.outSpatialReference = view.spatialReference;                                                        
         return HWLayer.queryFeatures(query)
        // display the query results in the view    
        function displayResults(results) {       
          var pfeatures = {
            graphica.symbol = {
              type: "simple-fill",  // autocasts as new SimpleFillSymbol()
                 color: "orange",
                    style: "solid",
                    outline: {  // autocasts as new SimpleLineSymbol()
                    color: "black",
                       width: 1
            return graphica 
        const btnupdate = dom.byId("button-update");
        on(btnupdate, "click", function () {
          // Create a new graphic and set its geometry to
          function addGraphic(event) {
          // Create a new graphic and set its geometry to
          // `create-complete` event geometry.
          const graphic = new Graphic({
            geometry: polygon,
            symbol: graphica.symbol,
            attributes: {}

               const edits = { //Fire the addFeatures function using the completed graphic
              addFeatures: [graphic]
        function applyEdits(params) {
          featureLayer.applyEdits(params).then(function(editsResult) {
            // Get the objectId of the newly added feature.
            // Call selectFeature function to highlight the new feature.
            if (editsResult.addFeatureResults.length > 0) {
              const objectId = editsResult.addFeatureResults[0].objectId;
          .catch(function(error) {
            console.error("[ applyEdits ] FAILURE: ", error.code,,
            console.log("error = ", error);
  <button id="query-Zebna">ძებნა</button>
  <button id="button-update">Update</button>
  <div id="viewDiv"></div>