Hi,
I have created custom feature layer (polygon) , and able to add it in to the map . Now i am trying to show only few geometries , so i am using setDefinition expression but it is not working . Its shows all the features on the Map. Will this method work in custom feature layer ?
Solved! Go to Solution.
Mohan,
So the only way is to maintain a master array of all graphics and when you want to show just a subset of those based on an attribute you just clear your featureLayer and only add in the ones you need based on the attribute value. When you do not need a subset you just add the the graphics back in from the master graphics array.
Can you share you’re code on your extended setDefinitionExpression?
Hi Robert,
PFB code for the dynamic feature layer creation and DefinitiomExpression?
CreateFeatureLayer : function (featureset) {
var len = featureset.features.length;
var attributeObj = null;
var longi = null;
var lat =null;
var pt = null;
var feature =null;
var jsonFS = new Object();
jsonFS.geometryType = "esriGeometryPoint";
if (featureset.geometryType === 'esriGeometryPoint') {
renderer = new SimpleRenderer(new SimpleMarkerSymbol());
} else if (featureset.geometryType === 'esriGeometryMultipoint') {
renderer = new SimpleRenderer(new SimpleMarkerSymbol());
} else if (featureset.geometryType === 'esriGeometryPolyline') {
renderer = new SimpleRenderer(new SimpleLineSymbol());
} else if (featureset.geometryType === 'esriGeometryPolygon') {
renderer = new SimpleRenderer(new SimpleFillSymbol());
}
if (featureset.geometryType === 'esriGeometryPoint' || featureset.geometryType === 'esriGeometryMultipoint' || featureset.geometryType === 'esriGeometryPolyline') {
renderer.symbol.setColor(new esri.Color([0, 255, 255, 1]));
} else if (featureset.geometryType === 'esriGeometryPolygon') {
renderer.symbol.setColor(new esri.Color([0, 255, 255, 0.25]));
}
debugger;
var features = [];
var incomeData = getIncomeResult[1].split(",");
var panfromWS = getIncomeResult[0].split(",");
for (var i = 0; i < len; i++) {
panidFeature = "'" + featureset.features.attributes.pan_id + "'" ;
for (var j = 0; j < len; j++)
{
if (panidFeature == panfromWS
{
attributeObj = new Object();
attributeObj.objectid = featureset.features.attributes.FID;
attributeObj.name = "ssssssss";
attributeObj.address = "address";
attributeObj.pan_id = featureset.features.attributes.pan_id;
attributeObj.Income = incomeData
longi = featureset.features.geometry.x;
lat = featureset.features.geometry.y;
pt = new Point(longi,lat,this.map.spatialReference);
feature = new Object();
feature.attributes = attributeObj
feature.geometry = pt;
features.push(feature);
//break;
}
}
}
jsonFS.features = features;
var featureSet = new FeatureSet(jsonFS);
featureSet.spatialReference = featureset.spatialReference;
var infoTemplate = new InfoTemplate("${name}","NAME :${name}<br>ADDRESS :${address}<br>PAN_ID :${pan_id}<br>INCOME:${Income} Lakhs per annum");
var hsFeatureCollection = {
layerDefinition:{
"displayFieldName": "",
"geometryType": "esriGeometryPoint",
"spatialReference":
{
"latestWkid": 3857,
"wkid": 102100
},
"fields":[
{
"name": "objectid",
"type": "esriFieldTypeOID",
"alias": "objectid"
},
{
"name": "name",
"type": "esriFieldTypeString",
"alias": "name",
"length" : 50
},
{
"name": "address",
"type": "esriFieldTypeString",
"alias": "address",
"length" : 50
},
{
"name": "pan_id",
"type": "esriFieldTypeString",
"alias": "pan_id",
"length" : 255
},
{
"name": "Income",
"type": "esriFieldTypeInteger",
"alias": "Income"
},
{
"name": "shape",
"type": "esriFieldTypeGeometry",
"alias": "shape"
},
],
}, featureSet: featureSet,
"exceededTransferLimit": false
};
debugger;
var heatmapFeatureLayerOptions = {
mode: FeatureLayer.MODE_SNAPSHOT,
outFields: ["*"],
infoTemplate: infoTemplate,
id:"Income Heatmap"
};
heatMapInPutLyr = new FeatureLayer(hsFeatureCollection,heatmapFeatureLayerOptions);
var extent = graphicsUtils.graphicsExtent(featureSet.features);
this.map.setExtent(extent.expand(1.2));
heatMapInPutLyr.setDefinitionExpression("Income = 50000");
this.map.addLayer(heatMapInPutLyr);
}
Thanks,
Mohan
Mohan,
OK, I see you are not extending the FeatureLayer class, you are just using it. When creating a FeatureLayer from a FeatureCollection you are limited in the several ways (as outlined in the help). One of which is this:
Does not support queries that need to be performed on the server, e.g. queries with a where clause or non-extent based spatial queries.
So setDefinitionExpression is a affected by this limitation.
Thanks for the information Robert. Actually I am creating a layer with temporal data dynamically . The temporal information(population and Year) will come from the business table which is residing on some database(teradata) and spatial data coming from other data base. So i am joining spatial and business data and creating new feature layer (dynamically) . So my final layer(dynamic) will be look like below.
shape state_name population(coming from business table) year(coming from business table)
polygon TamilNadu 20000000 1990
polygon TamilNadu 30000000 1995
polygon TamilNadu 50000000 2000
I could not able to use esri time slider , because it says time property should be enabled in the map service . But in may case i am creating the custom dynamic layer so i could not able to use esri time slider.
So i am using dijit horizontalslider , based on the year selection in time slider i need to display corresponding geometry on the Map . So i thought of using setdefinition expression to filter out only the required year . But as you mentioned that also limitation in dynamic layer . Is there any approach to solve this issue or any suggestion .
Mohan,
So the only way is to maintain a master array of all graphics and when you want to show just a subset of those based on an attribute you just clear your featureLayer and only add in the ones you need based on the attribute value. When you do not need a subset you just add the the graphics back in from the master graphics array.
Thank you Robert
Don't forget to mark this question as answered by clicking on the "Correct Answer" link on the reply that answered your question.