protected PointPlacemarkAttributes assemblePointAttributes(PointPlacemarkAttributes attrs, KMLIconStyle style) { KMLIcon icon = style.getIcon(); if (icon != null && icon.getHref() != null) { // The icon reference may be to a support file within a KMZ file, so check for that. If it's not, then just // let the normal PointPlacemark code resolve the reference. String href = icon.getHref(); String localAddress = null; try { localAddress = this.parent.getRoot().getSupportFilePath(href); } catch (IOException e) { String message = Logging.getMessage("generic.UnableToResolveReference", href); Logging.logger().warning(message); } attrs.setImageAddress((localAddress != null ? localAddress : href)); } // If the Icon element is present, but there is no href, draw a point instead of the default icon. else if (icon != null && WWUtil.isEmpty(icon.getHref())) { attrs.setUsePointAsDefaultImage(true); } // Assign the other attributes defined in the KML Feature element. if (style.getColor() != null) { attrs.setImageColor(WWUtil.decodeColorABGR(style.getColor())); } if (style.getColorMode() != null && "random".Equals(style.getColorMode())) { attrs.setImageColor(WWUtil.makeRandomColor(attrs.getImageColor())); } if (style.getScale() != null) { attrs.setScale(style.getScale()); } if (style.getHeading() != null) { attrs.setHeading(style.getHeading()); attrs.setHeadingReference(AVKey.RELATIVE_TO_GLOBE); // KML spec is not clear about this } if (style.getHotSpot() != null) { KMLVec2 hs = style.getHotSpot(); attrs.setImageOffset(new Offset(hs.getX(), hs.getY(), KMLUtil.kmlUnitsToWWUnits(hs.getXunits()), KMLUtil.kmlUnitsToWWUnits(hs.getYunits()))); } else { // By default, use the center of the image as the offset. attrs.setImageOffset(new Offset(0.5, 0.5, AVKey.FRACTION, AVKey.FRACTION)); } return(attrs); }
/** * Create an screen image. * * @param tc the current {@link KMLTraversalContext}. * @param overlay the <i>Overlay</i> element containing. * * @throws NullPointerException if the traversal context is null. * @throws ArgumentException if the parent overlay or the traversal context is null. */ public KMLScreenImageImpl(KMLTraversalContext tc, KMLScreenOverlay overlay) { this.parent = overlay; if (tc == null) { String msg = Logging.getMessage("nullValue.TraversalContextIsNull"); Logging.logger().severe(msg); throw new ArgumentException(msg); } if (overlay == null) { String msg = Logging.getMessage("nullValue.ParentIsNull"); Logging.logger().severe(msg); throw new ArgumentException(msg); } KMLVec2 xy = this.parent.getScreenXY(); if (xy != null) { this.screenOffset = new Offset(xy.getX(), xy.getY(), KMLUtil.kmlUnitsToWWUnits(xy.getXunits()), KMLUtil.kmlUnitsToWWUnits(xy.getYunits())); } xy = this.parent.getOverlayXY(); if (xy != null) { this.imageOffset = new Offset(xy.getX(), xy.getY(), KMLUtil.kmlUnitsToWWUnits(xy.getXunits()), KMLUtil.kmlUnitsToWWUnits(xy.getYunits())); } this.setRotation(overlay.getRotation()); xy = this.parent.getRotationXY(); if (xy != null) { setRotationOffset(new Offset(xy.getX(), xy.getY(), KMLUtil.kmlUnitsToWWUnits(xy.getXunits()), KMLUtil.kmlUnitsToWWUnits(xy.getYunits()))); } String colorStr = overlay.getColor(); if (colorStr != null) { Color color = WWUtil.decodeColorABGR(colorStr); this.setColor(color); } // Compute desired image size, and the scale factor that will make it that size KMLVec2 kmlSize = this.parent.getSize(); if (kmlSize != null) { Size size = new Size(); size.setWidth(getSizeMode(kmlSize.getX()), kmlSize.getX(), KMLUtil.kmlUnitsToWWUnits(kmlSize.getXunits())); size.setHeight(getSizeMode(kmlSize.getY()), kmlSize.getY(), KMLUtil.kmlUnitsToWWUnits(kmlSize.getYunits())); this.setSize(size); } }