try {
// Handle visible layerIds
int layerCount = map.getMapContext().getLayerCount();
for (int i = 0; i < layerCount; i++) {
MapLayer layer = map.getLayer(i).getMapLayer();
layer.setVisible(false);
}
List<String> visibleLayerIds = renderParam.getVisibleLayerIds();
HashMap<String, String> layerDefs = renderParam.getLayerDefs();
if (visibleLayerIds == null) {
visibleLayerIds = new ArrayList<String>();
for (int i = 0; i < layerCount; i++) {
visibleLayerIds.add(String.valueOf(i));
}
}
for (int i = 0, count = visibleLayerIds.size(); i < count; i++) {
int layerId = Integer.parseInt(visibleLayerIds.get(i));
MapLayer layer = map.getLayer(i).getMapLayer();
layer.setVisible(true);
// Handle layerDefs
String key = String.valueOf(layerId);
if (layerDefs != null && layerDefs.containsKey(key)) {
String def = layerDefs.get(key);
if (def != null && !"".equals(def)) {
try {
Filter filter = ECQL.toFilter(def);
DefaultQuery query = new DefaultQuery();
query.setFilter(filter);
layer.setQuery(query);
} catch (Exception e) {
StringBuilder sb = new StringBuilder();
sb.append(ResourceBundleManager
.getResourceBundleMapServiceLog()
.getString("ERROR.LAYER_DEFS"));
sb.append("<");
sb.append(serviceName);
sb.append("-");
sb.append(String.valueOf(layerId));
sb.append(">");
logger.error(sb.toString(), e);
}
} else {
layer.setQuery(Query.ALL);
}
}
}
MapImage mapImage = map.render(renderParam);