}
if( !wmslayer.isQueryable() ){
return null;
}
// TODO: Fix wmslayer so we can ask who its "source" is.
final WebMapServer wms = layer.getResource( WebMapServer.class, null );
if( wms == null ) {
throw new IllegalArgumentException("Provided layer cannot resolve to a wms" ); //$NON-NLS-1$
}
String desiredFormat = desiredInfoFormat( wms );
if( desiredFormat == null ){
return null;
}
GetMapRequest getmap = wms.createGetMapRequest();
String code = BasicWMSRenderer2.findRequestCRS(
Collections.singletonList( wmslayer ), map.getViewportModel().getCRS(), map );
getmap.setBBox( bbox );
String srs = CRS.toSRS(bbox.getCoordinateReferenceSystem() );
//getmap.setSRS( code != null ? code : srs );
getmap.setProperty( GetMapRequest.LAYERS, wmslayer.getName() );
int width = map.getRenderManager().getMapDisplay().getWidth();
int height = map.getRenderManager().getMapDisplay().getHeight();
getmap.setDimensions(width, height);
//getmap.setSRS(code);
List<String> formats = wms.getCapabilities().getRequest().getGetMap().getFormats();
if (formats.contains("image/png")) { //$NON-NLS-1$
getmap.setProperty(GetMapRequest.FORMAT, "image/png"); //$NON-NLS-1$
} else if (formats.contains("image/gif")) { //$NON-NLS-1$
getmap.setProperty(GetMapRequest.FORMAT, "image/gif"); //$NON-NLS-1$
} else if (formats.contains("image/jpeg")) { //$NON-NLS-1$
getmap.setProperty(GetMapRequest.FORMAT, "image/jpeg"); //$NON-NLS-1$
} else if (formats.contains("image/bmp")) { //$NON-NLS-1$
getmap.setProperty(GetMapRequest.FORMAT, "image/bmp"); //$NON-NLS-1$
}
StyleImpl wmsStyle = (StyleImpl) layer.getStyleBlackboard().get(WMSStyleContent.WMSSTYLE);
if (wmsStyle != null) {
getmap.setProperty(GetMapRequest.STYLES, wmsStyle.getName());
}
else {
// supply an empty String as per UDIG-1507
getmap.setProperty(GetMapRequest.STYLES, "");
}
final GetFeatureInfoRequest request = wms.createGetFeatureInfoRequest( getmap );
request.setInfoFormat( desiredFormat );
request.setQueryPoint( centre.x, centre.y );
request.setQueryLayers( Collections.singleton( wmslayer ) );
LayerPointInfo info = new LayerPointInfo( layer ){
private GetFeatureInfoResponse response;
/** Lazy request */
protected GetFeatureInfoResponse getResponse() throws IOException {
if (this.response == null) {
try {
System.out.println(request.getFinalURL());
this.response = wms.issueRequest( request );
} catch (SAXException e) {
throw new IOException(
"Unable to parse the returned response from the server. Reason unknown."); //$NON-NLS-1$
}
}