I'm new to GIS. I'm using the CMV template for my applications, but I can't get the Editor widget to work. The problem is that all the functionalities form the Editor Toolbar are not working. The only thing that works is adding a new point to the map, but then you can't delete nor edit it... Here is my code:

return declare([_WidgetBase, _TemplatedMixin, _WidgetsInTemplateMixin], {

    templateString: template,
    i18n: i18n,
    widgetsInTemplate: true,
    editor: null,
    isEdit: false,
    mapClickMode: null,
    layerInfos: [],
    postCreate: function() {
        this.inherited(arguments);
        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);
            })));
        }
    },
    toggleEditing: function() {
        if (!this.isEdit) {
            var ops = lang.clone(this.settings);
            ops.map = this.map;
            ops.layerInfos = this.layerInfos;

            array.forEach(ops.layerInfos, function(layerInfo) {
                var controlOptions = layerInfo.controlOptions;
                console.log("ControlOptions: " + controlOptions);
            });

            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);
                console.log("click on new Editor => " + ops.layerInfos);
                this.editor.startup();
                this.editor.editToolbar.on('graphic-first-move', function(e) {
                    console.log('Move has begun');
                });
                ops.map.enableSnapping({
                    /*snapPointSymbol: symbol,*/
                    tolerance: 20,
                    snapKey: keys.CTRL
                });

            }));
            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');
        }
    },
    endEditing: function() {
        if (this.editor && this.editor.destroyRecursive) {
            this.editor.destroyRecursive();
        }
        this.toggleBTN.set('label', this.i18n.labels.startEditing);
        this.toggleBTN.set('class', 'success');
        this.isEdit = false;
        this.editor = null;
    },

    onLayoutChange: function(open) {
        // end edit on close of title pane
        if (!open && this.mapClickMode === 'editor') {
            this.endEditing();
            topic.publish('mapClickMode/setDefault');
        }
    },
    setMapClickMode: function(mode) {
        this.mapClickMode = mode;
        if (mode !== 'editor') {
            this.endEditing();
        }
    }
});

This is the configuration for the widget:

editor: {
    include: true,
    id: 'editor',
    type: 'titlePane',
    path: 'gis/dijit/Editor',
    title: '<i class="fa fa-pencil-square-o"></i>&nbsp;&nbsp;' + i18nViewer.Editor_menuLabel,
    open: false,
    position: 7,
    options: {
        map: true,
        mapClickMode: true,
        editorLayerInfos: true,
        settings: {
            toolbarVisible: true,
            showAttributesOnClick: true,
            enableUndoRedo: true,
            createOptions: {
                polygonDrawTools: ['freehandpolygon', 'autocomplete']
            },
            toolbarOptions: {
                reshapeVisible: true,
                cutVisible: true,
                mergeVisible: true
            }
        }
    }
},

The CMV Editor widget is just a wrapper for the ESRI Edit toolbar and the desired configuration is passed along to the ESRI toolbar. Whether you can add/edit/delete features using the ESRI editor toolbar is mostly determined by the operational layer not the configuration for the CMV widget.

First, the layer in the Feature Service on your ArcGIS Server must allow the operations for Create, Update and Delete. That is the first thing that you should verify and where the problem most likely occurs.

Second, the template(s) for the layer (as created in ArcGIS Desktop) is also a possible factor. I include this only for completeness since it sounds like this is working as expected in your case.

Lastly, you did not include in your question the editorLayerInfos for your operational layer in the viewer.js configuration file. That section of the configuration is how the ESRI Editor widget knows the layer should be editted and what capabilites to provide. Here's an example of a working configuration:

operationalLayers: [
    {
        type: 'feature',
        url: 'https://yourserver/arcgis/rest/services/test/EditTest/FeatureServer/0',
        title: 'Edit Points',
        options: {
            id: 'editPoints',
            visible: true,
            outFields: ['*'],
            mode: 1
        },
        editorLayerInfos: {
            showDeleteButton: true,
            disableAttributeUpdate: false,
            disableGeometryUpdate: false,
            fieldInfos: [
                {
                    fieldName: 'FEATURE_NAME',
                    label: 'Feature Name'
                },
                {
                    fieldName: 'FEATURE_TYPE',
                    label: 'Feature Type'
                },
                {
                    fieldName: 'KEY',
                    label: 'Key',
                    isEditable: false
                },
                {
                    fieldName: 'PROGRAM',
                    label: 'Program'
                },
                {
                    fieldName: 'COLLECT_BY',
                    label: 'Collected By',
                    isEditable: false
                },
                {
                    fieldName: 'CREATED_DATE',
                    label: 'Date Created'
                },
                {
                    fieldName: 'LAST_EDITED_DATE',
                    label: 'Date Modified'
                }
            ]
        }
    }
}

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.