Solved! Go to Solution.
function addFeature(evt){ var X = evt.mapPoint.x var Y = evt.mapPoint.y featureService = "http://sever/ArcGIS/rest/services/HSEC/FeatureServer/0/addFeatures?features="; addPoint = '[{"geometry":{"x":' + X + ',"y":' + Y + '}}]'; addFeaturesEncode(); } function addFeaturesEncode() { var unencoded = addPoint; var obj = encodeURIComponent(unencoded); var theUrl = featureService + obj; var xmlHttp = null; xmlHttp = new XMLHttpRequest(); xmlHttp.open( "POST", theUrl, false ); xmlHttp.send( null ); }
<!DOCTYPE html> <html> <head> <title>Simple Editing</title> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <link rel="stylesheet" href="http://serverapi.arcgisonline.com/jsapi/arcgis/3.4/js/dojo/dijit/themes/claro/claro.css"> <link rel="stylesheet" href="http://serverapi.arcgisonline.com/jsapi/arcgis/3.4/js/dojo/dijit/themes/claro/claro.css"> <link rel="stylesheet" href="http://serverapi.arcgisonline.com/jsapi/arcgis/3.4/js/esri/css/esri.css"> <style> html,body,#mapDiv,.map.container{ padding:0; margin:0; height:100%; } #point{ z-index: 40; position: absolute; top:30px; right:40px; } </style> <script src="http://serverapi.arcgisonline.com/jsapi/arcgis/3.4/"></script> <script> dojo.require("esri.map"); dojo.require("esri.layers.FeatureLayer"); dojo.require("esri.dijit.AttributeInspector-all"); dojo.require("esri.toolbars.draw"); var drawToolbar, map; var notesLayer; var attributeInspector; function init(){ dojo.connect(dojo.byId("point"), "onclick", function(){ //activate the draw toolbar so a new point can be added to the map drawToolbar.activate(esri.toolbars.Draw.POINT); }); esri.config.defaults.io.proxyUrl = "http://localhost/~kell3008/proxy/proxy.php"; map = new esri.Map("mapDiv", { center: [-56.049, 38.485], zoom: 3, basemap: "streets" }); notesLayer = new esri.layers.FeatureLayer("http://sampleserver5.arcgisonline.com/ArcGIS/rest/services/Notes/FeatureServer/0",{ outFields: ["*"] }); //select features and show attribute inspector when clicking on note feature dojo.connect(notesLayer,"onClick", showAttributes); dojo.connect(map, "onLayersAddResult", setupEditor); map.addLayers([notesLayer]); } function showAttributes(event){ hideAttributes(); var query = new esri.tasks.Query(); query.objectIds = [event.graphic.attributes.objectid]; notesLayer.selectFeatures(query, esri.layers.FeatureLayer.SELECTION_NEW, function(features){ //attributeInspector.refresh(); map.infoWindow.show(event.screenPoint); }); } function hideAttributes(){ if(map.infoWindow.isShowing){ map.infoWindow.hide(); } } function setupEditor(results){ //setup the draw toolbar and an event that will fire after the point has been drawn. drawToolbar = new esri.toolbars.Draw(map); dojo.connect(drawToolbar, "onDrawEnd",addNote); //Create the attribute inspector so we can update attributes //first lets get the feature layers to associate with the attribute inspector var layerInfos = dojo.map(results, function(result) { return { 'featureLayer':result.layer, 'showAttachments': false }; }); attributeInspector = new esri.dijit.AttributeInspector({ layerInfos: layerInfos, },dojo.create("div")); //display the attribute inspector in the popup map.infoWindow.setTitle("Edit Features"); map.infoWindow.setContent(attributeInspector.domNode); dojo.connect(attributeInspector, "onAttributeChange", updateAttributes); dojo.connect(attributeInspector, "onDelete", deleteFeature); } function updateAttributes(feature, fieldName, newFieldValue){ //update attributes for feature feature.attributes[fieldName] = newFieldValue; notesLayer.applyEdits(null, [feature]); } function deleteFeature(feature){ //remove the feature from the feature layer notesLayer.applyEdits(null, null, [feature]); hideAttributes(); } function addNote(geometry){ //add a new feature to the feature layer drawToolbar.deactivate(); //only one feature template in this feature layer so let's get that one and use it //the template gets us access to things like the attribute info so we can populate //the new feature with the default attributes. var template = notesLayer.templates[0]; //lets setup the attributes for the new feature var attributes = dojo.mixin({},template.prototype.attributes); //now create the feature and add it to the layer var feature = new esri.Graphic(geometry ,null, attributes); notesLayer.applyEdits([feature]); map.infoWindow.show(map.toScreen(geometry)); } dojo.ready(init); </script> </head> <body class="claro"> <div id="mapDiv"> <input id="point" type="button" value="Add Note"/> </div> </body> </html>
James
You can do this with the api you just need to handle many of the update events yourself. The feature layer has an applyEdits method that can be used to add, update and delete features. Here's code for a simple use case where we are editing a point feature layer with only one feature template. In this app just click the 'Add Note' button and you'll see a new note added to the map and the attribute inspector will appear.
<snip>
You can do this with the api you just need to handle many of the update events yourself. The feature layer has an applyEdits method that can be used to add, update and delete features. Here's code for a simple use case where we are editing a point feature layer with only one feature template. In this app just click the 'Add Note' button and you'll see a new note added to the map and the attribute inspector will appear.