AnsweredAssumed Answered

apply edits error

Question asked by abbabharath on Dec 6, 2016

Hi ,

 

i am unable to edit line feature on map click for the second time below is the code i have used landuselinelayer is line feature, 

landusepointlayer is point feature (for the second time i'm getting following error unable to complete operation)

 

<%@ 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 xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<link rel="stylesheet" href="https://js.arcgis.com/3.18/dijit/themes/claro/claro.css">
<link rel="stylesheet" href="https://js.arcgis.com/3.18/esri/css/esri.css">
<meta name="viewport" content="initial-scale=1, maximum-scale=1,user-scalable=no">
<title>Landuse</title>
<link rel="stylesheet" href="https://js.arcgis.com/3.18/dijit/themes/claro/claro.css">
<link rel="stylesheet" href="https://js.arcgis.com/3.18/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 2px #462d44;
background: #fff;
color: #444;
-moz-border-radius: 4px;
border-radius: 4px;
font-family: sans-serif;
font-size: 1.1em padding-left:20px;
}
#map
{
padding: 1px;
border: solid 2px #444;
-moz-border-radius: 4px;
border-radius: 4px;
}
#rightPane
{
border: none;
padding: 0;
width: 228px;
}
.templatePicker
{
border: solid 2px #444;
}
</style>
<script src="https://js.arcgis.com/3.18/"></script>
<script type="text/javascript">
var map;
require([
"dojo/dom", "dojo/on",
"esri/map",
"esri/layers/ArcGISDynamicMapServiceLayer",
"esri/toolbars/draw",
"esri/toolbars/edit",
"esri/graphic",
"esri/config",
"esri/tasks/QueryTask",
"esri/tasks/query",
"esri/Color",
"esri/geometry/Polyline",
"esri/geometry/Point",

"esri/layers/FeatureLayer",

"esri/symbols/SimpleMarkerSymbol",

"esri/symbols/SimpleLineSymbol",
"esri/symbols/SimpleFillSymbol",
"esri/symbols/CartographicLineSymbol",

"esri/dijit/editing/TemplatePicker",

"dojo/_base/array",
"dojo/_base/event",
"dojo/_base/lang",
"dojo/parser",
"dijit/registry",
"dojo/_base/Color",


"dijit/layout/BorderContainer", "dijit/layout/ContentPane",
"dijit/form/Button", "dojo/domReady!"
], function (
dom, on, Map, ArcGISDynamicMapServiceLayer, Draw, Edit, Graphic, esriConfig, QueryTask, Query, Color, Polyline, Point,
FeatureLayer,
SimpleMarkerSymbol, SimpleLineSymbol, SimpleFillSymbol, CartographicLineSymbol,
TemplatePicker,
arrayUtils, event, lang, parser, registry, Color
) {
parser.parse();

// refer to "Using the Proxy Page" for more information: https://developers.arcgis.com/javascript/3/jshelp/ags_proxy.html
esriConfig.defaults.io.proxyUrl = "/proxy/";

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

map = new Map("map", {

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


var executeQueryTask;
var line;
var lineSymbol;


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

//initialize query task
var queryTask = new QueryTask("http://localhost:6080/ArcGIS/rest/services/edit/MapServer/20");

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


symbol = new SimpleMarkerSymbol();
symbol.setStyle(SimpleMarkerSymbol.STYLE_SQUARE);
symbol.setSize(10);
symbol.setColor(new Color([255, 255, 0, 0.5]));

on(dom.byId("execute"), "click", execute);

on(dom.byId("ltext"), "click", ltext);

 

 

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

 


// map.on("layers-add-result",setupEditor);


map.addLayers([landusePointLayer, landuseLineLayer]);

 

 


function execute() {
debugger;
query.text = dom.byId("stateName").value;
queryTask.execute(query, showResults);
}


function showResults(featureSet) {
debugger;

map.graphics.clear();

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

//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[i];
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);

}
}
}


function ltext() {
debugger;

line = new Polyline(map.spatialReference);
lineSymbol = new CartographicLineSymbol(
CartographicLineSymbol.STYLE_SOLID,
new Color([255, 0, 0]), 10,
CartographicLineSymbol.CAP_ROUND,
CartographicLineSymbol.JOIN_MITER, 5
);

pointSymbol = new SimpleMarkerSymbol().setColor(new Color([255, 0, 0, 0.5]));


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


}

function addPt(e) {
debugger;

var pathCount = line.paths.length;
console.log(pathCount);
// console.log(e.mapPoint.y);
// console.log(e.mapPoint.x);
if (pathCount == 0) {
var point1 = new Point(218966.696, 1173294.233, map.spatialReference);
var point2 = new Point(e.mapPoint.x, e.mapPoint.y, map.spatialReference);


line.addPath([point1, point2]);

map.graphics.add(new Graphic(point1, pointSymbol));


map.graphics.add(new Graphic(point2, pointSymbol));
map.graphics.add(new Graphic(line, lineSymbol));

var template = landusePointLayer.templates[0];
var newAttributes = lang.mixin({}, template.prototype.attributes);
var newGraphic = new Graphic(point2, null, newAttributes);
landusePointLayer.applyEdits([newGraphic], null, null);


var template1 = landuseLineLayer.templates[0];
var newAttributes = lang.mixin({}, template1.prototype.attributes);
var newGraphicss = new Graphic(line, null, newAttributes);
landuseLineLayer.applyEdits([newGraphicss], null, null);
}
else {

var getX = line.paths[pathCount - 1][line.paths[pathCount - 1].length - 1][0],
getY = line.paths[pathCount - 1][line.paths[pathCount - 1].length - 1][1],
mapPointX = e.mapPoint.x, mapPointY = e.mapPoint.y;
var pointS = new Point(getX, getY, map.spatialReference);
var pointD = new Point(mapPointX, mapPointY, map.spatialReference);

line.addPath([pointS, pointD]);

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

 

map.graphics.add(new Graphic(pointS, pointSymbol));
map.graphics.add(new Graphic(pointD, pointSymbol));
map.graphics.add(new Graphic(line, pointSymbol));

var template1 = landusePointLayer.templates[0];
var newAttributes = lang.mixin({}, template1.prototype.attributes);
var newGraphic = new Graphic(pointD, null, newAttributes);
landusePointLayer.applyEdits([newGraphic], null, null);


var template1 = landuseLineLayer.templates[0];
var newAttributessss = lang.mixin({}, template1.prototype.attributes);
var newGraphicss = new Graphic(line, null, newAttributessss);
landuseLineLayer.applyEdits([newGraphicss], null, null);


}
}


});


</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:'headline'"
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="stateName" >
<input id="execute" type="button" value="Get Details">

<input id="ltext" type="button" value="Start LT Ext" />


</div>
</div>
</body>
</html>@@@#

 

 

Outcomes