HOW TO
When you do a query by putting a Filter on a map layer, you are limiting the returned records to only those satisfying the query. You may also want to limit the returned fields to only those that are of interest to you. The way to do this is to call Filter.addSubField() and pass the names of the fields desired, as in the following code:
Code:
filter.addSubField("AREA");
filter.addSubField("STATE_FIPS");
filter.setWhereExpression("AREA =0.23612");
tLayer.setFilterObject(filter);
Code:
String[] subfields={"AREA","STATE_FIPS"};
filter.addSubField(subfields[0]);
filter.addSubField(subfields[1]);
...
tLayer.setFilterObject(filter);
Code:
out.println("<table border='1'><tr>");
for (int j=0; j<subfields.length; j++) {
out.println("<td>"+subfields[j] + "</td>");
}
out.println("</tr>");
for (int i=0; i < tLayer.getRecordset().getCount(); i++) {
out.println("<tr>");
for (int j=0; j<subfields.length; j++) {
out.println("<td>"+tLayer.getRecordset().getRecords(i).getFieldValue(j) + "</td>");
}
}
out.println("</tr></td></table>");
Note:
1. The order of the fields in the returned recordset is fixed, so they're in the same order as they appear in the original map service. So even if your code is like:
Code:
filter.addSubField("STATE_FIPS");
filter.addSubField("AREA);
Get help from ArcGIS experts
Download the Esri Support App