📄 imagemaster.java
字号:
* Start up and go. */ public static void main(String[] args) { Debug.init(); ImageMaster master = null; for (int i = 0; i < args.length; i++) { if (args[i].equalsIgnoreCase("-file")) { master = new ImageMaster(args[++i]); } else if (args[i].equalsIgnoreCase("-url")) { String url = null; try { url = args[++i]; master = new ImageMaster(new URL(url)); } catch (MalformedURLException mue) { Debug.output("ImageMaster: Malformed URL: " + url); master = null; } } else if (args[i].equalsIgnoreCase("-masterprops")) { printMasterProps(); } else if (args[i].equalsIgnoreCase("-serverprops")) { printServerProps(); } else if (args[i].equalsIgnoreCase("-h")) { printHelp(); } } if (master != null) { master.run(); } else { printHelp(); } } /** * <b>printHelp </b> should print a usage statement which reflects * the command line needs of the ImageServer. */ public static void printHelp() { Debug.output(""); Debug.output("usage: java com.bbn.openmap.image.ImageMaster [-file <properties file> || -url <properties file>] [-masterprops || -serverprops"); Debug.output(" -file requires a complete path to a ImageMaster properties file."); Debug.output(" -url requires an URL to a ImageMaster properties file."); Debug.output(" -masterprops prints out an example of a ImageMaster properties file."); Debug.output(" -serverprops prints out an example of a ImageServer properties file."); Debug.output(""); System.exit(1); } /** * Prints an example of the ImageMaster properties file. */ public static void printMasterProps() { Debug.output(""); Debug.output("#################################################"); Debug.output("# Properties file for the ImageMaster"); Debug.output("# List of unique server nicknames (your choice)."); Debug.output("servers=<server1> <server2> <server3> <etc>"); Debug.output(""); Debug.output("# URL of server1 properties"); Debug.output("# If this is not included, it is assumed that "); Debug.output("# the ImageServer properties reside in the "); Debug.output("# ImageMaster properties file."); Debug.output("server1.properties=http://<url to server1 properties>"); Debug.output("# Projection type of server1 image."); Debug.output("server1.imageProjection=mercator"); Debug.output("# Center latitude of server1 image."); Debug.output("server1.imageLatitude=40f"); Debug.output("# Center longitude of server1 image."); Debug.output("server1.imageLongitude=-72f"); Debug.output("# Projection scale of server1 image."); Debug.output("server1.imageScale=20000000"); Debug.output("# Pixel height of server1 image."); Debug.output("server1.imageHeight=640"); Debug.output("# Pixel width of server1 image."); Debug.output("server1.imageWidth=480"); Debug.output("# ARGB representation of the map background color (default is a saucy blue)"); Debug.output("server1.imageBackgroundColor=ffffffff"); Debug.output("# Complete path to server1 image output."); Debug.output("server1.outputName=<path to output file>"); Debug.output(""); Debug.output("# Repeat for each server listed in the servers property"); Debug.output("#################################################"); Debug.output(""); } /** * Print the ImageServer properties file, referenced by the * ImageMaster properties file. */ public static void printServerProps() { Debug.output(""); Debug.output("#################################################"); Debug.output("# Properties for ImageServer"); Debug.output("# List of unique layer nicknames to use for the image (your choice)."); Debug.output("# server1 is the name specified in the ImageMaster properties."); Debug.output("server1.imageServer.layers=<layer1> <layer2> <etc>"); Debug.output("# Classname of object to determine image format."); Debug.output("server1.imageServer.formatter=<classname of ImageFormatter>"); Debug.output(""); Debug.output("layer1.class=<com.bbn.openmap.layer.ShapeLayer"); Debug.output("layer1.prettyName=ShapeLayer"); Debug.output("# Continue with layer specific properties. See each layer's documentation or source for more details."); Debug.output(""); Debug.output("# Continue for each layer listed in the imageServer.layers property."); Debug.output("#################################################"); Debug.output(""); } /** * The ImageMasterHelper contains an ImageServer, and acts like * the ImageReceiver to create the Image file when the bits are * ready. */ public class ImageMasterHelper implements ImageReceiver { public ImageServer iServer; public String outputFileName; public boolean complete = false; public ImageMaster iMaster; public Proj proj; public String outputLogFileName; public String errorLogFileName; public int scaleToWidth = -1; public int scaleToHeight = -1; public ImageMasterHelper(String prefix, Properties props, ImageMaster master) { String propPrefix = prefix + "."; float scale = PropUtils.floatFromProperties(props, propPrefix + ImageScaleProperty, 20000000f); int height = PropUtils.intFromProperties(props, propPrefix + ImageHeightProperty, 480); int width = PropUtils.intFromProperties(props, propPrefix + ImageWidthProperty, 640); float longitude = PropUtils.floatFromProperties(props, propPrefix + ImageLongitudeProperty, -71f); float latitude = PropUtils.floatFromProperties(props, propPrefix + ImageLatitudeProperty, 42f); String projType = props.getProperty(propPrefix + ImageProjectionProperty); String uniquePropsURL = props.getProperty(propPrefix + ServerPropertiesProperty); scaleToWidth = PropUtils.intFromProperties(props, propPrefix + ScaleToWidthProperty, -1); scaleToHeight = PropUtils.intFromProperties(props, propPrefix + ScaleToHeightProperty, -1); outputFileName = props.getProperty(propPrefix + ImageNameProperty); outputLogFileName = props.getProperty(propPrefix + OutputLogFileProperty); errorLogFileName = props.getProperty(propPrefix + ErrorLogFileProperty); if (outputLogFileName != null && errorLogFileName != null) { if (outputLogFileName.equalsIgnoreCase(errorLogFileName)) { Debug.setLog(new File(outputFileName), true); } else { Debug.directErrors(errorLogFileName, true, true); Debug.directOutput(new File(outputLogFileName), true); } } else { if (errorLogFileName != null) { Debug.directErrors(errorLogFileName, true, true); } if (outputLogFileName != null) { Debug.directOutput(new File(outputLogFileName), true); } } Class projClass = ProjectionFactory.getProjClassForName(projType); if (projClass == null) { projClass = Mercator.class; } proj = (Proj) ProjectionFactory.makeProjection(projClass, latitude, longitude, scale, width, height); // Set the background color of the map Color background = (Color) PropUtils.parseColorFromProperties(props, propPrefix + ImageBackgroundColorProperty, MapBean.DEFAULT_BACKGROUND_COLOR); iMaster = master; Properties uniqueProps; // if there isn't a unique properties file designated for // the imageerver layers, assume that the layer properties // reside in the ImageMaster properties file. if (uniquePropsURL != null) { uniqueProps = new Properties(); try { loadProperties(uniqueProps, new URL(uniquePropsURL)); } catch (MalformedURLException mue) { Debug.error("ImageMaster: Malformed URL for server properties: " + uniquePropsURL); uniqueProps = null; } } else { uniqueProps = props; } if (uniqueProps != null && outputFileName != null) { iServer = new ImageServer(propPrefix, uniqueProps, instantiatedLayers); iServer.setBackground(background); } } /** * Start the ImageServer on it's creative journey. */ public void create() { receiveImageData(iServer.createImage(proj, scaleToWidth, scaleToHeight)); } /** * Receive the bytes from a image. ImageReceiver interface * function. * * @param imageBytes the formatted image.. */ public void receiveImageData(byte[] imageBytes) { writeDataFile(outputFileName, imageBytes); complete = true; iMaster.doNext(); } /** * Write the image to a file. * * @param fileName the file name to write the image into. * @param imageData the image data to put in the file. */ public void writeDataFile(String fileName, byte[] imageData) { try { Debug.message("imagemaster", "ImageMasterHelper: Writing image file " + fileName); FileOutputStream binFile = new FileOutputStream(fileName); binFile.write(imageData); binFile.close(); } catch (IOException ioe) { Debug.error("ImageMasterHelper: Error writing image file " + fileName); } } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -