AnsweredAssumed Answered

SnapManager fails to complete snap in Javascript

Question asked by tjones on Dec 4, 2015
Latest reply on Dec 7, 2015 by tjones

Using the Web Application Builder, I am trying to make a Measurement widget that will snap to one particular (line) feature layer. The snapping at first appears to be working on the map: Hovering the mouse near a feature will create the default blue + symbol on the feature. However, no actual snap occurs when the mouse is clicked. The same happens when trying to complete the measurement. The start and end points don't actually snap at all, they are set where the mouse pointer is, not where the blue + is.

 

I found that if I do not specify layerInfos in the code below (line 25), the snapping works correctly. The problem is that the snapping manager will not use my line feature layer and instead defaults to a different layer in the map. What is wrong in the code below that is causing the actual snap part of the process to fail?

 

Lines 01 to 14 is a for loop that is finding my line layer (Distribution). Lines 17 to 25 are getting the snapManager set up with the right properties and layer to snap to.

 

var url = "";
for(var j = 0; j < this.map.layerIds.length; j++) {
    var layer = this.map.getLayer(this.map.layerIds[j]);
    var items = layer.layerInfos;
        for (h = 0; h < items.length; h++) {
          
          if (items[h].name === "Distribution"){
              if (url === ""){
                    url = layer.url + "/" + items[h].id;
              }
             break;
            }
        }
}
   
  
var snaplayer =  new FeatureLayer(url);
var snapManager = this.map.enableSnapping({
    tolerance: 30,
    alwaysSnap: true
});
var layerInfos = [{
    layer: snaplayer
}];
snapManager.setLayerInfos(layerInfos);

Outcomes