AnsweredAssumed Answered

Adding feature layer to existing web map

Question asked by Dean.Wilson7232 on Mar 4, 2019
Latest reply on Apr 16, 2019 by Dean.Wilson7232

I'm having an issue adding a feature layer to an existing webmap.  Here's what I'm trying to accomplish.

 

I'm building a feature layer from a feature collection.  The attributes for the feature collection is coming out of a different service then arcgis server, (just a database table).  When building up the feature collection, It keeps shooting me in the foot saying no object id.  So I went ahead and told it to use a different field for the object id. here's a code snippet of my feature collection:

var featureCollection = {
"layerDefinition": null,
"featureSet": {
"features": [],
"geometryType": "esriGeometryPolygon"
}
};

featureCollection.layerDefinition = {
"geometryType": "esriGeometryPolygon",
"objectIdField": "accountNumber",
"fields": [{
"name":"routingNumber",
"alias": "Routing Number",
"type":"esriFieldTypeString"
},
{
"name":"accountNumber",
"alias": "Account Number",
"type":"esriFieldTypeInteger"
},
{
"name":"sidwellNumber",
"alias": "Parcel Number",
"type":"esriFieldTypeString"
}],
};

 

Now I'm getting/building up the attributes and adding them to the features array with these methods:

var featureLayer = new FeatureLayer(featureCollection,{
id: 'Ratio Viewer Results',
mode: FeatureLayer.MODE_ONDEMAND,
infoTemplate: new PopupTemplate({
accountNumber: "{accountNumber}",
routingNumber: "{routingNumber}"
})
});

this.map.on("layer-add-result", function(){
requestLayerData();
});

this.map.addLayer(featureLayer);

featureLayer.on("edits-complete", function(results){
console.log("Edits complete results: ", results);
});

function requestLayerData(){
request.post("URL to service", {
data: JSON.stringify(searchParams),
headers: {
"Content-Type": "application/json"
},
handleAs: 'json'
}).then(requestSucceeded)
.catch(requestFailed);
}

function requestSucceeded(response){
var features = [];

arrayUtils.forEach(response, function(item){
var attributes = {
"accountNumber": item.accountNumber,
"routingNumber": item.routingNumber,
"sidwellNumber": item.sidwellNumber,
};
var geometryQuery = new Query();
var geometryQueryTask = new QueryTask("URL to arcgis service");
geometryQuery.where = "MACCT = " + item.accountNumber;
geometryQuery.returnGeometry = true;
geometryQueryTask.execute(geometryQuery)
.then(function(geoData){
var geometry = {
"geometry": geoData.features[0].geometry,
"symbol": {
"color":[
0,
0,
0,
64
],
"outline":{
"color":[
0,
0,
0,
255
],
"width":1,
"type":"esriSLS",
"style":"esriSLSSolid"
},
"type":"esriSFS",
"style":"esriSFSSolid"
}
};

var graphic = new Graphic(geometry);
graphic.setAttributes(attributes);
console.log(graphic);
features.push(graphic);
}, function(error){
console.log("Error in feature set request: ", error);
});
});
featureLayer.applyEdits(features, null, null);
}

function requestFailed(error){
console.log("Main Request errored: ", error);
}

 

 

and when I add the callback function to applyEdits, the results there are blank. Plus i have the edit-complete event hooked to this feature layer, but it doesn't fire at all. Thoughts?  Thanks in advance!

 

-Dean

 

UPDATE -

 

It looks like it's being added as a graphics layer and not a feature layer?  when I look at the map object, this layer isn't in the list of layerIds, but it's in the list of graphic layers.  Not what I want.  Any ideas?

Outcomes