org.geotools.swing.tool
Class VectorLayerHelper

Object
  extended by InfoToolHelper<FeatureCollection>
      extended by VectorLayerHelper

public class VectorLayerHelper
extends InfoToolHelper<FeatureCollection>

Helper class used by InfoTool to query MapLayers with vector feature data.

Implementation note: this class keeps only a weak reference to the MapLayer it is working with to avoid memory leaks if the layer is deleted.

Since:
2.6
Author:
Michael Bedward
See Also:
InfoTool, GridLayerHelper
Module:

Constructor Summary
VectorLayerHelper(MapContext context, MapLayer layer)
          Create a new helper to work with a MapLayer that has vector feature data.
 
Method Summary
 FeatureCollection getInfo(DirectPosition2D pos, Object... params)
          Get feature data at the given position.
 MapLayer getMapLayer()
          Get the MapLayer that this helper is working with.
 boolean isValid()
          Query if this helper has a reference to a MapContext and MapLayer.
 
Methods inherited from class InfoToolHelper
getMapContext, getTransform, isTransformRequired, setCRS
 
Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

VectorLayerHelper

public VectorLayerHelper(MapContext context,
                         MapLayer layer)
Create a new helper to work with a MapLayer that has vector feature data.

Parameters:
layer - the map layer
geomAttributeName - the name of the geometry attribute for Features
geomClass - the geometry class
Method Detail

isValid

public boolean isValid()
Query if this helper has a reference to a MapContext and MapLayer.

Helpers only hold a WeakReference to the map context and layer with which they are working to avoid blocking garbage collection when layers are discarded. If this method returns false the helper should be re-created.


 //
 // Example using a VectorLayerHelper...
 //
 VectorLayerHelper helper = ...

 if (helper != null && helper.isValid()) {
     FeatureCollection coll = helper.getInfo(queryLocation, ...);
     // do something useful with results

 } else {
     // (Re-)create the helper
     // Note: example only; this obviously depends on your use case
     helper = new VectorLayerHelper(context, layer);
 }
 

Specified by:
isValid in class InfoToolHelper<FeatureCollection>
Returns:

getMapLayer

public MapLayer getMapLayer()
Get the MapLayer that this helper is working with.

Returns:
the MapLayer or null if the original layer is no longer valid
See Also:
isValid()

getInfo

public FeatureCollection getInfo(DirectPosition2D pos,
                                 Object... params)
                          throws IOException
Get feature data at the given position.

Specified by:
getInfo in class InfoToolHelper<FeatureCollection>
Parameters:
params - a Double value for the search radius to use with point or line features
pos - the location to query
Returns:
the features that lie within the search radius of pos; if this helper is not valid an empty collection will be returned
Throws:
IOException - if the feature source for the layer cannot be accessed
See Also:
InfoToolHelper.isValid()


Copyright © 1996-2010 Geotools. All Rights Reserved.