}
final Style layerStyle = styles[i];
final Filter layerFilter = filters[i];
final MapLayer layer;
int layerType = mapLayerInfo.getType();
if (layerType == MapLayerInfo.TYPE_REMOTE_VECTOR) {
final SimpleFeatureSource source = mapLayerInfo.getRemoteFeatureSource();
layer = new DefaultMapLayer(source, layerStyle);
layer.setTitle(mapLayerInfo.getRemoteFeatureSource().getSchema().getTypeName());
final Query definitionQuery = new Query(source.getSchema().getTypeName());
definitionQuery.setFilter(layerFilter);
definitionQuery.setVersion(featureVersion);
int maxFeatures = request.getMaxFeatures() != null ? request.getMaxFeatures()
: Integer.MAX_VALUE;
definitionQuery.setMaxFeatures(maxFeatures);
layer.setQuery(definitionQuery);
mapContext.addLayer(layer);
} else if (layerType == MapLayerInfo.TYPE_VECTOR) {
FeatureSource<? extends FeatureType, ? extends Feature> source;
// /////////////////////////////////////////////////////////
//
// Adding a feature layer
//
// /////////////////////////////////////////////////////////
try {
source = mapLayerInfo.getFeatureSource(true);
// NOTE for the feature. Here there was some code that
// sounded like:
// * get the bounding box from feature source
// * eventually reproject it to the actual CRS used for
// map
// * if no intersection, don't bother adding the feature
// source to the map
// This is not an optimization, on the contrary,
// computing the bbox may be
// very expensive depending on the data size. Using
// sigma.openplans.org data
// and a tiled client like OpenLayers, it dragged the
// server to his knees
// and the client simply timed out
} catch (IOException exp) {
if (LOGGER.isLoggable(Level.SEVERE)) {
LOGGER.log(Level.SEVERE, new StringBuffer("Getting feature source: ")
.append(exp.getMessage()).toString(), exp);
}
throw new ServiceException("Internal error", exp);
}
layer = new FeatureSourceMapLayer(source, layerStyle);
layer.setTitle(mapLayerInfo.getFeature().getPrefixedName());
final Query definitionQuery = new Query(source.getSchema().getName().getLocalPart());
definitionQuery.setVersion(featureVersion);
definitionQuery.setFilter(layerFilter);
if (viewParams != null) {
definitionQuery.setHints(new Hints(Hints.VIRTUAL_TABLE_PARAMETERS, viewParams.get(i)));
}
// check for startIndex + offset
final Integer startIndex = request.getStartIndex();
if (startIndex != null) {
QueryCapabilities queryCapabilities = source.getQueryCapabilities();
if (queryCapabilities.isOffsetSupported()) {
// fsource is required to support
// SortBy.NATURAL_ORDER so we don't bother checking
definitionQuery.setStartIndex(startIndex);
} else {
// source = new PagingFeatureSource(source,
// request.getStartIndex(), limit);
throw new ServiceException("startIndex is not supported for the "
+ mapLayerInfo.getName() + " layer");
}
}
int maxFeatures = request.getMaxFeatures() != null ? request.getMaxFeatures()
: Integer.MAX_VALUE;
definitionQuery.setMaxFeatures(maxFeatures);
layer.setQuery(definitionQuery);
mapContext.addLayer(layer);
} else if (layerType == MapLayerInfo.TYPE_RASTER) {
// /////////////////////////////////////////////////////////
//
// Adding a coverage layer
//
// /////////////////////////////////////////////////////////
final AbstractGridCoverage2DReader reader = (AbstractGridCoverage2DReader) mapLayerInfo
.getCoverageReader();
if (reader != null) {
// get the group of parameters tha this reader supports
GeneralParameterValue[] readParameters = wms.getWMSReadParameters(request,
mapLayerInfo, layerFilter, reader, false);
try {
try {
layer = new DefaultMapLayer(FeatureUtilities.wrapGridCoverageReader(
reader, readParameters), layerStyle);
} catch (Exception e) {
throw new RuntimeException(e);
}
layer.setTitle(mapLayerInfo.getCoverage().getPrefixedName());
layer.setQuery(Query.ALL);
mapContext.addLayer(layer);
} catch (IllegalArgumentException e) {
if (LOGGER.isLoggable(Level.SEVERE)) {
LOGGER.log(
Level.SEVERE,
new StringBuilder("Wrapping GC in feature source: ").append(
e.getLocalizedMessage()).toString(), e);
}
throw new ServiceException(
"Internal error : unable to get reader for this coverage layer "
+ mapLayerInfo);
}
} else {
throw new ServiceException(new StringBuffer(
"Internal error : unable to get reader for this coverage layer ")
.append(mapLayerInfo.toString()).toString());
}
} else if (layerType == MapLayerInfo.TYPE_WMS) {
WMSLayerInfo wmsLayer = (WMSLayerInfo) mapLayerInfo.getResource();
WebMapServer wms = wmsLayer.getStore().getWebMapServer(null);
Layer gt2Layer = wmsLayer.getWMSLayer(null);
// see if we can merge this layer with the previous one
boolean merged = false;
if (mapContext.getLayerCount() > 0) {
MapLayer lastLayer = mapContext.getLayer(mapContext.getLayerCount() - 1);
if (lastLayer instanceof WMSMapLayer) {
WMSMapLayer lastWMS = (WMSMapLayer) lastLayer;
WebMapServer otherWMS = lastWMS.getWebMapServer();
if (otherWMS.equals(wms)) {
lastWMS.addLayer(gt2Layer);