Class LocalVectorDataSource

java.lang.Object
com.massifmaps.datasources.VectorDataSource
com.massifmaps.datasources.LocalVectorDataSource

public class LocalVectorDataSource extends VectorDataSource
A modifiable vector data source that keeps all the elements in the local memory.
Optionally vector elements can be kept in a spatial index and only the visible elements get rendered.
There can be a small delay before previously invisible elements become visible after view changes.
This makes it suitable for cases where there are a large number of static vector elements.

The draw order of vector elements within the data source is undefined.
  • Constructor Details

    • LocalVectorDataSource

      public LocalVectorDataSource(Projection projection)
      Constructs an LocalVectorDataSource object with no spatial index.
      Parameters:
      projection - The projection used by this data source.
    • LocalVectorDataSource

      public LocalVectorDataSource(Projection projection, int spatialIndexType)
      Constructs an LocalVectorDataSource object with specified spatial index.
      Parameters:
      projection - The projection used by this data source.
      spatialIndexType - The spatial index type to use.
  • Method Details

    • clear

      public void clear()
      Clear the data source by removing all elements.
    • getAll

      public VectorElementVector getAll()
      Returns all vector elements added to this data source using add() and addAll() methods.
      Returns:
      A vector containing all the vector elements in this data source.
    • setAll

      public void setAll(VectorElementVector elements)
      Replaces all vector elements in the data source with the given list of vector elements.
      Parameters:
      elements - The list of new vector elements
    • add

      public void add(VectorElement element)
      Adds a vector element to the data source. The vector element's coordinates are expected to be
      in the data source's projection's coordinate system. The order in which the elements are added has
      no effect on the order they get rendered.
      Parameters:
      element - The vector element to be added.
    • addAll

      public void addAll(VectorElementVector elements)
      Adds multiple vector elements to the data source. The vector elements' coordinates are expected to be
      in the data source's projection's coordinate system. The order in which the elements are added has
      no effect on the order they get rendered.
      Parameters:
      elements - A list of vector elements to be added.
    • remove

      public boolean remove(VectorElement element)
      Removes a vector element from the data source.
      Parameters:
      element - The vector element to be removed.
      Returns:
      True if the vector element existed in the data source.
    • removeAll

      public boolean removeAll(VectorElementVector elements)
      Removes multiple vector elements from the data source.
      Parameters:
      elements - A list of vector elements to be removed.
      Returns:
      True if all listed elements were removed. False otherwise.
    • getGeometrySimplifier

      public GeometrySimplifier getGeometrySimplifier()
      Returns the active geometry simplifier of the data source.
      Returns:
      The current geometry simplifier (can be null)
    • setGeometrySimplifier

      public void setGeometrySimplifier(GeometrySimplifier simplifier)
      Attaches geometry simplifier to the data source. If the specified simplifier is null, detaches any active simplifier.
      Parameters:
      simplifier - The new geometry simplifier to use (can be null).
    • getFeatureCollection

      public FeatureCollection getFeatureCollection()
      Returns the elements of this data source as a feature collection. The feature collection can be then serialized as a GeoJSON, for example.
      Returns:
      The feature collection containing all data source elements.
    • addFeatureCollection

      public void addFeatureCollection(FeatureCollection featureCollection, Style style)
      Loads all vector elements from specified feature collection by applying specified style.
      Parameters:
      featureCollection - The feature collection to load elements from.
      style - The geometry collection style to use. Only elements compatible with style are created.
    • getDataExtent

      public MapBounds getDataExtent()
      Description copied from class: VectorDataSource
      Returns the extent of the data of this data source.
      The bounds are in coordinate system of the projection of the data source.
      Overrides:
      getDataExtent in class VectorDataSource
      Returns:
      The extent of the data source.
    • loadElements

      public VectorData loadElements(CullState cullState)
      Description copied from class: VectorDataSource
      Loads all the elements within the defined envelope.
      Overrides:
      loadElements in class VectorDataSource
      Parameters:
      cullState - State for describing view parameters and conservative view envelope.
      Returns:
      The vector of loaded vector elements. If no elements are available, null may be returned.