Hi all,
I am trying to update a textlayer (graphiclayer) after applyedits are done. I am thinking that I should remove the original textlayer to replace it with the new textlayer updated. So in my code I first remove the original textlayer and add it back but it the layer it adds seems to be blank. In my console.log, however, it is populated. I am not sure what I am doing wrong. Any idea?
sworkers.applyEdits(null, newGraArr, null, function () {
map.removeLayer(textLayer);
var arraynames = [];
console.log("Parcel updated!");
$("#body").empty();
$("#body2").empty();
//Query auto complete
var queryTaskauto = new QueryTask("http://services.arcgis.com/UHg8l1wC48WQyDSO/arcgis/rest/services/U64gI/FeatureServer/0");
var queryauto = new Query();
queryauto.returnGeometry = false;
queryauto.outFields = ["*"];
queryauto.where = "objectId > 0";
var textLayernew = new GraphicsLayer();
queryTaskauto.execute(queryauto, function (results){
$('table tbody').empty();
//parse results and add to autocomplete widget
//parse results and add to autocomplete widget
arrayUtil.forEach(results.features, function(value, index){
var pointnew = value.geometry;
arraynames.push(value.attributes.f3);
var arraynew = value.attributes.f3;
if (arraynew === null){
console.log("Dont split");
} else {
var words = arraynew.split(' ');
var textnew = '';
$.each(words, function () {
textnew += this.substring(0, 1);
});
var font = new Font(
"10pt",
Font.ALIGN_START,
Font.STYLE_NORMAL,
Font.VARIANT_NORMAL,
Font.WEIGHT_BOLD,
"Helvetica"
);
var textSymbol2 = new TextSymbol(
textnew,
font,
new Color("#000000")
);
textLayernew.add(new Graphic(pointnew, textSymbol2));
console.log(textnew);
console.log(words);
//Add the layers to the map
}
});
map.addLayer(textLayernew);
var counted = [], counter = []; var concat = [counted, counter], table = $('table tbody');
var i = 0, j = 0, k = 0;
while (k < arraynames.length) {
if (counted.indexOf(arraynames[k]) < 0) {
counted[i] = arraynames[k];
counter[i] = 0;
for (j = 0; j < arraynames.length; j++) {
if (counted[i] == arraynames[j]) {
counter[i]++;
}
}
i++;
} else {
k++;
}
}
console.log(counted);
console.log(counter);
//Convert rows to columns
var r = concat[0].map(function(col, i) {
return concat.map(function(row) {
return row[i];
});
});
$("#sidepanel").show();
table.innerHTML += '<th>' + 'Name' +'</th>' + '<th>' + 'Count' +'</th>'
//Add data to table
r.forEach(function(e) {
table.innerHTML += '<tr><td>' + e[0] + '</td><td>' + e[1] + '</td></tr>'
});
});
},function (error) {
console.log("Features not updated! ", error);
});
});
Solved! Go to Solution.
Nevermind, This was my issue. I forgot to return the geometry.
It should have been:
queryauto.returnGeometry = true;
instead of:
queryauto.returnGeometry = false;
Nevermind, This was my issue. I forgot to return the geometry.
It should have been:
queryauto.returnGeometry = true;
instead of:
queryauto.returnGeometry = false;