AnsweredAssumed Answered

Graphic Is Not Adding to the Exact Snapping Point

Question asked by behClevest on Dec 8, 2017
Latest reply on Dec 8, 2017 by behClevest

Can you please take a look at this demo and let me know why the added graphic to the snapping feature is not exactly added on top of the feature.

Please try the fiddle and add a Point to the map by CTL key . after zooming the graphic you will notice the point is added to position of the cursor instead of Snapped point. 

 

var map;

require(["esri/map",
  "esri/SnappingManager",
  "esri/toolbars/draw",
  "esri/layers/FeatureLayer",
  "esri/graphic",
  "esri/Color",
  "esri/symbols/SimpleMarkerSymbol",
  "esri/symbols/SimpleLineSymbol",
  "esri/symbols/SimpleFillSymbol",
  "dojo/keys",
  "dojo/domReady!"
], function(Map, SnappingManager, Draw, FeatureLayer, Graphic, Color, SimpleMarkerSymbol, SimpleLineSymbol, SimpleFillSymbol, keys) {
  map = new Map("map", {
    basemap: "topo",
    center: [-88.158805, 41.786075],
    zoom: 18
  });
  var sms = new SimpleMarkerSymbol(SimpleMarkerSymbol.STYLE_DIAMOND, 12,
    new SimpleLineSymbol(SimpleLineSymbol.STYLE_SOLID, new Color([70, 0, 130, 1]), 1), new Color([70, 0, 130, 1]));
  var propertyLayer = new FeatureLayer("https://sampleserver6.arcgisonline.com/arcgis/rest/services/CommunityAddressing/FeatureServer/0", {
    mode: FeatureLayer.MODE_ONDEMAND,
    outFields: ["*"]
  });
  map.addLayers([propertyLayer]);

  $("#add").on("click", function() {
    var toolbar = new esri.toolbars.Draw(map);
    toolbar.activate(esri.toolbars.Draw.POINT);
    map.on("click", addGraphic);

    function addGraphic(evt) {
      var graphic = new Graphic(evt.mapPoint, sms);
      map.graphics.add(graphic);
      console.log(evt.mapPoint);
    }

  });


  propertyLayer.on("mouse-over", function(evt) {
    //console.log("Snapped")
  });
  var snapManager = map.enableSnapping({
    snapKey: keys.CTRL,
    tolerance: 50,
  });
  var layerInfos = [{
    layer: propertyLayer
  }];
  snapManager.setLayerInfos(layerInfos);

});

Outcomes