Robert,
Here is my code:
startup: function() {
this.inherited(arguments);
var map = this.map;
var featureLayer;
var featureCollection = {
"layerDefinition": null,
"featureSet": {
"features": [],
"geometryType": "esriGeometryPoint"
}
};
featureCollection.layerDefinition = {
"geometryType": "esriGeometryPoint",
"objectIdField": "ObjectID",
"drawingInfo": {
"renderer": {
"type": "simple",
"symbol": {
"type": "esriPMS",
"url": "images/carElt.png",
"contentType": "image/png",
"width": 15,
"height": 15
}
}
},
"fields": [{
"name": "ObjectID",
"alias": "ObjectID",
"type": "esriFieldTypeOID"
}, {
"name": "car_spz",
"alias": "Vozidlo (SPZ)",
"type": "esriFieldTypeString"
}, {
"name": "Locality",
"alias": "Lokalita",
"type": "esriFieldTypeString"
}, {
"name": "Age",
"alias": "Stáří",
"type": "esriFieldTypeString"
}]
};
var popupTemplate = new PopupTemplate({
title: "{Vozidlo (SPZ)}",
});
featureLayer = new FeatureLayer(featureCollection, {
id: 'carPosition',
infoTemplate: popupTemplate
});
featureLayer.on("click", function(evt) {
map.infoWindow.setFeatures([evt.graphic]);
});
map.on("layers-add-result", function(results) {
requestCar();
});
map.addLayers([featureLayer]);
function requestCar() {
var requestHandle = esriRequest({
url: "http://server.domain.cz/ws/?cmd=getrealtimevehiclelist&auser=carposition&apass=0dotlE&outproj=JTSK&r...",
handleAs: "json"
});
requestHandle.then(requestSucceeded, requestFailed);
}
function requestSucceeded(response, io) {
var features = [];
array.forEach(response.response.resultitems, function(item) {
var attr = {};
attr["car_spz"] = item.fullname;
attr["Locality"] = item.locality;
attr["Age"] = item.age;
var geometry = new Point({"x":item.position.x,"y":item.position.y,"spatialReference":{"wkid":5514}});
var graphic = new Graphic(geometry);
graphic.setAttributes(attr);
features.push(graphic);
});
console.log(features)
featureLayer.applyEdits(features, null, null, function (add){
array.forEach(add, function (a){
console.log("success")
console.log(a.status)
})
}, function (error){
console.log("error")
console.log(error)
});
}
function requestFailed(error) {
console.log('failed');
}
}
the features object is after forEach loop successfully filled. ApplyEdits goes through a function not error function but the feature layer remains empty.