Package gov.nasa.worldwind.ogc.kml
Class KMLLink
- java.lang.Object
-
- gov.nasa.worldwind.util.xml.AbstractXMLEventParser
-
- gov.nasa.worldwind.ogc.kml.KMLAbstractObject
-
- gov.nasa.worldwind.ogc.kml.KMLLink
-
- All Implemented Interfaces:
MessageListener,XMLEventParser
- Direct Known Subclasses:
KMLIcon
public class KMLLink extends KMLAbstractObject
Represents the KML Link element and provides access to its contents. The Link maintains a timestamp that indicates when the resource was last updated. The timestamp is updated based on the link's refresh mode. Code that uses a resource loaded from a Link should keep track of when the resource was retrieved, and periodically check that timestamp against the timestamp returned bygetUpdateTime().
-
-
Field Summary
Fields Modifier and Type Field Description protected static java.lang.StringDEFAULT_VIEW_FORMATprotected java.lang.StringfinalHrefIf this link's href does not need to be modified with a query string, this value is the resource address.protected java.net.URLhrefURLTheURLfor the raw href.protected java.util.concurrent.ScheduledFuturerefreshTaskScheduled task that will update the when it runs.protected java.util.concurrent.atomic.AtomicLongupdateTimeThe time, in milliseconds since the Epoch, at which the linked content was most recently updated.-
Fields inherited from class gov.nasa.worldwind.ogc.kml.KMLAbstractObject
MSG_BOX_CHANGED, MSG_GEOMETRY_CHANGED, MSG_LINK_CHANGED, MSG_STYLE_CHANGED, MSG_TIME_CHANGED, MSG_VIEW_CHANGED
-
Fields inherited from class gov.nasa.worldwind.util.xml.AbstractXMLEventParser
CHARACTERS_CONTENT, fields, namespaceURI, parent
-
-
Constructor Summary
Constructors Constructor Description KMLLink(java.lang.String namespaceURI)Construct an instance.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidapplyChange(KMLAbstractObject sourceValues)protected java.lang.StringbuildQueryString(DrawContext dc)This returns the concatenation of the query part ofhref(if any), theviewFormatand thehttpQueryto form the link URL's query part.protected java.lang.LongcomputeRefreshTime()protected SectorcomputeVisibleBounds(DrawContext dc)Returns aSectorthat specifies the current visible bounds on the globe.java.lang.StringgetAddress(DrawContext dc)Returns the address of the resource specified by this KML link.java.lang.StringgetHref()java.lang.StringgetHttpQuery()java.lang.DoublegetRefreshInterval()java.lang.StringgetRefreshMode()longgetUpdateTime()Returns the time at which the linked resource was last updated.java.lang.DoublegetViewBoundScale()java.lang.StringgetViewFormat()java.lang.StringgetViewRefreshMode()java.lang.DoublegetViewRefreshTime()protected booleanisLocalReference(java.net.URL url)Returns whether the resource specified by theurlis a local resource.voidonMessage(Message msg)Schedule the link to refresh when anView.VIEW_STOPPEDmessage is received, and the link's view refresh mode isonStop.java.lang.Objectparse(XMLEventParserContext ctx, javax.xml.stream.events.XMLEvent inputEvent, java.lang.Object... args)Parse the event and initialize the parser's values to those found in the event.protected java.util.concurrent.ScheduledFuturescheduleDelayedTask(java.lang.Runnable task, long delay, java.util.concurrent.TimeUnit timeUnit)Schedule a task to mark a link as updated after a delay.protected voidscheduleRefreshIfNeeded()Schedule a task to refresh the link if the refresh mode requires it.voidsetExpirationTime(long time)Specifies the time at which the linked resource expires.voidsetField(java.lang.String keyName, java.lang.Object value)Overridden to markonChangelinks as updated when a field set.voidsetUpdateTime(long updateTime)Specifies the time at which the linked resource was last updated.-
Methods inherited from class gov.nasa.worldwind.ogc.kml.KMLAbstractObject
getId, getRoot, getTargetId, onChange
-
Methods inherited from class gov.nasa.worldwind.util.xml.AbstractXMLEventParser
allocate, doAddCharacters, doAddEventAttribute, doAddEventContent, doParseEventAttributes, doParseEventContent, freeResources, getAConstructor, getCharacters, getField, getField, getFields, getNamespaceURI, getParent, hasField, hasField, hasFields, mergeFields, newInstance, overrideFields, parseCharacterContent, removeField, setField, setFields, setNamespaceURI, setParent
-
-
-
-
Field Detail
-
DEFAULT_VIEW_FORMAT
protected static final java.lang.String DEFAULT_VIEW_FORMAT
- See Also:
- Constant Field Values
-
updateTime
protected java.util.concurrent.atomic.AtomicLong updateTime
The time, in milliseconds since the Epoch, at which the linked content was most recently updated.
-
finalHref
protected java.lang.String finalHref
If this link's href does not need to be modified with a query string, this value is the resource address.
-
hrefURL
protected java.net.URL hrefURL
TheURLfor the raw href. Will be null if the href is not a remote URL or this link has a query string
-
refreshTask
protected java.util.concurrent.ScheduledFuture refreshTask
Scheduled task that will update the when it runs. Used to implementonIntervalrefresh mode.
-
-
Method Detail
-
getHref
public java.lang.String getHref()
-
getRefreshMode
public java.lang.String getRefreshMode()
-
getRefreshInterval
public java.lang.Double getRefreshInterval()
-
getViewRefreshMode
public java.lang.String getViewRefreshMode()
-
getViewRefreshTime
public java.lang.Double getViewRefreshTime()
-
getViewBoundScale
public java.lang.Double getViewBoundScale()
-
getViewFormat
public java.lang.String getViewFormat()
-
getHttpQuery
public java.lang.String getHttpQuery()
-
setField
public void setField(java.lang.String keyName, java.lang.Object value)Overridden to markonChangelinks as updated when a field set.- Overrides:
setFieldin classAbstractXMLEventParser
-
getUpdateTime
public long getUpdateTime()
Returns the time at which the linked resource was last updated. This method is safe to call from any thread.- Returns:
- The time at which the linked content was most recently updated. See
System.currentTimeMillis()for its numerical meaning of this timestamp.
-
setUpdateTime
public void setUpdateTime(long updateTime)
Specifies the time at which the linked resource was last updated. This method is safe to call from any thread.- Parameters:
updateTime- The time at which the linked content was most recently updated. SeeSystem.currentTimeMillis()for its numerical meaning of this timestamp.
-
setExpirationTime
public void setExpirationTime(long time)
Specifies the time at which the linked resource expires. If the link's update mode is onExpire, the link will mark itself updated at this time.- Parameters:
time- Time, in milliseconds since the Epoch, at which the link expires. Zero indicates no expiration.
-
scheduleRefreshIfNeeded
protected void scheduleRefreshIfNeeded()
Schedule a task to refresh the link if the refresh mode requires it. In the case of anonIntervalandonExpirerefresh modes, this method schedules a task to update the link after the refresh interval elapses, but only if such a task has not already been scheduled (only one refresh task is active at a time).
-
computeRefreshTime
protected java.lang.Long computeRefreshTime()
-
onMessage
public void onMessage(Message msg)
Schedule the link to refresh when anView.VIEW_STOPPEDmessage is received, and the link's view refresh mode isonStop.- Specified by:
onMessagein interfaceMessageListener- Overrides:
onMessagein classKMLAbstractObject- Parameters:
msg- The message that was received.
-
scheduleDelayedTask
protected java.util.concurrent.ScheduledFuture scheduleDelayedTask(java.lang.Runnable task, long delay, java.util.concurrent.TimeUnit timeUnit)Schedule a task to mark a link as updated after a delay. The task only executes once.- Parameters:
task- Task to schedule.delay- Delay to wait before executing the task. The time unit is determined by {code timeUnit}.timeUnit- The time unit ofdelay.- Returns:
- Future that represents the scheduled task.
-
parse
public java.lang.Object parse(XMLEventParserContext ctx, javax.xml.stream.events.XMLEvent inputEvent, java.lang.Object... args) throws javax.xml.stream.XMLStreamException
Parse the event and initialize the parser's values to those found in the event. Overridden to set a default refresh mode ofonChangeif the refresh mode is not specified.- Specified by:
parsein interfaceXMLEventParser- Overrides:
parsein classAbstractXMLEventParser- Parameters:
ctx- a current parser context.inputEvent- the event to parse.args- an optional list of arguments that may by used by subclasses.- Returns:
- if parsing is successful, returns
this, otherwise returns null. - Throws:
javax.xml.stream.XMLStreamException- if an exception occurs during event-stream reading.
-
getAddress
public java.lang.String getAddress(DrawContext dc)
Returns the address of the resource specified by this KML link. If the resource specified in this link'shrefis a local resource, this returns only thehref, and ignores theviewFormatandhttpQuery. Otherwise, this returns the concatenation of thehref, theviewFormatand thehttpQueryfor form an absolute URL string. If the thehrefcontains a query string, theviewFormatandhttpQueryare appended to that string. If necessary, this inserts the&character between thehref's query string, theviewFormat, and thehttpQuery.This substitutes the following parameters in
viewFormatandhttpQuery:[bboxWest],[bboxSouth],[bboxEast],[bboxNorth]- visible bounds of the globe, or 0 if the globe is not visible. The visible bounds are scaled from their centroid by this link'sviewBoundScale.[lookatLon], [lookatLat]- longitude and latitude of the position on the globe the view is looking at, or 0 if the view is not looking at the globe.[lookatRange]- distance between view's eye position and the point on the globe the view is looking at.[lookatTilt], [lookatHeading]- view's tilt and heading.[lookatTerrainLon], [lookatTerrainLat], [lookatTerrainAlt]- terrain position the view is looking at, or 0 if the view is not looking at the terrain.[cameraLon], [cameraLat], [cameraAlt]- view's eye position.[horizFov], [vertFov]- view's horizontal and vertical field of view.[horizPixels], [vertPixels]- width and height of the viewport.[terrainEnabled]- alwaystrue[clientVersion]- WorldWind client version.[clientName]- WorldWind client name.[kmlVersion]- KML version supported by WorldWind.[language]- current locale's language.
viewFormatis unspecified, and theviewRefreshModeis one ofonRequest,onStoporonRegion, this automatically appends the following information to the query string:BBOX=[bboxWest],[bboxSouth],[bboxEast],[bboxNorth]. The[clientName]and[clientVersion]parameters of thehttpQuerymay be specified in the configuration file using the keysandAVKey.NAME. If not specified, this uses default values ofAVKey.VERSIONandVersion.getVersionName()forVersion.getVersion()[clientName]and[clientVersion], respectively.- Parameters:
dc- theDrawContextused to determine the current view parameters.- Returns:
- the address of the resource specified by this KML link.
- Throws:
java.lang.IllegalArgumentException- ifdcisnull.- See Also:
getHref(),getViewFormat(),getHttpQuery(),Configuration
-
isLocalReference
protected boolean isLocalReference(java.net.URL url)
Returns whether the resource specified by theurlis a local resource.- Parameters:
url- the URL to test.- Returns:
trueif theurlspecifies a local resource, otherwisefalse.
-
buildQueryString
protected java.lang.String buildQueryString(DrawContext dc)
This returns the concatenation of the query part ofhref(if any), theviewFormatand thehttpQueryto form the link URL's query part. This returnsnullif this link'shrefdoes not specify a URL. This substitutes parameters inviewFormataccording to the specifiedDrawContext's current viewing parameters, and substitutes parameters inhttpQueryaccording to the currentparameters.Configuration- Parameters:
dc- theDrawContextused to determine the current view parameters.- Returns:
- the query part of this KML link's address, or
nullif this link does not specify a URL.
-
computeVisibleBounds
protected Sector computeVisibleBounds(DrawContext dc)
Returns aSectorthat specifies the current visible bounds on the globe. If this link specifies aviewBoundScale, this scales the visible bounds from its centroid by that factor, but limits the bounds to [-90,90] latitude and [-180,180] longitude. This returnsif the globe is not visible.Sector.EMPTY_SECTOR- Parameters:
dc- theDrawContextfor which to compute the visible bounds.- Returns:
- the current visible bounds on the specified
DrawContext.
-
applyChange
public void applyChange(KMLAbstractObject sourceValues)
- Overrides:
applyChangein classKMLAbstractObject
-
-