POST
|
Hello Eben, The built in Editor widget doesn't work so I combined the edit toolbar, attribute inspector, and template picker to get all the features to work. Here is the function I created. Add your own feature layer. Add the appropriate requires and use map.on("layers-add-result", initEditTool). Sorry, I cannot upload the whole app, as the layers have sensitive material. I used this as a guide and made minimal changes to get multipoint to work. Hope this helps! function initEditTool(results) {
var layers = array.map(results.layers, function(result) {
return result.layer;
});
//display read-only info window when user clicks on feature
var query = new Query();
array.forEach(layers, function(layer) {
layer.on("click", function(evt) {
if (map.infoWindow.isShowing) {
map.infoWindow.hide();
}
var layerInfos = [{
'featureLayer': layer,
'isEditable': false,
'showDeleteButton': false,
'showAttachments': false,
}]
var attInspector = new AttributeInspector({
layerInfos: layerInfos
}, domConstruct.create("div"));
query.objectIds = [evt.graphic.attributes.OBJECTID];
layer.selectFeatures(query, FeatureLayer.SELECTION_NEW, function(features) {
map.infoWindow.setTitle("");
map.infoWindow.setContent(attInspector.domNode);
map.infoWindow.resize(310, 165);
map.infoWindow.show(evt.screenPoint, map.getInfoWindowAnchor(evt.screenPoint));
});
});
});
var templatePicker = new TemplatePicker({
featureLayers: layers,
rows: 'auto',
columns: 'auto',
grouping: true
}, "templatePickerDiv");
templatePicker.startup();
var drawToolbar = new Draw(map);
var selectedTemplate;
templatePicker.on("selection-change", function() {
selectedTemplate = templatePicker.getSelected();
if (selectedTemplate) {
switch (selectedTemplate.featureLayer.geometryType) {
case "esriGeometryPoint":
drawToolbar.activate(Draw.POINT);
break;
case "esriGeometryPolyline":
selectedTemplate.template.drawingTool === 'esriFeatureEditToolFreehand' ? drawToolbar.activate(Draw.FREEHAND_POLYLINE) : drawToolbar.activate(Draw.POLYLINE);
break;
case "esriGeometryPolygon":
selectedTemplate.template.drawingTool === 'esriFeatureEditToolFreehand' ? drawToolbar.activate(Draw.FREEHAND_POLYGON) : drawToolbar.activate(Draw.POLYGON);
break;
case "esriGeometryMultipoint":
selectedTemplate.template.drawingTool === 'esriFeatureEditToolFreehand' ? drawToolbar.activate(Draw.MULTI_POINT) : drawToolbar.activate(Draw.MULTI_POINT) ;
break;
}
}
});
drawToolbar.on("draw-end", function(result) {
//display the editable info window for newly created features
if (map.infoWindow.isShowing) {
map.infoWindow.hide();
}
drawToolbar.deactivate();
var fieldAttributes = layerFieldToAttributes(selectedTemplate.featureLayer.fields);
var newAttributes = lang.mixin(fieldAttributes, selectedTemplate.template.prototype.attributes);
var newGraphic = new Graphic(result.geometry, null, newAttributes);
var layerInfos = [{
'featureLayer': selectedTemplate.featureLayer,
'isEditable': true
}];
var attInspector = new AttributeInspector({
layerInfos: layerInfos
}, domConstruct.create("div"));
selectedTemplate.featureLayer.applyEdits([newGraphic], null, null, function() {
var screenPoint = map.toScreen(getInfoWindowPositionPoint(newGraphic));
map.infoWindow.setTitle("");
map.infoWindow.setContent(attInspector.domNode);
map.infoWindow.resize(325, 185);
map.infoWindow.show(screenPoint, map.getInfoWindowAnchor(screenPoint));
templatePicker.clearSelection();
});
attInspector.on("attribute-change", function(result) {
result.feature.attributes[result.fieldName] = result.fieldValue; // result will contains a feature layer to access its attributes
result.feature.getLayer().applyEdits(null, [result.feature], null);
});
attInspector.on("delete", function(result) {
result.feature.getLayer().applyEdits(null, null, [result.feature]);
map.infoWindow.hide();
});
});
}
function getInfoWindowPositionPoint(feature) {
var point;
switch (feature.getLayer().geometryType) {
case "esriGeometryPoint":
point = feature.geometry;
break;
case "esriGeometryPolyline":
var pathLength = feature.geometry.paths[0].length;
point = feature.geometry.getPoint(0, Math.ceil(pathLength / 2));
break;
case "esriGeometryPolygon":
point = feature.geometry.getExtent().getCenter();
break;
case "esriGeometryMultipoint":
point = feature.geometry.getExtent().getCenter();
break;
}
return point;
}
function layerFieldToAttributes(fields) {
var attributes = {};
array.forEach(fields.Object, function(field) {
attributes[field.name] = null;
});
return attributes;
}
... View more
02-07-2018
03:32 PM
|
0
|
0
|
1005
|
POST
|
Hello Everyone, I am trying to learn how to use the edit toolbar, but it seems like editing points does not work, even with the sample on Arcgis Javascript sample code. ArcGIS API for JavaScript Sandbox Double clicking on any other graphic will select it, but not for the point graphics. The console shows an error: Uncaught Error: [esri.toolbars.Edit::activate] Unable to activate the tool. Check if the tool is valid for the given geometry type. I cannot use the Editor Widget because I need it to work for multi points also. How can I change the sample code to fix this? Thank you for your time.
... View more
02-04-2018
12:55 AM
|
0
|
2
|
960
|
POST
|
The multipoint is used to represent a city construction project that can take place at multiple points throughout the city. I need to draw the multipoints and have it be editable as one project. I would appreciate and example of combining the draw tool, attribute selector, and apply edits to work around this. Thank you!
... View more
01-29-2018
05:06 PM
|
0
|
0
|
1005
|
POST
|
Have either of you figured out how to work around this? It is giving a halt on my project. Any help is appreciated!
... View more
01-27-2018
03:06 PM
|
0
|
2
|
1005
|
POST
|
Thank you for the reply Chris. I'd like to expand on my question. What I am looking for is for the Editor to save the new drawn multipoint to my multipoint feature layer, not just to simply draw it on the map. I want it to be exactly like the example I posted but with the addition of multipoint. I appreciate and further advice you can give!
... View more
01-25-2018
02:11 PM
|
0
|
0
|
308
|
POST
|
Hello everyone. I am using the following example that uses the Editor to draw a point, line, and polygon onto my map. However, I am trying to do the same with multipoints but I am not sure where to start. It seems like the Editor does not support multipoints. What can I do to get it working? Thank you in advance. ArcGIS API for JavaScript Sandbox
... View more
01-25-2018
12:35 PM
|
0
|
2
|
576
|
Online Status |
Offline
|
Date Last Visited |
11-11-2020
02:24 AM
|