int maxFeatures,
MapLayerInfo layerInfo) throws Exception {
final int x = request.getXPixel();
final int y = request.getYPixel();
WMSLayerInfo info = (WMSLayerInfo) layerInfo.getResource();
WebMapServer wms = info.getStore().getWebMapServer(null);
Layer layer = info.getWMSLayer(null);
CoordinateReferenceSystem crs = request.getGetMapRequest().getCrs();
if(crs == null) {
// use the native one
crs = info.getCRS();
}
ReferencedEnvelope bbox = new ReferencedEnvelope(request.getGetMapRequest().getBbox(), crs);
int width = request.getGetMapRequest().getWidth();
int height = request.getGetMapRequest().getHeight();
// we can cascade GetFeatureInfo on queryable layers and if the GML mime type is supported
if (!layer.isQueryable()) {
return null;
}
List<String> infoFormats;
infoFormats = wms.getCapabilities().getRequest().getGetFeatureInfo().getFormats();
if (!infoFormats.contains("application/vnd.ogc.gml")) {
return null;
}
// the wms layer does request in a CRS that's compatible with the WMS server srs
// list,
// we may need to transform
WMSMapLayer ml = new WMSMapLayer(wms, layer);
// delegate to the web map layer as there's quite a bit of reprojection magic
// code
// that we want to be consistently reproduced for GetFeatureInfo as well
final InputStream is = ml.getFeatureInfo(bbox, width, height, x, y,
"application/vnd.ogc.gml", maxFeatures);
List<FeatureCollection> results = null;
try {
Parser parser = new Parser(new WFSConfiguration());
parser.setStrict(false);
Object result = parser.parse(is);
if (result instanceof FeatureCollectionType) {
FeatureCollectionType fcList = (FeatureCollectionType) result;
results = fcList.getFeature();
List<FeatureCollection> retypedResults =
new ArrayList<FeatureCollection>(results.size());
// retyping feature collections to replace name and namespace
// from cascading server with our local WMSLayerInfo
for (Iterator it = results.iterator(); it.hasNext();) {
SimpleFeatureCollection fc = (SimpleFeatureCollection) it.next();
SimpleFeatureType ft = fc.getSchema();
SimpleFeatureTypeBuilder builder = new SimpleFeatureTypeBuilder();
builder.init(ft);
builder.setName(info.getName());
builder.setNamespaceURI(info.getNamespace().getURI());
FeatureCollection rfc =
new ReTypingFeatureCollection(fc, builder.buildFeatureType());
retypedResults.add(rfc);