if( monitor == null ) monitor = new NullProgressMonitor();
monitor.beginTask("TileSet generation", 100 );
try {
if (server == null ) { //$NON-NLS-1$
WmsPlugin.log("WebMapService required", new ServiceNotFoundException()); //$NON-NLS-1$
return null;
}
ServiceInfo serverInfo = server.getInfo();
URI serverURI = serverInfo.getSource();
String source = serverURI != null ? serverURI.toString() : null;
String version = server.getCapabilities().getVersion();
if (source == null || "".equals(source)) { //$NON-NLS-1$
WmsPlugin.log("GetCapabilities SERVICE is required", new ServiceNotFoundException()); //$NON-NLS-1$
return null;
}
if (version == null || "".equals(version)) { //$NON-NLS-1$
WmsPlugin.log("GetCapabilities VERSION is required", new ServiceNotFoundException()); //$NON-NLS-1$
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);
/*