Hello. I'm developing with JS 2D API 3.24 in WAB 2.8.
I'm trying to make a New FeatureLayer which is compound of polylines making from point geometries as result of a Query against a FeatureLayer in my server. This runs ok an if I create a GraphicsLayer and adds it to my map, I can see the graphics correctly.
The problem begins when I try to create a FeatureLayer with this geometries. I receive the next message in the javascript console (as info in blue (chrome) and not as error):
esri.layers.FeatureLayer: unable to find '[object Object],[object Object],[object Object]' field in the layer 'fields' information [url: ]
There are 3 '[object Object]' because I'm defining 3 fields in featureCollectionObject.fields. There is strikingly a reference to a "layer fields information".
This is the code for creating the featureLayer:
_crearLayerVectores: function(graficos){
var featureCollectionObject = {
layerDefinition:{
geometryType: "esriGeometryPolyline",
objectIdField:"OBJECTID",
fields:[{
name: "OBJECTID", alias: "OBJECTID", type: "esriFieldTypeOID"
},{
name: "FechaFrom", alias: "FechaFrom", type: "esriFieldTypeDate"
},{
name: "FechaTo", alias: "FechaTo", type: "esriFieldTypeDate"
}]
},
featureset:{
features: [graficos],
geometryType: "esriGeometryPolyline"
}
}
var featureLayerOptions = {
mode: FeatureLayer.MODE_SNAPSHOT,
outFields:[featureCollectionObject.layerDefinition.fields]
}
var vectores = new FeatureLayer(featureCollectionObject, featureLayerOptions);
vectores.title = this.nls.nombreCapaGenerada + this._campo + " = " + this._discriminador;
var sLineSymbol = this._obtenerSimpleLineSymbol();
var renderer = new SimpleRenderer(sLineSymbol);
vectores.setRenderer(renderer);
this.map.addLayer(vectores);
},
To improve understanding of code, the graphics are generated like this:
padre = this;
.
.
.
queryTask.execute(query, function(results){
for(i = 0; i < results.features.length - 1; i++){
var puntoFrom = results.features[i];
var puntoTo = results.features[i+1];
var geomPolyLine = new Polyline(capa.spatialReference);
geomPolyLine.addPath([[puntoFrom.x, puntoFrom.y],[puntoTo.x, puntoTo.y]]);
var atributos ={};
atributos["OBJECTID"] = i + 520;
atributos["FechaFrom"] = puntoFrom.attributes[padre._campoFecha];
atributos["FechaTo"] = puntoTo.attributes[padre._campoFecha];
var graficoVector = new Graphic({
geometry:geomPolyLine,
attributes: atributos
});
graficosVectores.push(graficoVector);
}
padre._crearLayerVectores(graficosVectores);
//padre._crearGraphicLayerVectores(graficosVectores); --> runs ok
});
I have also tried this. It doesn't give any warning or error in the javascript console, but it doesn't draw anything.
Differences:
In featureCollection.featureSet.features set to [] (empty array) (line 5)
Graphics are entered with: featureLayer.applyEdits() (line 34)
Following this: Create a feature layer based on a feature collection example
_crearLayerVectores: function(graficos){
var featureCollection ={
"layerDefinition": null,
"featureSet":{
"features": [],
"geometryType": "esriGeometryPolyline"
}
};
featureCollection.layerDefinition = {
"geometryType": "esriGeometryPolyline",
"objectIdField":"OBJECTID",
"fields":[{
"name": "OBJECTID", "alias": "OBJECTID", "type": "esriFieldTypeOID"
},{
"name": "FechaFrom", "alias": "FechaFrom", "type": "esriFieldTypeInteger"
},{
"name": "FechaTo", "alias": "FechaTo", "type": "esriFieldTypeInteger"
}]
};
var vectores = new FeatureLayer(featureCollection, {
id: this.nls.nombreCapaGenerada + this._campo + " = " + this._discriminador
});
vectores.title = this.nls.nombreCapaGenerada + this._campo + " = " + this._discriminador;
var sLineSymbol = this._obtenerSimpleLineSymbol();
var renderer = new SimpleRenderer(sLineSymbol);
vectores.setRenderer(renderer);
this.map.addLayer(vectores);
vectores.applyEdits(graficos, null, null);
this.jimuButtonBorrarCapas.style.visibility = "visible";
},
I hope that someone will can help me.
Best regards.
I hope this can help you. It's with feature layer with grahics layer I found limitations
.......
}
Hello. First of all, thank you for your reply.
Whern you say:
It's with feature layer with grahics layer I found limitations
I don't sure if I'm understanding you: The code wich you have posted is functional for you with FeatureLayer but you have problems with GraphicsLayer?.
If is that correct, I can help you with GraphicLayer.
This is the way in which I make the GraphicsLayer: "graficos" is an array of esri/Graphic
_crearGraphicLayerVectores: function(graficos){
var vectoresGraphicsLayer = new GraphicsLayer();
vectoresGraphicsLayer.title = this.nls.nombreCapaGenerada + this._capasGeneradas.length;
this.map.addLayer(vectoresGraphicsLayer);
this._capasGeneradas.push(vectoresGraphicsLayer);
for(i=0; i < graficos.length; i++){
var sLineSymbol = this._obtenerSimpleLineSymbol();
graficos[i].setSymbol(sLineSymbol);
vectoresGraphicsLayer.add(graficos[i]);
}
var extent = GraphicsUtils.graphicsExtent(graficos);
this.map.setExtent(extent.expand(1.20));
},