/** * {@inheritDoc} Overridden to set the expiration time of the placemark's icon based on the HTTP headers of the * linked resource. */ protected WWTexture initializeTexture(String address) { WWTexture texture = super.initializeTexture(address); if (texture != null) { // Query the KMLRoot for the expiration time. long expiration = this.parent.getRoot().getExpiration(address); // Set the Icon's expiration. This has no effect if the refreshMode is not onExpire. String mode = this.isHighlighted() ? KMLConstants.HIGHLIGHT : KMLConstants.NORMAL; KMLIconStyle iconStyle = (KMLIconStyle)this.parent.getSubStyle(new KMLIconStyle(null), mode); KMLIcon icon = iconStyle.getIcon(); if (icon != null) { icon.setExpirationTime(expiration); } if (this.isHighlighted()) { this.highlightIconRetrievalTime = System.currentTimeMillis(); } else { this.iconRetrievalTime = System.currentTimeMillis(); } } return(texture); }
public override void Load() { ics = new Icons("Globe cursor"); ic = new KMLIcon("", 0f, 0f, "", 0f); ic.Image = cursBmp; ic.Width = 16; ic.Height = 16; ics.Add(ic); Global.worldWindow.CurrentWorld.RenderableObjects.Add(ics); Global.worldWindow.MouseMove += new MouseEventHandler(MouseMove); base.Load(); }
/** * Indicates whether or not the image source needs to be resolved. The source needs to be resolved when the KMLIcon * is updated. * * @return True if the image source must be resolved. */ protected bool mustResolveHref() { KMLIcon icon = this.parent.getIcon(); //noinspection SimplifiableIfStatement if (icon == null || icon.getHref() == null) { return(false); } // Resolve the reference if the image hasn't been retrieved, or if the link has expired. return(this.getImageSource() == null || icon.getUpdateTime() > this.iconRetrievalTime); }
/** * Indicates whether or not the icon resource has expired. * * @return True if the icon has expired and must be refreshed. */ protected bool mustRefreshIcon() { String mode; long retrievalTime; if (this.isHighlighted()) { mode = KMLConstants.HIGHLIGHT; retrievalTime = this.highlightIconRetrievalTime; } else { mode = KMLConstants.NORMAL; retrievalTime = this.iconRetrievalTime; } KMLIconStyle iconStyle = (KMLIconStyle)this.parent.getSubStyle(new KMLIconStyle(null), mode); KMLIcon icon = iconStyle.getIcon(); return(icon != null && icon.getUpdateTime() > retrievalTime); }
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); }
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; } }
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); } }