public class TLcdKML22StyleProvider extends Object
Provides styles for KML features on demand.
styles can be retrieved synchronously or asynchronously. The provider keeps a cache of styles to optimize performance.
A template for the usage of retrieving styles is as follows:
//variables used in this template
TLcdKML22StyleProvider styleProvider;
TLcdKML22AbstractFeature abstractFeature;
ELcdKML22StyleState styleState;
ILcdKML22ResourceListener callbackFunction;
//the template
//obtain the status of the style to decide what to do
ELcdKML22ResourceStatus imageStatus = styleProvider.getImageStatus( abstractFeature,styleState );
TLcdKML22Style style = null;
switch ( imageStatus ) {
case CACHED:
//the resource is cached, so you can retrieve it synchronously without blocking the calling
//thread
style = styleProvider.retrieveStyle( abstractFeature, styleState );
break;
case LOADING:
//the resource is being loaded. Use a temporary value instead.
style = getLoadingStyle();
break;
case FAULTY:
//the resource is unavailable because it is faulty. A fallback mechanism should be used here
//because the resource itself can't be retried.
style = getFaultyStyle();
break;
case NOT_CACHED:
//the resource is not cached. Start an asynchronous retrieve and used a temporary value instead.
styleProvider.retrieveStyle( abstractFeature,styleState,callbackFunction );
style = getLoadingStyle();
break;
}
Modifier and Type | Method and Description |
---|---|
ELcdKML22ResourceStatus |
getStyleStatus(TLcdKML22AbstractFeature aAbstractFeature,
ELcdKML22StyleState aStyleState)
Gets the status of the style of a given abstract feature
|
TLcdKML22Style |
retrieveStyle(TLcdKML22AbstractFeature aAbstractFeature,
ELcdKML22StyleState aStyleState)
Retrieves a style synchronously.
|
void |
retrieveStyle(TLcdKML22AbstractFeature aAbstractFeature,
ELcdKML22StyleState aStyleState,
ILcdKML22ResourceListener aCallbackFunction)
Retrieves styles asynchronously.
|
public TLcdKML22Style retrieveStyle(TLcdKML22AbstractFeature aAbstractFeature, ELcdKML22StyleState aStyleState)
Retrieves a style synchronously. This method will block the calling thread until the style is returned. This method caches all styles it retrieves, so that subsequent calls will be more performant.
To find out if the style is available before calling this method, use the getStyleStatus(com.luciad.format.kml22.model.feature.TLcdKML22AbstractFeature, com.luciad.format.kml22.model.style.ELcdKML22StyleState) method
aAbstractFeature
- An abstract feature for which a style should be retrievedaStyleState
- The state of the retrieve style. If null, the method will assume a normal style.aAbstractFeature
, or null if the style could not
be retrieved, or the abstract feature did not have a style.getStyleStatus(com.luciad.format.kml22.model.feature.TLcdKML22AbstractFeature, com.luciad.format.kml22.model.style.ELcdKML22StyleState)
public ELcdKML22ResourceStatus getStyleStatus(TLcdKML22AbstractFeature aAbstractFeature, ELcdKML22StyleState aStyleState)
aAbstractFeature
- an abstract featureaStyleState
- a style statepublic void retrieveStyle(TLcdKML22AbstractFeature aAbstractFeature, ELcdKML22StyleState aStyleState, ILcdKML22ResourceListener aCallbackFunction)
Retrieves styles asynchronously. This method will return immediately in all cases and not block the calling thread.
The given callback function will be notified when the style is ready
aAbstractFeature
- An abstract feature for which a style should be retrievedaStyleState
- The state of the retrieve style, if null, the method will assume a normal style.aCallbackFunction
- A resource listener that is to be notified when the given style is updated.