I am using the ArcGIS JavaScript API 3.24 and trying to update a featureLayer via an HTML input form. Below is my code:
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>MyMap</title>
<link rel="stylesheet" href="https://js.arcgis.com/4.7/esri/css/main.css">
<script src="https://js.arcgis.com/4.7/"></script>
<style>
html,
body,
#map {
width:100%;
height:100%;
margin:0;
padding:0;
}
</style>
<script>
require([
"esri/Map",
"esri/views/MapView",
"esri/layers/FeatureLayer",
"esri/Graphic",
"esri/widgets/Search",
"esri/geometry/Point",
"dojo/dom",
"esri/geometry/SpatialReference",
"dojo/on",
"dojo/domReady!"
], function (
map,
FeatureLayer,
Graphic,
Search,
Point,
dom,
SpatialReference,
on
) {
featureLayer = new FeatureLayer({
url: "https://services8.arcgis.com/R1PAHHLiCM5plgJt/arcgis/rest/services/Somepoint/FeatureServer/0",
outFields: ["*"],
});
//for testing purpose
var extent = {
XMin: -5120763.26772284,
XMax: 2036.05706365815,
YMin: 6120763.26772284,
YMax: 19997963.9429363,
};
var getLongitude = function() {
return (Math.random() * extent.XMax) + extent.XMin;
};
var getLatitude = function() {
return (Math.random() * extent.YMax) + extent.YMin;
};
on(document.getElementById('edit-save'), 'click', function() {
//create the feature
var feature = new Graphic();
var geometry = new Point({
x: getLongitude(),
y: getLatitude(),
spatialReference: new SpatialReference({wkid: 28354})
});
feature.geometry = geometry;
feature.attributes = {
"Name": document.getElementById('Name').value,
"Id": document.getElementById('Id').value
};
//add to the featureLayer
var promise = featureLayer.applyEdits({
addFeatures: [feature]
});
promise.then(function(res){
console.log('new OBJECTID:', res.addFeatureResults[0].objectId);
}, function(err){
console.error(err);
});
});
});
</script>
</head>
<body class="">
<div id="" class="">
<div class="">
<div class="">
<div class="">
<h1 class="">Edit Information</h1>
</div>
<div class="">
<form class="">
<div class="">
<label class="">ID</label>
<div class="">
<input type="text" class="" id="Id">
</div>
</div>
<div class="">
<label class="">Name</label>
<div class="">
<input type="text" class="" id="Name">
</div>
</div>
</form>
</div>
<div class="">
<button type="button" class="" id="edit-save">Save Changes</button>
</div>
</div>
</div>
</div>
</body>
</html>
...
with the lines from "your" code