AnsweredAssumed Answered

Union only working on second draw extent

Question asked by alex.gole_ELDORADOCOUNTY on Nov 10, 2016
Latest reply on Nov 10, 2016 by alex.gole_ELDORADOCOUNTY

Hi all,

I am using geometry service's union to dissolve polygons. It works great. However, I cannot figure out why on my first draw-end my featurelayer selection is done but not the union. If I draw a second extent then it works. not too sure what I am missing here. Thanks,

Alex

 

here is my code:

 <script>
        var map;

        require([
          "esri/InfoTemplate",
          "esri/map",
          "esri/layers/FeatureLayer",
          "esri/symbols/SimpleFillSymbol",
          "esri/symbols/SimpleLineSymbol",
          "esri/tasks/query",
          "esri/toolbars/draw",
          "esri/tasks/GeometryService",
          "esri/dijit/editing/Union",
          "esri/graphic",
          "esri/graphicsUtils",
          "dojo/dom",
          "dojo/on",
          "dojo/parser",
          "dojo/_base/array",
          "esri/Color",
          "dojo/domReady!"
        ],
          function (
            InfoTemplate, Map, FeatureLayer, SimpleFillSymbol, SimpleLineSymbol,
            Query, Draw, GeometryService, Union, Graphic, graphicsUtils, dom, on, parser, arrayUtil, Color
          ) {

              parser.parse();


             

              var selectionToolbar, featureLayer;


              map = new Map("map", {
                  basemap: "streets",
                  center: [-97.395, 37.537],
                  zoom: 11
              });

              map.on("load", initSelectToolbar);

              var fieldsSelectionSymbol =
                new SimpleFillSymbol(SimpleFillSymbol.STYLE_SOLID,
                  new SimpleLineSymbol(SimpleLineSymbol.STYLE_DASHDOT,
                new Color([255, 0, 0]), 2), new Color([255, 255, 0, 0.5]));


              featureLayer = new FeatureLayer("https://sampleserver3.arcgisonline.com/ArcGIS/rest/services/Petroleum/KSPetro/MapServer/1",
                {
                    mode: FeatureLayer.MODE_SNAPSHOT
                });
              featureLayer.setSelectionSymbol(fieldsSelectionSymbol);
              map.addLayer(featureLayer);

              $("#selectFieldsButton").click(function () {
                  selectionToolbar.activate(Draw.EXTENT);
              });

              function initSelectToolbar(event) {
                  console.log("start edits");
                  selectionToolbar = new Draw(event.map);
                  var selectQuery = new Query();
                 
                  on(selectionToolbar, "DrawEnd", function (geometry) {
                      var geometryService = new GeometryService("http://itas46:6080/arcgis/rest/services/Utilities/Geometry/GeometryServer");
                      selectQuery.geometry = geometry;
                      featureLayer.selectFeatures(selectQuery, FeatureLayer.SELECTION_NEW);
                      var targetGeometry = graphicsUtils.getGeometries(featureLayer.getSelectedFeatures());
                      console.log(targetGeometry);
                      geometryService.union(targetGeometry, function (geometry) {
                          featureLayer.clearSelection();
                          var symbol = new SimpleFillSymbol("none", new SimpleLineSymbol("solid", new Color([255, 255, 255]), 2), new Color([255, 255, 255, 0.25]));
                          var graphic = new Graphic(geometry, symbol);
                          map.graphics.add(graphic);
                          console.log(targetGeometry);
                      });

                  });

              }
          });
    </script>

 Thanks

Outcomes