Hi all,I'm trying to create a feature layer from a feature collection (json, converted from shapefile) but it's not showing on the map. If I log the feature layer to the console I can see it contains the same number of features as the original json. In the console, I can navigate through the features and see the geometries and attributes in the tree. Problem is the features are not being drawn on the map for some reason. Does anyone have any ideas? My code is below:
var layerDefinition = {
"geometryType" : "esriGeometryPolygon",
"objectIdField" : "FID",
"drawingInfo" : {
"renderer" : {
"type" : "simple"
}
},
"fields" : [{
"name" : "FID",
"alias" : "ID",
"type" : "esriFieldTypeOID"
}, {
"name" : "ZONE_",
"alias" : "Zone",
"type" : "esriFieldTypeString"
}, {
"name" : "FSR",
"alias" : "FSR",
"type" : "esriFieldTypeDouble"
}]
};
var featureCollection = {
"layerDefinition" : layerDefinition,
"featureSet" : {
"features" : [],
"geometryType" : "esriGeometryPolygon"
}
};
//define a popup template
var popupTemplate = new PopupTemplate({
title : "{ZONE_}",
description : "{FSR}"
});
//create a feature layer based on the feature collection
featureLayer = new FeatureLayer(featureCollection, {
id : "ufmLayer",
infoTemplate : popupTemplate,
outFields : ["*"]
});
map.on("layers-add-result", function(results) {
requestData();
});
map.addLayers([featureLayer]);
function requestData() {
var requestHandle = esriRequest({
url : "http://<server>/ResearchAndAnalysis/UFM_Edit/data/RockdaleUFMBase_min.json",
callbackParamName : "jsoncallback"
});
requestHandle.then(requestSucceeded, requestFailed);
}
function requestSucceeded(response, io) {
//loop through the items and add to the feature layer
var features = response.features;
alert(features.length);
var ufmData = [];
dojo.forEach(features, function(feature) {
var attr = {};
attr["ZONE_"] = feature.attributes.ZONE_;
attr["FSR"] = feature.attributes.FSR;
var geometry = new Polygon(feature.geometry);
var graphic = new Graphic(geometry);
graphic.setAttributes(attr);
ufmData.push(graphic);
});
featureLayer.applyEdits(ufmData, null, null, addSucceeded, addFailed);
console.log(featureLayer);
}
function requestFailed(error) {
console.log(error);
}
function addFailed(error) {
console.log(error);
}
function addSucceeded() {
console.log("add succeeded");
}
Thanks very much for any help.Ed