return null;
}
IGeoResourceInfo info = resource.getInfo( new SubProgressMonitor(monitor, 50));
String srs = CRS.toSRS(info.getCRS());
TileSet tileset = new WMSTileSet();
ReferencedEnvelope bounds = info.getBounds();
if (bounds == null ) { //$NON-NLS-1$
WmsPlugin.log("Bounds required for TileSet definition", new NullPointerException("Bounds required for tileset definitio")); //$NON-NLS-1$
return null;
}
double minX = bounds.getMinimum(0);
double maxX = bounds.getMaximum(0);
double minY = bounds.getMinimum(1);
double maxY = bounds.getMaximum(1);
CRSEnvelope bbox = new CRSEnvelope(srs, minX, minY, maxX, maxY);
tileset.setBoundingBox(bbox);
tileset.setCoorindateReferenceSystem(srs);
Map<String, Serializable> properties = resource.getPersistentProperties();
Integer width = Integer.parseInt((String) properties.get(PreferenceConstants.P_TILESET_WIDTH));
Integer height = Integer.parseInt((String) properties.get(PreferenceConstants.P_TILESET_HEIGHT));
if (width == null) {
width = PreferenceConstants.DEFAULT_TILE_SIZE;
}
if (height == null) {
height = PreferenceConstants.DEFAULT_TILE_SIZE;
}
tileset.setWidth(width);
tileset.setHeight(height);
String imageType = (String) properties.get(PreferenceConstants.P_TILESET_IMAGE_TYPE);
if (imageType == null || "".equals(imageType)) { //$NON-NLS-1$
imageType = PreferenceConstants.DEFAULT_IMAGE_TYPE;
}
tileset.setFormat(imageType);
/*
* The layer ID
*/
tileset.setLayers(info.getName());
String scales = (String) properties.get(PreferenceConstants.P_TILESET_SCALES);
String resolutions = workoutResolutions(scales, new ReferencedEnvelope(bbox), width);
/*
* If we have no resolutions to try - we wont.
*/
if ("".equals(resolutions)) { //$NON-NLS-1$
WmsPlugin.log("Resolutions are required for TileSet generation", new ServiceNotFoundException()); //$NON-NLS-1$
return null;
}
tileset.setResolutions(resolutions);
/*
* The styles
*/
String style = ""; //$NON-NLS-1$
if (resource.canResolve(Layer.class)) {
Layer layer = resource.resolve(Layer.class, new SubProgressMonitor(monitor, 50));
StringBuilder sb = new StringBuilder(""); //$NON-NLS-1$
for( StyleImpl layerStyle : layer.getStyles() ) {
sb.append(layerStyle.getName()+","); //$NON-NLS-1$
}
style = sb.toString();
}
if (style.length()>0){
tileset.setStyles(style.substring(0, style.length()-1));
} else {
tileset.setStyles(style);
}
/*
* The server is where tiles can be retrieved
*/
tileset.setServer(server);
return tileset;
}
finally {
monitor.done();
}