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.String
DEFAULT_VIEW_FORMAT
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.protected java.net.URL
hrefURL
TheURL
for the raw href.protected java.util.concurrent.ScheduledFuture
refreshTask
Scheduled task that will update the when it runs.protected java.util.concurrent.atomic.AtomicLong
updateTime
The 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 void
applyChange(KMLAbstractObject sourceValues)
protected java.lang.String
buildQueryString(DrawContext dc)
This returns the concatenation of the query part ofhref
(if any), theviewFormat
and thehttpQuery
to form the link URL's query part.protected java.lang.Long
computeRefreshTime()
protected Sector
computeVisibleBounds(DrawContext dc)
Returns aSector
that specifies the current visible bounds on the globe.java.lang.String
getAddress(DrawContext dc)
Returns the address of the resource specified by this KML link.java.lang.String
getHref()
java.lang.String
getHttpQuery()
java.lang.Double
getRefreshInterval()
java.lang.String
getRefreshMode()
long
getUpdateTime()
Returns the time at which the linked resource was last updated.java.lang.Double
getViewBoundScale()
java.lang.String
getViewFormat()
java.lang.String
getViewRefreshMode()
java.lang.Double
getViewRefreshTime()
protected boolean
isLocalReference(java.net.URL url)
Returns whether the resource specified by theurl
is a local resource.void
onMessage(Message msg)
Schedule the link to refresh when anView.VIEW_STOPPED
message is received, and the link's view refresh mode isonStop
.java.lang.Object
parse(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.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.protected void
scheduleRefreshIfNeeded()
Schedule a task to refresh the link if the refresh mode requires it.void
setExpirationTime(long time)
Specifies the time at which the linked resource expires.void
setField(java.lang.String keyName, java.lang.Object value)
Overridden to markonChange
links as updated when a field set.void
setUpdateTime(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
TheURL
for 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 implementonInterval
refresh 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 markonChange
links as updated when a field set.- Overrides:
setField
in 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 anonInterval
andonExpire
refresh 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_STOPPED
message is received, and the link's view refresh mode isonStop
.- Specified by:
onMessage
in interfaceMessageListener
- Overrides:
onMessage
in 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 ofonChange
if the refresh mode is not specified.- Specified by:
parse
in interfaceXMLEventParser
- Overrides:
parse
in 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'shref
is a local resource, this returns only thehref
, and ignores theviewFormat
andhttpQuery
. Otherwise, this returns the concatenation of thehref
, theviewFormat
and thehttpQuery
for form an absolute URL string. If the thehref
contains a query string, theviewFormat
andhttpQuery
are appended to that string. If necessary, this inserts the&
character between thehref
's query string, theviewFormat
, and thehttpQuery
.This substitutes the following parameters in
viewFormat
andhttpQuery
:[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.
viewFormat
is unspecified, and theviewRefreshMode
is one ofonRequest
,onStop
oronRegion
, this automatically appends the following information to the query string:BBOX=[bboxWest],[bboxSouth],[bboxEast],[bboxNorth]
. The[clientName]
and[clientVersion]
parameters of thehttpQuery
may be specified in the configuration file using the keys
andAVKey.NAME
. If not specified, this uses default values ofAVKey.VERSION
andVersion.getVersionName()
forVersion.getVersion()
[clientName]
and[clientVersion]
, respectively.- Parameters:
dc
- theDrawContext
used to determine the current view parameters.- Returns:
- the address of the resource specified by this KML link.
- Throws:
java.lang.IllegalArgumentException
- ifdc
isnull
.- See Also:
getHref()
,getViewFormat()
,getHttpQuery()
,Configuration
-
isLocalReference
protected boolean isLocalReference(java.net.URL url)
Returns whether the resource specified by theurl
is a local resource.- Parameters:
url
- the URL to test.- Returns:
true
if theurl
specifies a local resource, otherwisefalse
.
-
buildQueryString
protected java.lang.String buildQueryString(DrawContext dc)
This returns the concatenation of the query part ofhref
(if any), theviewFormat
and thehttpQuery
to form the link URL's query part. This returnsnull
if this link'shref
does not specify a URL. This substitutes parameters inviewFormat
according to the specifiedDrawContext
's current viewing parameters, and substitutes parameters inhttpQuery
according to the current
parameters.Configuration
- Parameters:
dc
- theDrawContext
used to determine the current view parameters.- Returns:
- the query part of this KML link's address, or
null
if this link does not specify a URL.
-
computeVisibleBounds
protected Sector computeVisibleBounds(DrawContext dc)
Returns aSector
that 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 returns
if the globe is not visible.Sector.EMPTY_SECTOR
- Parameters:
dc
- theDrawContext
for which to compute the visible bounds.- Returns:
- the current visible bounds on the specified
DrawContext
.
-
applyChange
public void applyChange(KMLAbstractObject sourceValues)
- Overrides:
applyChange
in classKMLAbstractObject
-
-