Apply edits

5142
26
Jump to solution
10-22-2016 11:14 PM
bharathreddy
Occasional Contributor

hi,

can anyone give an example on how to apply edits while editing two layers in arcgis javasscript

0 Kudos
26 Replies
RobertScheitlin__GISP
MVP Emeritus

Bharath,

   You need to provide the attributes that the layer is expecting even you you just set them to null.

0 Kudos
bharathreddy
Occasional Contributor

what u mean is Attribute to the layer which i am editing? please guide me how to provide attributes

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Yes to the layer you are editing.

  var attr = {"Xcoord":evt.mapPoint.x,"Ycoord":evt.mapPoint.y,"Plant":"Mesa Mint"};
  var graphic = new Graphic(pt,null,attr);
bharathreddy
Occasional Contributor

Thank u very much robert

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Don't forget to mark this question as answered by clicking on the "Correct Answer" link on the reply that answered your question.

bharathreddy
Occasional Contributor

Robert,

  The stuff suggest by you was helpul now i'm able to edit point layer but unable to edit polyline i'm posting my code here please do the needful

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=7, IE=9, IE=10">
<!--The viewport meta tag is used to improve the presentation and behavior of the samples
on iOS devices-->
<meta name="viewport" content="initial-scale=1, maximum-scale=1,user-scalable=no">
<title>LT ext</title>

<link rel="stylesheet" href="http://serverapi.arcgisonline.com/jsapi/arcgis/3.5/js/dojo/dijit/themes/claro/claro.css">
<link rel="stylesheet" href="http://serverapi.arcgisonline.com/jsapi/arcgis/3.5/js/esri/css/esri.css">
<style>
html, body
{
height: 100%;
width: 100%;
margin: 0;
padding: 0;
overflow: hidden;
}

.btn
{
background: #3f3f3f;
color: #fff;
font-family: Tahoma;
font-size: 11px;
height: 18px;
}
.lbl
{
color: #000;
font-family: Tahoma;
font-size: 11px;
font-weight: 200;
}

#header
{
border: solid 1px #e4e4e4;
background: #fff;
color: #749749;
-moz-border-radius: 4em;
border-radius: 4em;
font-size: 14px;
padding-left: 20px;
font-weight: 700;
}
#map
{
padding: 1px;
border: solid 1px #e4e4e4;
-moz-border-radius: 4px;
border-radius: 4px;
}
#rightPane
{
border: none;
width: 250px;
height: 95%;
padding-bottom: 10px;
top: 20px;
border: solid 1px #e4e4e4;
}
.templatePicker
{
border: solid 2px #e4e4e4 !important;
}
</style>
<script> var dojoConfig = { parseOnLoad: true };</script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<script src="http://serverapi.arcgisonline.com/jsapi/arcgis/3.5/"></script>
<script>
dojo.require("dijit.layout.BorderContainer");
dojo.require("dijit.layout.ContentPane");
dojo.require("esri.map");
dojo.require("esri.dijit.editing.TemplatePicker-all");
dojo.require("esri.tasks.query");
dojo.require("esri.toolbars.draw");
dojo.require("esri.dijit.AttributeInspector-all");


var map, line, lineGraphic, toolbar, symbol, geomTask;
var landuseLineLayer;
var landusePointLayer;
var drawToolbar;
var fieldName1;
var newFieldValue1;
var newGraphic1;

function init() {
//This sample requires a proxy page to handle communications with the ArcGIS Server services. You will need to
//replace the url below with the location of a proxy on your machine. See the 'Using the proxy page' help topic
//for details on setting up a proxy page.
esri.config.defaults.io.proxyUrl = "/proxy";
esri.config.defaults.io.alwaysUseProxy = false;

//This service is for development and testing purposes only. We recommend that you create your own geometry service for use within your applications.
esri.config.defaults.geometryService = new esri.tasks.GeometryService("http://tasks.arcgisonline.com/ArcGIS/rest/services/Geometry/GeometryServer");

map = new esri.Map("map", {

center: [-83.244, 42.581],
zoom: 15
});


dojo.connect(map, "onLayersAddResult",setupEditor);

queryTask = new esri.tasks.QueryTask("http://localhost:6080/arcgis/rest/services/edit/MapServer/20");

// //initialize query
query = new esri.tasks.Query();
query.returnGeometry = true;
query.outFields = ["LTP_ID", "OBJECTID"];

// //create symbol for selected features
symbol = new esri.symbol.SimpleMarkerSymbol();
symbol.setStyle(esri.symbol.SimpleMarkerSymbol.STYLE_SQUARE);
symbol.setSize(10);
//symbol.setColor(new esri.Color([255, 255, 0, 0.5]));


var labels = new esri.layers.ArcGISDynamicMapServiceLayer("http://localhost:6080/arcgis/rest/services/edit/MapServer");
map.addLayer(labels);


landusePointLayer = new esri.layers.FeatureLayer("http://localhost:6080/arcgis/rest/services/edit/FeatureServer/20", {
mode: esri.layers.FeatureLayer.MODE_SNAPSHOT,
outFields: ["*"]
});
landuseLineLayer = new esri.layers.FeatureLayer("http://localhost:6080/arcgis/rest/services/edit/FeatureServer/34", {
mode: esri.layers.FeatureLayer.MODE_SNAPSHOT,
outFields: ["*"]
});


map.addLayers([landusePointLayer, landuseLineLayer]);
var ltline = landuseLineLayer;
var ltpole = landusePointLayer;


dojo.connect(map, "onLoad", function () {


dojo.connect(dijit.byId("map"), "resize", map, map.resize);

});
}
var selectedTemplate;
function LTEXT() {


//var l = landuseLineLayer;

var p1 = new esri.geometry.Point(218103.84229999967, 1172648.3827999998, map.spatialReference);


line = new esri.geometry.Polyline();
line.addPath([p1]);


dojo.connect(map, "onClick", addPt);
}

function addPt(e) {

var selectedTemplate;
var featureLayers;
var geometryType;

// create a new path using the current line endpoint and the click point
//var p2 = esri.geometry.geographicToWebMercator(new esri.geometry.Point(e.mapPoint.x, e.mapPoint.y, map.spatialReference));
//line.addPath([p2]);
var pathCount = line.paths.length;
line.addPath([line.paths[pathCount - 1][line.paths[pathCount - 1].length - 1], [e.mapPoint.x, e.mapPoint.y]]);
lineGraphic = map.graphics.add(new esri.Graphic(line, new esri.symbol.SimpleLineSymbol()));
map.graphics.add(new esri.Graphic(e.mapPoint, new esri.symbol.SimpleMarkerSymbol()));
var ltp = e.mapPoint;
var k = landuseLineLayer;
var p = landusePointLayer;
saveedits(lineGraphic, landuseLineLayer, landusePointLayer,ltp)
//lineGraphic.setGeometry(line);
// var newGraphic = new esri.Graphic(lineGraphic, null);
// landuseLineLayer.applyEdits([newGraphic], null, null);

/////////////////////////////////////////////////////////////////////////////////////////////

}

function saveedits(linegraphic,landuseLineLayer,landusePointLayer,ltp) {
debugger;

var template = landusePointLayer.templates[0];
var template1 = landuseLineLayer.templates[0];
var attributes = dojo.mixin({}, template.prototype.attributes);
var attributes1 = dojo.mixin({}, template1.prototype.attributes);

var newGraphic = new esri.Graphic(ltp, null, attributes);
landusePointLayer.applyEdits([newGraphic]);

var newGraphic1 = new esri.Graphic(pol, null, attributes1);
landuseLineLayer.applyEdits([newGraphic1,null,null]);


var ggg=pol;
map.infoWindow.show(map.toScreen(pol));

updateAttributes(newGraphic,newGraphic1,ggg);

}

function updateAttributes(newGraphic,newGraphic1,ggg,fieldName, newFieldValue) {
debugger;

//update attributes for feature
newGraphic.attributes[fieldName] = newFieldValue;

landusePointLayer.applyEdits(null, [newGraphic]);

updateltline(newGraphic1,fieldName1, newFieldValue1,ggg);

}

function updateltline(newGraphic1,fieldName1,newFieldValue1,ggg) {
debugger;
var fieldNamel;
//update attributes for feature
map.infoWindow.show(map.toScreen(ggg));
// map.infoWindow.show(map.toScreen(ggg));
newGraphic1.attributes[fieldName1] = newFieldValue1;
// map.infoWindow.show(map.toScreen(ggg));

landuseLineLayer.applyEdits(null, [newGraphic1]);

}

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("onClickEnd",saveedits);
// map.on("click", myClickHandler);
//dojo.connect(map, "onClick", saveedits);

//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 executeQueryTask(sTownID) {


query.where = "LTP_ID ='" + sTownID + "'";


//execute query
queryTask.execute(query, showResults);

}

function showResults(featureSet) {

//remove all graphics on the maps graphics layer
map.graphics.clear();

//Performance enhancer - assign featureSet array to a single variable.
var resultFeatures = featureSet.features;
console.log(resultFeatures);

//Loop through each feature returned
for (var i = 0, il = resultFeatures.length; i < il; i++) {
//Get the current feature from the featureSet.
//Feature is a graphic
var graphic = resultFeatures;
graphic.setSymbol(symbol);

//Set the infoTemplate.
//graphic.setInfoTemplate(infoTemplate);

//Add graphic to the map graphics layer.
map.graphics.add(graphic);
if (graphic.geometry.type === 'point') {

map.centerAndZoom(graphic.geometry, 0.001);

}

}
}


dojo.ready(init);
</script>
</head>
<body class="claro">
<div style="height: 30px; border: solid 1px; border-color: #e4e4e4; width: 100%;
background: #f0ebff">
Header
</div>
<div style="height: 25px; border: solid 1px; border-color: #e4e4e4; width: 100%;
background: #d2d2d2; text-align: center">
ToolBar
</div>
<div data-dojo-type="dijit.layout.BorderContainer" data-dojo-props="gutters:true, design:'sidebar'"
style="width: 100%; height: 100%;">
<div id="map" data-dojo-type="dijit.layout.ContentPane" data-dojo-props="region:'center'">
</div>
<div id="rightPane" data-dojo-type="dijit.layout.ContentPane" data-dojo-props="region:'right'">
<span class="lbl">Enter Value :</span>
<input type="text" id="pop" style="width: 150px;" />
<input type="button" value="Zoom" onclick="executeQueryTask(dojo.byId('pop').value);"
class="btn" />
<div id="templatePickerDiv1">
<input type="button" id="templatePickerDiv" value="Start LT Ext" onclick="LTEXT()"
class="btn" />
</div>
</div>
</div>
</body>
</html>

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Bharath,

   I don't think I can spend any more time helping with code that is using such an old API version and still using legacy format. I am not sure why you are not spending time to update your code to Modern standards and using the latest API. There are things in your code that I don't even understand because they are so old and I have no experience with.