/** * 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); }
/** * 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); } } }
internal KMLGroundOverlayRenderable(KMLGroundOverlay oSource, String strKMLDirectory) : base(oSource.Name) { m_oGroundOverlay = oSource; m_strKMLDirectory = strKMLDirectory; }
private static RenderableObject Construct(String strRelativeDirectory, KMLObject oSource, World oWorld, GeographicBoundingBox oBounds, ProjectedVectorRenderer oPVR, Icons oIcons) { if (oSource is KMLContainer) { KMLContainer oCastSource = oSource as KMLContainer; KMLRenderableObjectList result = new KMLRenderableObjectList(oCastSource.Name); if (oPVR == null) { oPVR = new ProjectedVectorRenderer("Polygons and LineStrings", oWorld); result.Add(oPVR); } if (oIcons == null) { oIcons = new Icons("Icons"); result.Add(oIcons); } for (int count = 0; count < oCastSource.Count; count++) { if (oCastSource[count].Visibility == true) { RenderableObject oLayer = Construct(strRelativeDirectory, oCastSource[count], oWorld, oBounds, oPVR, oIcons); if (oLayer != null) { result.Add(oLayer); } } } return(result); } else if (oSource is KMLPlacemark) { KMLPlacemark oCastSource = oSource as KMLPlacemark; return(Construct(strRelativeDirectory, oCastSource.Geometry, oWorld, oBounds, oPVR, oIcons)); } else if (oSource is KMLMultiGeometry) { KMLMultiGeometry oCastSource = oSource as KMLMultiGeometry; KMLRenderableObjectList result = new KMLRenderableObjectList("MultiGeometry"); for (int count = 0; count < oCastSource.Count; count++) { RenderableObject oLayer = Construct(strRelativeDirectory, oCastSource[count], oWorld, oBounds, oPVR, oIcons); if (oLayer != null) { result.Add(oLayer); } } return(result); } else if (oSource is KMLPoint) { KMLPoint oCastSource = oSource as KMLPoint; KMLIcon result = new KMLIcon(oCastSource.Owner.Name, oCastSource.Coordinates.Latitude, oCastSource.Coordinates.Longitude, oCastSource.Coordinates.Altitude); result.DrawGroundStick = oCastSource.Extrude; result.Rotation = WorldWind.Angle.FromDegrees(oCastSource.Style.NormalStyle.IconStyle.Heading); result.IsRotated = oCastSource.Style.NormalStyle.IconStyle.Heading != 0.0f; result.NormalColor = oCastSource.Style.NormalStyle.LabelStyle.Color; result.HotColor = oCastSource.Style.HighlightStyle.LabelStyle.Color; oIcons.Add(result); oBounds.Union(oCastSource.Coordinates.Longitude, oCastSource.Coordinates.Latitude, oCastSource.Coordinates.Altitude); return(null); } else if (oSource is KMLPolygon) { KMLPolygon oCastSource = oSource as KMLPolygon; Polygon oTool = new Polygon(); oTool.outerBoundary = new WorldWind.LinearRing(GetPoints(oCastSource.OuterBoundary)); oTool.innerBoundaries = GetInnerBoundaries(oCastSource); oTool.PolgonColor = oCastSource.Style.NormalStyle.PolyStyle.Color; oTool.Fill = oCastSource.Style.NormalStyle.PolyStyle.Fill; oTool.LineWidth = oCastSource.Style.NormalStyle.LineStyle.Width; oTool.Outline = oCastSource.Style.NormalStyle.PolyStyle.Outline; oTool.OutlineColor = oCastSource.Style.NormalStyle.LineStyle.Color; oPVR.Add(oTool); oBounds.Union(oTool.GetGeographicBoundingBox()); return(null); } else if (oSource is KMLLineString) { KMLLineString oCastSource = oSource as KMLLineString; LineString oTool = new LineString(); oTool.Coordinates = GetPoints(oCastSource); oTool.Color = oCastSource.Style.NormalStyle.LineStyle.Color; oTool.LineWidth = oCastSource.Style.NormalStyle.LineStyle.Width; oPVR.Add(oTool); oBounds.Union(oTool.GetGeographicBoundingBox()); return(null); } else if (oSource is KMLGroundOverlay) { KMLGroundOverlay oCastSource = oSource as KMLGroundOverlay; KMLGroundOverlayRenderable result = new KMLGroundOverlayRenderable(oCastSource, strRelativeDirectory); oBounds.Union(new GeographicBoundingBox(oCastSource.LatLonBox.North, oCastSource.LatLonBox.South, oCastSource.LatLonBox.West, oCastSource.LatLonBox.East)); return(result); } else { return(null); } }