/** * 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); }
/** * Apply a rotation to the corner points of the overlay. * * @param dc Current draw context. */ protected void applyRotation(DrawContext dc) { KMLLatLonBox box = this.parent.getLatLonBox(); if (box != null) { Double rotation = box.getRotation(); if (rotation != null) { List <LatLon> corners = KMLUtil.rotateSector(dc.getGlobe(), this.getSector(), Angle.fromDegrees(rotation)); this.setCorners(corners); } } }
/** * Apply a rotation to the corner points of the overlay. This method is called the first time the polygon is * rendered, if the position is specified using a rotated LatLon box. * * @param dc Current draw context. */ protected void applyRotation(DrawContext dc) { // Rotation applies only to ground overlay position with a LatLon box. if (!(this.parent is KMLGroundOverlay)) { return; } KMLLatLonBox box = ((KMLGroundOverlay)this.parent).getLatLonBox(); if (box != null) { Double rotation = box.getRotation(); if (rotation != null) { Sector sector = KMLUtil.createSectorFromLatLonBox(box); java.util.List <LatLon> corners = KMLUtil.rotateSector(dc.getGlobe(), sector, Angle.fromDegrees(rotation)); this.setOuterBoundary(corners); } } }
/** * 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); } } }