/** * Specifies the image source, which may be either a file path {@link String} or a {@link * java.awt.image.BufferedImage}. If the image is not already in memory, it will be loaded in the background. * * @param imageSource the image source, either a file path {@link String} or a {@link * java.awt.image.BufferedImage}. * * @throws ArgumentException if the <code>imageSource</code> is null. */ public void setImageSource(Object imageSource) { if (imageSource == null) { String message = Logging.getMessage("nullValue.ImageSource"); Logging.logger().severe(message); throw new ArgumentException(message); } this.imageSource = imageSource; this.texture = null; // New image source, we need to load a new texture }
/** * Create and initialize the texture from the image source. If the image is not in memory this method will request * that it be loaded and return null. * * @return The texture, or null if the texture is not yet available. */ protected BasicWWTexture initializeTexture() { Object imageSource = this.getImageSource(); if (imageSource is String || imageSource is URL) { URL imageURL = WorldWind.getDataFileStore().requestFile(imageSource.ToString()); if (imageURL != null) { this.texture = new BasicWWTexture(imageURL, true); this.texture.setUseAnisotropy(false); } } else if (imageSource != null) { this.texture = new BasicWWTexture(imageSource, true); return(this.texture); } return(null); }
/** * Compute the image size, rotation, and position based on the current viewport size. This method updates the * calculated values for screen point, rotation point, width, and height. The calculation is not performed if the * values have already been calculated for this frame. * * @param dc DrawContext into which the image will be rendered. */ protected void computeOffsets(DrawContext dc) { if (dc.getFrameTimeStamp() != this.frameNumber) { final BasicWWTexture texture = this.getTexture(); final int viewportWidth = dc.getView().getViewport().width; final int viewportHeight = dc.getView().getViewport().height; // Compute image size if (texture != null) { this.originalImageWidth = texture.getWidth(dc); this.originalImageHeight = texture.getHeight(dc); } else if (this.getImageSource() == null) // If no image source is set, draw a rectangle { this.originalImageWidth = 1; this.originalImageHeight = 1; } else // If an image source is set, but the image is not available yet, don't draw anything { this.frameNumber = dc.getFrameTimeStamp(); return; } if (this.size != null) { Dimension d = this.size.compute(this.originalImageWidth, this.originalImageHeight, viewportWidth, viewportHeight); this.width = d.width; this.height = d.height; } else { this.width = this.originalImageWidth; this.height = this.originalImageHeight; } // Compute rotation Offset rotationOffset = this.getRotationOffset(); // If no rotation offset is set, rotate around the center of the image. if (rotationOffset != null) { // The KML specification according to both OGC and Google states that the rotation point is specified in // a coordinate system with the origin at the lower left corner of the screen (0.5, 0.5 is the center // of the screen). But Google Earth interprets the point in a coordinate system with origin at the lower // left corner of the image (0.5, 0.5 is the center of the image), so we'll do that too. Point.Double pointD = rotationOffset.computeOffset(this.width, this.height, null, null); rotationPoint = new Point((int)pointD.x, (int)pointD.y); } else { this.rotationPoint = new Point(this.width, this.height); } // Compute position if (this.screenOffset != null) { // Compute the screen location in OpenGL coordinates. There is no need to convert from AWT to OpenGL // coordinates because the Offset is already in OpenGL coordinates with its origin in the lower-left // corner. Point.Double pointD = this.screenOffset.computeOffset(viewportWidth, viewportHeight, null, null); this.screenLocation = new Point((int)pointD.x, (int)(pointD.y)); } else { this.screenLocation = new Point(viewportWidth / 2, viewportHeight / 2); } // Convert the screen location from OpenGL to AWT coordinates and store the result in awtScreenLocation. The // awtScreenLocation property is used in getScreenLocation to indicate the screen location in AWT // coordinates. this.awtScreenLocation = new Point(this.screenLocation.x, viewportHeight - this.screenLocation.y); Point.Double overlayPoint; if (this.imageOffset != null) { overlayPoint = this.imageOffset.computeOffset(this.width, this.height, null, null); } else { overlayPoint = new Point.Double(this.originalImageWidth / 2.0, this.originalImageHeight / 2.0); } this.dx = -overlayPoint.x; this.dy = -overlayPoint.y; this.frameNumber = dc.getFrameTimeStamp(); } }