/** * Create a surface polygon from a KML GroundOverlay. * * @param tc the current {@link KMLTraversalContext}. * @param overlay the {@link SharpEarth.ogc.kml.KMLGroundOverlay} to render as a polygon. * * @throws NullPointerException if the geometry is null. * @throws ArgumentException if the parent placemark or the traversal context is null. */ public KMLSurfacePolygonImpl(KMLTraversalContext tc, KMLGroundOverlay 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); } this.parent = overlay; // Positions are specified either as a kml:LatLonBox or a gx:LatLonQuad Position.PositionList corners = overlay.getPositions(); this.setOuterBoundary(corners.list); // Check to see if a rotation is provided. The rotation will be applied when the image is rendered, because // how the rotation is performed depends on the globe. KMLLatLonBox box = overlay.getLatLonBox(); if (box != null && box.getRotation() != null) { this.mustApplyRotation = true; } if (overlay.getName() != null) { this.setValue(AVKey.DISPLAY_NAME, overlay.getName()); } if (overlay.getDescription() != null) { this.setValue(AVKey.BALLOON_TEXT, overlay.getDescription()); } if (overlay.getSnippetText() != null) { this.setValue(AVKey.SHORT_DESCRIPTION, overlay.getSnippetText()); } String colorStr = overlay.getColor(); if (!WWUtil.isEmpty(colorStr)) { Color color = WWUtil.decodeColorABGR(colorStr); ShapeAttributes attributes = new BasicShapeAttributes(); attributes.setDrawInterior(true); attributes.setInteriorMaterial(new Material(color)); this.setAttributes(attributes); } }
/** * 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 KMLSurfaceImageImpl(KMLTraversalContext tc, KMLGroundOverlay 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); } // Positions are specified either as a kml:LatLonBox or a gx:LatLonQuad KMLLatLonBox box = overlay.getLatLonBox(); if (box != null) { Sector sector = KMLUtil.createSectorFromLatLonBox(box); this.initializeGeometry(sector); // Check to see if a rotation is provided. The rotation will be applied when the image is rendered, because // how the rotation is performed depends on the globe. Double rotation = box.getRotation(); if (rotation != null) { this.mustApplyRotation = true; } } else { GXLatLongQuad latLonQuad = overlay.getLatLonQuad(); if (latLonQuad != null && latLonQuad.getCoordinates() != null) { this.initializeGeometry(latLonQuad.getCoordinates().list); } } // Apply opacity to the surface image String colorStr = overlay.getColor(); if (!WWUtil.isEmpty(colorStr)) { Color color = WWUtil.decodeColorABGR(colorStr); int alpha = color.getAlpha(); this.setOpacity((double)alpha / 255); } this.setPickEnabled(false); }
public static ShapeAttributes assembleInteriorAttributes(ShapeAttributes attrs, KMLPolyStyle style) { // Assign the attributes defined in the KML Feature element. if (style.getColor() != null) { Color color = WWUtil.decodeColorABGR(style.getColor()); attrs.setInteriorMaterial(new Material(color)); attrs.setInteriorOpacity((double)color.getAlpha() / 255); } if (style.getColorMode() != null && "random".Equals(style.getColorMode())) { attrs.setInteriorMaterial(new Material(WWUtil.makeRandomColor(attrs.getOutlineMaterial().getDiffuse()))); } return(attrs); }
public static ShapeAttributes assembleLineAttributes(ShapeAttributes attrs, KMLLineStyle style) { // Assign the attributes defined in the KML Feature element. if (style.getWidth() != null) { attrs.setOutlineWidth(style.getWidth()); } if (style.getColor() != null) { attrs.setOutlineMaterial(new Material(WWUtil.decodeColorABGR(style.getColor()))); } if (style.getColorMode() != null && "random".Equals(style.getColorMode())) { attrs.setOutlineMaterial(new Material(WWUtil.makeRandomColor(attrs.getOutlineMaterial().getDiffuse()))); } return(attrs); }
/** * Create an instance. * * @param tc the current {@link KMLTraversalContext}. * @param overlay the {@link SharpEarth.ogc.kml.KMLGroundOverlay} to render as a polygon. * * @throws NullPointerException if the geomtry is null. * @throws ArgumentException if the parent placemark or the traversal context is null. */ public KMLGroundOverlayPolygonImpl(KMLTraversalContext tc, KMLGroundOverlay 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); } this.parent = overlay; String altMode = overlay.getAltitudeMode(); if (!WWUtil.isEmpty(altMode)) { if ("relativeToGround".Equals(altMode)) { this.setAltitudeMode(WorldWind.RELATIVE_TO_GROUND); } else if ("absolute".Equals(altMode)) { this.setAltitudeMode(WorldWind.ABSOLUTE); } } // Positions are specified either as a kml:LatLonBox or a gx:LatLonQuad Position.PositionList corners = overlay.getPositions(); this.setOuterBoundary(corners.list); // Apply rotation if the overlay includes a LatLonBox KMLLatLonBox box = overlay.getLatLonBox(); if (box != null) { this.setRotation(box.getRotation()); } if (overlay.getName() != null) { this.setValue(AVKey.DISPLAY_NAME, overlay.getName()); } if (overlay.getDescription() != null) { this.setValue(AVKey.BALLOON_TEXT, overlay.getDescription()); } if (overlay.getSnippetText() != null) { this.setValue(AVKey.SHORT_DESCRIPTION, overlay.getSnippetText()); } // If no image is specified, draw a filled rectangle if (this.parent.getIcon() == null || this.parent.getIcon().getHref() == null) { String colorStr = overlay.getColor(); if (!WWUtil.isEmpty(colorStr)) { Color color = WWUtil.decodeColorABGR(colorStr); ShapeAttributes attributes = new BasicShapeAttributes(); attributes.setDrawInterior(true); attributes.setInteriorMaterial(new Material(color)); this.setAttributes(attributes); } } }
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); }
/** * Sets the label color as a string in the form 0xAABBGGRR. * * @param labelColorString the line color. May be null. */ public void setLabelColor(String labelColorString) { this.setLabelMaterial(new Material(WWUtil.decodeColorABGR(labelColorString))); }
/** * Sets the line color as a string in the form 0xAABBGGRR. * * @param lineColorString the line color. May be null. */ public void setLineColor(String lineColorString) { this.setLineMaterial(new Material(WWUtil.decodeColorABGR(lineColorString))); }
/** * 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); } }