Package gov.nasa.worldwind.ogc.kml.impl
Class KMLModelPlacemarkImpl
- java.lang.Object
-
- gov.nasa.worldwind.avlist.AVListImpl
-
- gov.nasa.worldwind.WWObjectImpl
-
- gov.nasa.worldwind.ogc.kml.impl.KMLModelPlacemarkImpl
-
- All Implemented Interfaces:
AVList
,MessageListener
,ColladaResourceResolver
,KMLRenderable
,WWObject
,java.beans.PropertyChangeListener
,java.util.EventListener
public class KMLModelPlacemarkImpl extends WWObjectImpl implements KMLRenderable, ColladaResourceResolver
Class to load and render a COLLADA model as the geometry of a KML Placemark.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected static class
KMLModelPlacemarkImpl.RequestTask
Attempts to find this model link resource file locally, and if that fails attempts to find it remotely.
-
Field Summary
Fields Modifier and Type Field Description protected java.util.concurrent.atomic.AtomicReference<ColladaRoot>
colladaRoot
Reference to the COLLADA root that contains the parsed COLLADA file.protected ColladaTraversalContext
colladaTraversalContext
Traversal context for rendering the ColladaRoot.protected KMLModel
model
Model rendered by this class.protected KMLPlacemark
parent
Placemark that contains the model.protected java.util.Map<java.lang.String,java.lang.String>
resourceMap
Map specified by the KML Model's ResourceMap element.protected java.util.concurrent.atomic.AtomicLong
resourceRetrievalTime
Time, in milliseconds since the Epoch, at which this placemark's model resource was last retrieved.
-
Constructor Summary
Constructors Constructor Description KMLModelPlacemarkImpl(KMLTraversalContext tc, KMLPlacemark placemark, KMLAbstractGeometry geom)
Create an instance.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected void
configureColladaRoot(ColladaRoot root)
Apply the model's position, orientation, and scale to a COLLADA root.protected java.util.Map<java.lang.String,java.lang.String>
createResourceMap(KMLModel model)
Build the resource map from the KML Model's ResourceMap element.protected ColladaRoot
getColladaRoot()
Indicates the Collada resource referenced by this placemark.protected boolean
mustRetrieveResource()
Returns whether this placemark must retrieve its model resource.void
preRender(KMLTraversalContext tc, DrawContext dc)
Pre-render this element.void
render(KMLTraversalContext tc, DrawContext dc)
Render this element.protected void
requestResource(DrawContext dc)
Thread's off a task to determine whether the resource is local or remote and then retrieves it either from disk cache or a remote server.java.lang.String
resolveFilePath(java.lang.String path)
Resolve COLLADA references relative to the COLLADA document.protected void
retrieveModel(java.lang.String address)
Initiates a retrieval of the model referenced by this placemark.Once the resource is retrieved and loaded, this calls
to specify this link's new network resource, and sends ansetColladaRoot(ColladaRoot)
property change event to this link's property change listeners.AVKey.RETRIEVAL_STATE_SUCCESSFUL
protected void
setColladaRoot(ColladaRoot root)
Specifies the Collada resource referenced by this placemark, ornull
if this placemark has no resource.-
Methods inherited from class gov.nasa.worldwind.WWObjectImpl
onMessage, propertyChange
-
Methods inherited from class gov.nasa.worldwind.avlist.AVListImpl
addPropertyChangeListener, addPropertyChangeListener, clearList, copy, firePropertyChange, firePropertyChange, getBooleanValue, getBooleanValue, getChangeSupport, getDoubleValue, getDoubleValue, getEntries, getIntegerValue, getIntegerValue, getLongValue, getLongValue, getRestorableStateForAVPair, getStringValue, getStringValue, getStringValue, getValue, getValues, hasKey, removeKey, removePropertyChangeListener, removePropertyChangeListener, setValue, setValues
-
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface gov.nasa.worldwind.avlist.AVList
addPropertyChangeListener, addPropertyChangeListener, clearList, copy, firePropertyChange, firePropertyChange, getEntries, getStringValue, getValue, getValues, hasKey, removeKey, removePropertyChangeListener, removePropertyChangeListener, setValue, setValues
-
Methods inherited from interface gov.nasa.worldwind.event.MessageListener
onMessage
-
-
-
-
Field Detail
-
model
protected KMLModel model
Model rendered by this class.
-
parent
protected KMLPlacemark parent
Placemark that contains the model.
-
colladaRoot
protected java.util.concurrent.atomic.AtomicReference<ColladaRoot> colladaRoot
Reference to the COLLADA root that contains the parsed COLLADA file.
-
resourceRetrievalTime
protected java.util.concurrent.atomic.AtomicLong resourceRetrievalTime
Time, in milliseconds since the Epoch, at which this placemark's model resource was last retrieved. Initially-1
, indicating that the resource has not been retrieved.
-
resourceMap
protected java.util.Map<java.lang.String,java.lang.String> resourceMap
Map specified by the KML Model's ResourceMap element. The map relates relative references within the COLLADA file to paths relative to the KML document.
-
colladaTraversalContext
protected ColladaTraversalContext colladaTraversalContext
Traversal context for rendering the ColladaRoot.
-
-
Constructor Detail
-
KMLModelPlacemarkImpl
public KMLModelPlacemarkImpl(KMLTraversalContext tc, KMLPlacemark placemark, KMLAbstractGeometry geom)
Create an instance.- Parameters:
tc
- the currentKMLTraversalContext
.placemark
- the Placemark element containing the Point.geom
- theKMLPoint
geometry.- Throws:
java.lang.NullPointerException
- if the geometry is null.java.lang.IllegalArgumentException
- if the parent placemark or the traversal context is null.
-
-
Method Detail
-
createResourceMap
protected java.util.Map<java.lang.String,java.lang.String> createResourceMap(KMLModel model)
Build the resource map from the KML Model's ResourceMap element.- Parameters:
model
- Model from which to create the resource map.- Returns:
- Map that relates relative paths in the COLLADA document to paths relative to the KML document.
-
setColladaRoot
protected void setColladaRoot(ColladaRoot root)
Specifies the Collada resource referenced by this placemark, ornull
if this placemark has no resource.- Parameters:
root
- the Collada resource referenced by this placemark. May benull
.
-
getColladaRoot
protected ColladaRoot getColladaRoot()
Indicates the Collada resource referenced by this placemark. This returnsnull
if this placemark has no resource.- Returns:
- this placemark's Collada resource, or
null
to indicate that this placemark has no resource. - See Also:
setColladaRoot(gov.nasa.worldwind.ogc.collada.ColladaRoot)
-
configureColladaRoot
protected void configureColladaRoot(ColladaRoot root)
Apply the model's position, orientation, and scale to a COLLADA root.- Parameters:
root
- COLLADA root to configure.
-
preRender
public void preRender(KMLTraversalContext tc, DrawContext dc)
Pre-render this element.- Specified by:
preRender
in interfaceKMLRenderable
- Parameters:
tc
- the current KML traversal context.dc
- the current draw context.
-
render
public void render(KMLTraversalContext tc, DrawContext dc)
Render this element.- Specified by:
render
in interfaceKMLRenderable
- Parameters:
tc
- the current KML traversal context.dc
- the current draw context.
-
resolveFilePath
public java.lang.String resolveFilePath(java.lang.String path) throws java.io.IOException
Resolve COLLADA references relative to the COLLADA document. If the reference is relative then it will resolved relative to the .dae file, not the kml file. If the COLLADA document may be contained in a KMZ archive the resources will be resolved relative to the .dae file within the archive. Normally references in a KMZ are resolved relative to the root of the archive, but Model references are an exception. See https://developers.google.com/kml/documentation/kmzarchives and https://developers.google.com/kml/documentation/kmlreference#modelResolve a file path..
- Specified by:
resolveFilePath
in interfaceColladaResourceResolver
- Parameters:
path
- A file path relative to a COLLADA document.- Returns:
- An absolute path to the resource, or null if the path cannot be determined.
- Throws:
java.io.IOException
- If an error occurs attempting to locate the resource.
-
mustRetrieveResource
protected boolean mustRetrieveResource()
Returns whether this placemark must retrieve its model resource. This always returnsfalse
if this placemark has noKMLLink
.- Returns:
true
if this placemark must retrieve its model resource, otherwisefalse
.
-
requestResource
protected void requestResource(DrawContext dc)
Thread's off a task to determine whether the resource is local or remote and then retrieves it either from disk cache or a remote server.- Parameters:
dc
- the current draw context.
-
retrieveModel
protected void retrieveModel(java.lang.String address) throws java.io.IOException, javax.xml.stream.XMLStreamException
Initiates a retrieval of the model referenced by this placemark.Once the resource is retrieved and loaded, this calls
to specify this link's new network resource, and sends ansetColladaRoot(ColladaRoot)
property change event to this link's property change listeners.AVKey.RETRIEVAL_STATE_SUCCESSFUL
This does nothing if this
KMLNetworkLink
has noKMLLink
.- Parameters:
address
- the address of the resource to retrieve- Throws:
java.io.IOException
- if a reading error occurs.javax.xml.stream.XMLStreamException
- if a parsing error occurs.
-
-