Hello there,
Im trying to add a new feature in my applyedits but when i get the response it says success.
If i look at the service , it doesnt add the new feature.
What im doing wrong?
Here is my code:
on(updatebtn, "click", function(click){
var myAttributes = {
id_luminaria: document.getElementById('id_Luminaria').value,
id_nodo: document.getElementById('id_Nodo').value,
tipo_cnx: document.getElementById('tipo_Conexion').value,
tipo: document.getElementById('tipo_Lampara').value,
potencia: document.getElementById('tipo_Potencia').value,
propiedad: document.getElementById('tipo_Propiedad').value,
obs: document.getElementById('tipo_Observaciones').value,
rotulo: document.getElementById('id_Rotulo').value,
eliminar: 'modificar',
corregido: 'revisar'
};
var myAttributesGraphic = new Graphic(null,null,myAttributes);
myLayer.applyEdits([myAttributesGraphic],null,null,function(adds,updates,deletes){
console.log("its adding " + agrega);
},function error(err){
console.log("there is an error" + err);
});
});
Solved! Go to Solution.
Ok, i finally got the problem. It is actually adding things on the service, but for some configuration that i had on the table it didnt show.
The code is working and its the following:
on(map,"click",function(e){ var extentGeom = pointToExtent(map,e.mapPoint,10) var url = "...FeatureServer/1"; var queryTask = new QueryTask(url); var query = new Query(); query.where = "COMUNA='PANQUEHUE'"; query.returnGeometry=true; query.outFields = ["*"]; query.token=token; query.geometry = extentGeom; queryTask.execute(query,obtenerDatos); function obtenerDatos(featureSet){ for (var i = 0; i < featureSet.features.length; i++) { document.getElementById('id_Luminaria').value = featureSet.features[0].attributes['ID_LUMINARIA']; document.getElementById('tipo_Observaciones').value = featureSet.features[0].attributes['OBSERVACION']; document.getElementById('tipo_comuna').value = featureSet.features[0].attributes['COMUNA']; myGraphic = featureSet.features[0].geometry; console.log(featureSet.features); } } }); on(actualizar, "click", function(click){ //console.log("clickeando"); var myAttributes = { id_luminaria: parseInt(document.getElementById('id_Luminaria').value), Comuna: document.getElementById('tipo_comuna').value, /*id_nodo: document.getElementById('id_Nodo').value, tipo_cnx: document.getElementById('tipo_Conexion').value, tipo: document.getElementById('tipo_Lampara').value, potencia: document.getElementById('tipo_Potencia').value, propiedad: document.getElementById('tipo_Propiedad').value, rotulo: document.getElementById('id_Rotulo').value, */ obs: document.getElementById('tipo_Observaciones').value, eliminar: 'modificar', corregido: 'revisar' }; //console.log(myAttributes.obs); var features = []; var graphic = new Graphic(myGraphic); graphic.setAttributes(myAttributes); features.push(graphic); // var myAttributesGraphic = new Graphic(myGraphic,null,myAttributes); // console.log(features); myLayer.applyEdits(features,null,null,function(adds){ console.log("its adding"); console.log(adds); },function error(err){ console.log("Theres an error" + err); }); });
Evelyn,
Was it your intention to have no geometry for your added graphic? Your sample above sets the geometry to null, perhaps that is the problem?
Regards,
Tom
Actually no. But is there any example on how to do it propertly?
TY
Enviado desde Correo de Windows
De: Tom Sellsted
Enviado el: viernes, 26 de febrero de 2016 14:55
Para: Evelyn Elena Hernández Riquelme
GeoNet
Applyedits bug?
reply from Tom Sellsted in ArcGIS API for JavaScript - View the full discussion
Evelyn,
Was it your intention to have no geometry for your added graphic? Your sample above sets the geometry to null, perhaps that is the problem?
Regards,
Tom
Reply to this message by replying to this email, or go to the message on GeoNet
Start a new discussion in ArcGIS API for JavaScript by email or at GeoNet
Following Applyedits bug? in these streams: Inbox
This email was sent by GeoNet because you are a registered user.
You may unsubscribe instantly from GeoNet, or adjust email frequency in your email preferences
Evelyn,
Could you share more of your code? This would enable me to see where the geometry might be that you would want to use.
Here is some sample code that I use to applyEdits to some feature layers containing points and lines. There are separate functions that handle the success or error when using the applyEdits. My personal preference, I think it is easier to read.
function addNewLSP(evt) { // update lines and points pointFeatureLayer.applyEdits([graphicLive, graphicShop, graphicPlay], null, null, pointsUpdated, errorOnUpdate); lineFeatureLayer.applyEdits([graLinePlay, graLineShop], null, null, linesUpdated, errorOnUpdate); } function pointsUpdated(evt) { alert("Points added"); } function linesUpdated(evt) { alert("Lines added"); } function errorOnUpdate(evt) { alert("Error updating Live, Shop and Play"); }
I hope this will help you!
Best Regards,
Tom
var myLayer = new FeatureLayer("…/FeatureServer/0");
myLayer.setDefinitionExpression("COMUNA='PANQUEHUE'");
//map.addLayer(myLayer);
var myLayerLum = new FeatureLayer("../1");
myLayerLum.setDefinitionExpression("COMUNA='PANQUEHUE'");
map.addLayer(myLayerLum);
function pointToExtent(map, point,toleranceInPixel) {
//calculate map coords represented per pixel
var pixelWidth = map.extent.getWidth() / map.width;
//calculate map coords for tolerance in pixel
var toleraceInMapCoords = toleranceInPixel * pixelWidth;
//calculate & return computed extent
return new Extent( point.x - toleraceInMapCoords,
point.y - toleraceInMapCoords,
point.x + toleraceInMapCoords,
point.y + toleraceInMapCoords,
map.spatialReference );
}
on(map,"click",function(e){
var extentGeom = pointToExtent(map,e.mapPoint,10)
var url = "../1";
var queryTask = new QueryTask(url);
var query = new Query();
query.where = "COMUNA='PANQUEHUE'";
query.returnGeometry=true;
query.outFields = ["*"];
query.token=token;
query.geometry = extentGeom;
queryTask.execute(query,obtenerDatos);
function obtenerDatos(featureSet){
for (var i = 0; i < featureSet.features.length; i++) {
document.getElementById('id_Luminaria').value = featureSet.features[0].attributes['ID_LUMINARIA'];
document.getElementById('tipo_Observaciones').value = featureSet.features[0].attributes['OBSERVACION'];
myGraphic = new Graphic(featureSet.features[0].geometry, null,null);
console.log(myGraphic);
}
}
});
on(actualizar, "click", function(click){
//console.log("clickeando");
var myAttributes = {
id_luminaria: document.getElementById('id_Luminaria').value,
id_nodo: document.getElementById('id_Nodo').value,
tipo_cnx: document.getElementById('tipo_Conexion').value,
tipo: document.getElementById('tipo_Lampara').value,
potencia: document.getElementById('tipo_Potencia').value,
propiedad: document.getElementById('tipo_Propiedad').value,
obs: document.getElementById('tipo_Observaciones').value,
rotulo: document.getElementById('id_Rotulo').value,
eliminar: 'modificar',
corregido: 'revisar'
};
//console.log(myAttributes.obs);
var myAttributesGraphic = new Graphic(myGraphic.geometry,null,myAttributes);
var agregar = ;
myLayer.applyEdits(agregar,null,null,function(adds,updates,deletes){
console.log("Está agregando " + adds);
},function error(err){
console.log("Hay un error" + err);
});
});
Enviado desde Correo de Windows
De: Tom Sellsted
Enviado el: viernes, 26 de febrero de 2016 21:00
Para: Evelyn Elena Hernández Riquelme
GeoNet
Applyedits bug?
reply from Tom Sellsted in ArcGIS API for JavaScript - View the full discussion
Evelyn,
Could you share more of your code? This would enable me to see where the geometry might be that you would want to use.
Here is some sample code that I use to applyEdits to some feature layers containing points and lines. There are separate functions that handle the success or error when using the applyEdits. My personal preference, I think it is easier to read.
function addNewLSP(evt) {
// update lines and points
pointFeatureLayer.applyEdits(, null, null, pointsUpdated, errorOnUpdate);
lineFeatureLayer.applyEdits(, null, null, linesUpdated, errorOnUpdate);
}
function pointsUpdated(evt) {
alert("Points added");
}
function linesUpdated(evt) {
alert("Lines added");
}
function errorOnUpdate(evt) {
alert("Error updating Live, Shop and Play");
}
I hope this will help you!
Best Regards,
Tom
Reply to this message by replying to this email, or go to the message on GeoNet
Start a new discussion in ArcGIS API for JavaScript by email or at GeoNet
Following Applyedits bug? in these streams: Inbox
This email was sent by GeoNet because you are a registered user.
You may unsubscribe instantly from GeoNet, or adjust email frequency in your email preferences
Evelyn,
You are on the right track. You must use an array for your graphics, even if it is just one. It will look like this:
var myAttributesGraphic = new Graphic(myGraphic.geometry, null, myAttributes); myLayer.applyEdits([myGraphic], null, null, function(evt) { console.log("Está agregando " + adds); }, function error(err) { console.log("Hay un error" + err); });
Best Regards,
Tom
Ok, i finally got the problem. It is actually adding things on the service, but for some configuration that i had on the table it didnt show.
The code is working and its the following:
on(map,"click",function(e){ var extentGeom = pointToExtent(map,e.mapPoint,10) var url = "...FeatureServer/1"; var queryTask = new QueryTask(url); var query = new Query(); query.where = "COMUNA='PANQUEHUE'"; query.returnGeometry=true; query.outFields = ["*"]; query.token=token; query.geometry = extentGeom; queryTask.execute(query,obtenerDatos); function obtenerDatos(featureSet){ for (var i = 0; i < featureSet.features.length; i++) { document.getElementById('id_Luminaria').value = featureSet.features[0].attributes['ID_LUMINARIA']; document.getElementById('tipo_Observaciones').value = featureSet.features[0].attributes['OBSERVACION']; document.getElementById('tipo_comuna').value = featureSet.features[0].attributes['COMUNA']; myGraphic = featureSet.features[0].geometry; console.log(featureSet.features); } } }); on(actualizar, "click", function(click){ //console.log("clickeando"); var myAttributes = { id_luminaria: parseInt(document.getElementById('id_Luminaria').value), Comuna: document.getElementById('tipo_comuna').value, /*id_nodo: document.getElementById('id_Nodo').value, tipo_cnx: document.getElementById('tipo_Conexion').value, tipo: document.getElementById('tipo_Lampara').value, potencia: document.getElementById('tipo_Potencia').value, propiedad: document.getElementById('tipo_Propiedad').value, rotulo: document.getElementById('id_Rotulo').value, */ obs: document.getElementById('tipo_Observaciones').value, eliminar: 'modificar', corregido: 'revisar' }; //console.log(myAttributes.obs); var features = []; var graphic = new Graphic(myGraphic); graphic.setAttributes(myAttributes); features.push(graphic); // var myAttributesGraphic = new Graphic(myGraphic,null,myAttributes); // console.log(features); myLayer.applyEdits(features,null,null,function(adds){ console.log("its adding"); console.log(adds); },function error(err){ console.log("Theres an error" + err); }); });
Evelyn,
I am glad to hear that you got it working. I don't see anywhere in your code where you are adding a new graphic to the map graphics layer. Clicking on the map alone doesn't automatically add a new graphic for the added feature. You would have to add code to add the graphic or refresh the feature layer on your map.
Best Regards,
Tom
Yes, but if you just move a little bit the featurelayer where u add the feature it automatically refreshes.
The logic that i was doing was: Getting the info from featurelayerA (graphic included) then, modify the info locally and add it to another featurelayerB with the same graphic feature just saved. (Cuz i dont want to modify the info from featurelayerA).
Anyways. Really thanks for your reply, it helped me a lot to figure out what i was doing wrong, or maybe not?
Evelyn,
If your feature layer is in on demand mode, it will refresh when you pan or zoom. If you want to see your new feature immediately, you could put a featureLayer.refresh() in your successful add function.
Glad you have things working!
Best Regards,
Tom