cmv-app
cmv-app copied to clipboard
Snapping to features with Editor widget
Wondering if anyone has been successful implementing snapping to features in the Editor widget? I've implemented the SnappingManager to drawing and editing tools in stand alone apps, but not sure where to start in the Editor.js. I think the SnappingManager is built in to the esri Editor Dijit, so using something like below might work, just not sure how to implement.
map.enableSnapping({ snapPointSymbol: symbol, tolerance: 20, snapKey: keys.Ctrl });
Thanks for any info, PW
@pwild I have not tested but the code you have above should work fine. Simply add this after line 47 here. I would also add a disableSnapping call after line 61.
I have tried to enable snapping but have not been successful. I tried just adding the "this.map.enableSnapping();" after line 47, but I still do not see snapping enabled. Do I need to add the SnappingManager to the require function at line 43? If so, I also tried that, but must be doing something wrong. Any chance you can show me your Editor.js file with snapping enabled?
MUCH appreciated!
-Shana
Hey @slowe71, I just tested it with Editor widget and as @DavidSpriggs said, the toggleEditing
method ended like this:
javascript
toggleEditing : function () {
if (!this.isEdit) {
var ops = lang.clone(this.settings);
ops.map = this.map;
ops.layerInfos = this.layerInfos;
var con = domConstruct.create('div', {
innerHTML : '...',
'style' : 'text-align:center;'
}, this.containerNode, 'only');
require(['esri/dijit/editing/Editor'], lang.hitch(this, function (Editor) {
this.editor = new Editor({
settings : ops
}, con);
/* Below is the line 47 mentioned */
this.editor.startup();
/* Added code */
ops.map.enableSnapping({
/*snapPointSymbol: symbol,*/
tolerance : 20,
snapKey : keys.CTRL
});
/* End of added code */
}));
this.toggleBTN.set('label', this.i18n.labels.stopEditing);
this.toggleBTN.set('class', 'danger');
this.isEdit = true;
topic.publish('mapClickMode/setCurrent', 'editor');
} else {
this.endEditing();
topic.publish('mapClickMode/setDefault');
}
},
I also needed to add reference to `dojo/keys`. No need of `SnappingManager`dependency.
Hey @carrbrpoa I added the code just as you did to the Editor.js file including the dojo/keys reference and am not getting any snapping ability. Did you change anything else to make it work? I'm using the latest release of CMV 1.3.4
Thanks, Ry
Hey @rylincoln, it's really just that code. You need to press Ctrl to see/activate the snap highlight:
See the cross close to the popup, that's the snap :)
Ok, must be something else in my setup/system that's keeping it from working. My cursor never changes from the standard windows arrow cursor. Thanks for your reply!
Cheers, Ry
It didn't appears in the print screen, but the windows arrow cursor is there too. When you move it close to a feature pressing Ctrl, it "grabs" that feature and the green/blue cross appears there. In my case, the features are those dark points.
Wow - I'm a dunce. Ok it works and now I know how to properly reference the dojo/keys in the define function up top and for some reason I couldn't use CTRL but once I switched to SHIFT it worked fine.
Thanks for your help @carrbrpoa
-Ry
You are welcome, glad it worked!
@carrbrpoa @DavidSpriggs I need measurement at the time editing, i want to create polygon with dimesions like 100*100 FT without measurement unable to create please help.
Please help me editing with the measurement widget.when i start editing measurement not visible, without measurement how can i create polygon.
@saurabhgis That is the way the 2 widgets are designed, you can only click the map with one widget at a time. So when you start to edit, it clears any measurements or drawing. Both of the measurement and editor widgets use Esri widgets so CMV does not have much control over the individual behaviors. To do what you desire would require the creation of a new widget - probably not an insignificant effort since editing is involved.
Use distance tool to measure a distance while editing. Place a point, press d, enter distance, place second point.
Sent from my iPhone
On Jun 8, 2016, at 10:21 PM, saurabhgis [email protected] wrote:
Please help me editing with the measurement widget.when i start editing measurement not visible, without measurement how can i create polygon.
— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub, or mute the thread.
@barryderay I know the steps you describe are something that you can do with ArcGIS Desktop. Are you suggesting that this is also supported within the ESRI JavaScript API?
Snapping with Measurement Tool
I am trying to implement editor code on measurement widget to enable snapping but not succeed. @carrbrpoa @DavidSpriggs @rylincoln please help me.
Hey @saurabhgis,
Actually I'm having the same problem. Even with snapping enabled, snap is not working with Measurement Tool; works with Editor or Drawing tools.
Seems to exist some kind of conflict between Snapping's activation. I commented the lines that activated it inside Measurement Tool and it worked:
disconnectMapClick : function () {
topic.publish('mapClickMode/setCurrent', 'measure');
/*this.map.enableSnapping({
tolerance: 20,
snapKey: keys.CTRL
});*/
},
PS: I have activation code inside Editor widget though:
toggleEditing : function () {
if (!this.isEdit) {
var ops = lang.clone(this.settings);
ops.map = this.map;
...
require(['esri/dijit/editing/Editor'], lang.hitch(this, function (Editor) {
this.editor = new Editor({
settings : ops
}, con);
this.editor.startup();
}));
/* <ACTIVATION CODE> */
ops.map.enableSnapping({
tolerance : 15,
snapKey : keys.CTRL
});
/* </ACTIVATION CODE> */
this.toggleBTN.set('label', this.i18n.labels.stopEditing);
...
}
}
@carrbrpoa the line you commented out is not in the cmv measurement widget within the repo. Might that be custom code you have added?
Maybe...so many customs...sorry for that! :P
@carrbrpoa Thanks for sharing valuable information.
If possible share me measurement widget code, and also confirm me is it works on ArcGIS JS 3.15.
@carbropa Please check below measurement code.
define([ 'dojo/_base/declare', 'dijit/_WidgetBase', 'esri/dijit/Measurement', 'dojo/aspect', 'dojo/_base/lang', 'dojo/dom-construct', 'dojo/topic' ], function (declare, _WidgetBase, Measurement, aspect, lang, domConstruct, topic) {
return declare([_WidgetBase], {
declaredClass: 'gis.dijit.Measurement',
mapClickMode: null,
postCreate: function () {
this.inherited(arguments);
this.measure = new Measurement({
map: this.map,
defaultAreaUnit: this.defaultAreaUnit,
defaultLengthUnit: this.defaultLengthUnit
}, domConstruct.create('div')).placeAt(this.domNode);
this.measure.startup();
aspect.after(this.measure, 'setTool', lang.hitch(this, 'checkMeasureTool'));
aspect.after(this.measure, 'closeTool', lang.hitch(this, 'checkMeasureTool'));
this.own(topic.subscribe('mapClickMode/currentSet', lang.hitch(this, 'setMapClickMode')));
if (this.parentWidget && this.parentWidget.toggleable) {
this.own(aspect.after(this.parentWidget, 'toggle', lang.hitch(this, function () {
this.onLayoutChange(this.parentWidget.open);
})));
}
},
checkMeasureTool: function () {
// no measurement tool is active
if (!this.measure.activeTool || this.measure.activeTool === '') {
if (this.mapClickMode === 'measure') {
this.connectMapClick();
}
// a measurement tool is active
} else {
if (this.mapClickMode !== 'measure') {
this.disconnectMapClick();
}
}
},
disconnectMapClick: function () {
topic.publish('mapClickMode/setCurrent', 'measure');
this.map.enableSnapping({
tolerance: 20,
snapKey: keys.CTRL
});
},
connectMapClick: function () {
topic.publish('mapClickMode/setDefault');
},
onLayoutChange: function (open) {
// end measurement on close of title pane
if (!open && this.mapClickMode === 'measure') {
this.connectMapClick();
}
},
setMapClickMode: function (mode) {
this.mapClickMode = mode;
if (mode !== 'measure') {
this.measure.setTool('area', false);
this.measure.setTool('distance', false);
this.measure.setTool('location', false);
this.measure.clearResult();
}
}
});
});
@carrbrpoa @tmcgee # As discussed I have changed my measurement widget but snapping is not enabled.