SsnappingManager only snaps to map graphics

1145
6
Jump to solution
04-17-2013 06:13 AM
AdrianMarsden
Occasional Contributor III
Hi

I have a internal project about to go live, I really want to have snapping for measurements and user added graphics.

At the moment a simple

    map.enableSnapping({ snapKey: dojo.keys.copyKey });

gets it on. However snapping only appears to work against already drawn graphics, not on any of my vector layers on my map.  My map is made up of four ArcGISDynamicMapServiceLayer - added like this

    var background = new esri.layers.ArcGISDynamicMapServiceLayer(mapservice1, { "id": "mainbasemaps" });   // map.addLayer(background);       background.setDPI(150);     var altmaps = new esri.layers.ArcGISDynamicMapServiceLayer(altbasemaps, { "id": "altbasemaps" });    // map.addLayer(altmaps);     var aerials = new esri.layers.ArcGISDynamicMapServiceLayer(aerialservice, { "id": "aerialmaps" });       //map.addLayer(aerials);     dynamicMapServiceLayer = new esri.layers.ArcGISDynamicMapServiceLayer(mapservice2, { "id": "mainmap" });     dynamicMapServiceLayer.setOpacity(0.9);     dynamicMapServiceLayer.setDPI(96)     map.addLayers([background],[altmaps],[aerials],[dynamicMapServiceLayer]);



from the API documentation

Reference to a feature or graphics layer that will be a target snapping layer. The default option is to set all feature and graphics layers in the map to be target snapping layers.


So I would have thought it would snap to everything?

I've tried defining a specific layer like

var snappinglayer = new esri.layers.FeatureLayer(mapservice2 + "/4", {        mode: esri.layers.FeatureLayer.MODE_ONDEMAND,         outFields: ["*"]     }); ... var layerInfos = [{ layer: snappinglayer }];     snapManager.setLayerInfos(layerInfos);


But that fails.

Any ideas what I've missed?

ACM
0 Kudos
1 Solution

Accepted Solutions
JianHuang
Occasional Contributor III
Yes, the featureLayer has to be added to the map and it has to be visible.



Ah, do I understand correctly then, that the snapping only works on feature layers added to the map?  I guess so



If so it would explain a lot as I have no feature layers, just dynamic ones.

So, if  I add a feature layer to the map - does it have to be visible?

Cheers

ACM

View solution in original post

0 Kudos
6 Replies
JohnGravois
Frequent Contributor
im not sure i understand.  are you trying to snap to a featureLayer which hasn't been added to the map because youre already drawing it in a DynamicMapServiceLayer?
0 Kudos
AdrianMarsden
Occasional Contributor III
Ah, do I understand correctly then, that the snapping only works on feature layers added to the map?  I guess so

Reference to a feature or graphics layer that will be a target snapping layer. The default option is to set all feature and graphics layers in the map to be target snapping layers.


If so it would explain a lot as I have no feature layers, just dynamic ones.

So, if  I add a feature layer to the map - does it have to be visible?

Cheers

ACM
0 Kudos
JohnGravois
Frequent Contributor
i haven't done any testing with this at all, but my guess would be that only the graphics being drawn would be "snap enabled".
0 Kudos
JianHuang
Occasional Contributor III
Yes, the featureLayer has to be added to the map and it has to be visible.



Ah, do I understand correctly then, that the snapping only works on feature layers added to the map?  I guess so



If so it would explain a lot as I have no feature layers, just dynamic ones.

So, if  I add a feature layer to the map - does it have to be visible?

Cheers

ACM
0 Kudos
AdrianMarsden
Occasional Contributor III
Cheers - I'm sure I tried that, but I'll have another go.

Thanks

ACM
0 Kudos
AdrianMarsden
Occasional Contributor III
sorted - thanks - I must have read the API notes several times without noticing it said feature.

Cheers

ACM
0 Kudos