I'm working on a webapplication which requires snapping on some layers. I've enabled snapping using these lines of code:
var map = this.app.map;
this.snappingManager = map.enableSnapping({
alwaysSnap: true,
snapPointSymbol: esri.symbol.SimpleMarkerSymbol(),
tolerance: t,//t is a parameter in the complete function
snapKey: dojo.keys.copyKey
});
But when I try to snap to my layers, it does not work. I tried to debug my code and saw some behaviour which seems strange in the SnappingManager.js code from the javascript api
When the Snappingmanager is in the _getSnappingPoint function, the following code is executed:
n = this.map._getFrameWidth(); variable n is used in this function in various places
In my case n has the value undefined and I think therefore the other parts of the function fail.
I had a closer look at the _getFrameWidth function which gives an undefined
_getFrameWidth: function() {
var a = -1, b = this.spatialReference._getInfo();
this.__LOD ? (b = this.__LOD._frameInfo) && (a = b[3]) : b && (a = Math.round(2 * b.valid[1] / (this.extent.getWidth() / this.width)));
return a
In the first line of code I get a null for this.spatialReference._getInfo(); because my map is in WKID 28992
However the map has a .__LOD, so the function will try to use this in the tenary operaion and assign the _frameInfo from the LOD to b and then tries to get a value from this array. However my array is empty, because my __LOD looks like this: "{"scale":1216.7116413886708,"_frameInfo":[]}"
I compared my map to one of the examples from Esri and in this map the __LOD looks like this:
{"level":17,"resolution":1.1943285668550503,"scale":4513.988705,"startTileRow":214,"startTileCol":0,"endTileRow":130857,"endTileCol":131071,"_frameInfo":[131072,0,131071,33554432]}
And snapping works fine when I added a snapping manager from the Chrome Console into the example
I put together a quick test case and was not able to reproduce the problem. Here's the test case:
Can you modify this test case to show the problem you are experiencing?
Thanks for the test case. I could not reproduce the problem there, but I noticed the __LOD property of my modified test case did not change from undefined to something else (which is the case in my project).
I did some more debugging today to find out why my __LOD property changes and I could trace the source of this bug in Geocortex HTML5 essentials viewer 2.2.1 . Compared to the previous version they added these lines of code:
var b = function() {
x = a.app.map.__LOD;
a.app.map.__LOD = x ? dojo.fromJson(dojo.toJson(x)) : {scale: a.app.map.getScale()};
a.app.map.__LOD._frameInfo = a.app.map.__LOD._frameInfo || []
};
So, to me it's clear they are doing things to the __LOD of the map which breaks the functionality in _getFrameWidth(); of the esri map object.
So my next step is going to be a bug report for Geocortex and to try to create a workaround for this.
Hi. Snapping manager finding featurelayer in map. U have to add to map featurelayer. Or alwaysSnap:true or snapKey: dojo.keys.copyKey u choose one.
Have a good luck.