Class LayerManager

java.lang.Object
com.kheops.jmap.client.layers.LayerAdapter
com.kheops.jmap.client.layers.LayerManager
All Implemented Interfaces:
JMapEventDispatcher, LayerEventListener, JMapRequestClient, EventListener
Direct Known Subclasses:
SharedLayerManager

public class LayerManager extends LayerAdapter implements JMapRequestClient, JMapEventDispatcher
A LayerManager object responsible for managing two lists of ordered layers:
  • Normal layers: layers that are used to display data. They are normally configured in JMapAdmin, but may be added manually.
  • User layers: these layers are always on top of the normal layers. They can be used to do special work like drawing or adding temporary special elements to the view.
It also provides easy access to these layers, dispatching events to them and to provide methods that operate on all layers it manages. It is associated with a JMapSrvConnection object in order to initiate the data requests on behalf of the layer objects.
  • Field Details

    • DRAW_LAYERS

      public static final int DRAW_LAYERS
      A bit field constant that specifies to draw normal layers.
      See Also:
    • FORCE_DRAW_LAYERS

      public static final int FORCE_DRAW_LAYERS
      A bit field constant that specifies to draw normal layers even if they are not visible.
      See Also:
    • DRAW_LABELS

      public static final int DRAW_LABELS
      A bit field constant that specifies to draw labels.
      See Also:
    • FORCE_DRAW_LABELS

      public static final int FORCE_DRAW_LABELS
      A bit field constant that specifies to draw labels even if they are normally not visible.
      See Also:
    • DRAW_USERS_LAYERS

      public static final int DRAW_USERS_LAYERS
      A bit field constant that specifies to user layers.
      See Also:
    • FORCE_DRAW_USERS_LAYERS

      public static final int FORCE_DRAW_USERS_LAYERS
      A bit field constant that specifies to draw user layers even if they are normally not visible.
      See Also:
    • DRAW_BY_REGION_LAYERS

      public static final int DRAW_BY_REGION_LAYERS
      A bit field constant that specifies to draw layers that use the request mode by region.
      See Also:
    • FORCE_DRAW_BY_REGION_LAYERS

      public static final int FORCE_DRAW_BY_REGION_LAYERS
      A bit field constant that specifies to draw layers that use the request mode by region even if they are normally not visible.
      See Also:
    • DRAW_BASE_OFFIMAGE

      public static final int DRAW_BASE_OFFIMAGE
      A bit field constant that specifies to restore the baseOffImage user layers.
      See Also:
    • DRAW_SYNC

      public static final int DRAW_SYNC
      A bit field constant that specifies to draw layers synchronously.
      See Also:
    • INVALIDATE_LAYERS

      public static final int INVALIDATE_LAYERS
      A bit field constant that specifies to invalidate layers before draw layers.
      See Also:
    • DRAW_STATIC_ELEMENTS

      public static final int DRAW_STATIC_ELEMENTS
      A bit field constant that specifies to draw static elements on the map.
      See Also:
    • DRAW_ALL

      public static final int DRAW_ALL
      A bit field constant that specifies to draw everything.
      The value of this constant is equals to: DRAW_LAYERS | DRAW_LABELS | DRAW_USERS_LAYERS | DRAW_BY_REGION_LAYERS | DRAW_STATIC_ELEMENTS
      See Also:
    • FORCE_DRAW_ALL

      public static final int FORCE_DRAW_ALL
      A bit field constant that specifies to draw everything even if normally not visible.
      The value of this constant is equals to: FORCE_DRAW_LAYERS | FORCE_DRAW_LABELS | FORCE_DRAW_USERS_LAYERS | DRAW_BY_REGION_LAYERS | DRAW_ALL
      See Also:
    • DRAW_USER_LAYERS_AND_LABELS

      public static final int DRAW_USER_LAYERS_AND_LABELS
      A bit field constant that specifies to draw the labels and the user layers.
      The value of this constant is equals to: DRAW_USERS_LAYERS | DRAW_LABELS
      See Also:
    • DRAW_ALL_EXCEPT_LABELS

      public static final int DRAW_ALL_EXCEPT_LABELS
      A bit field constant that specifies to draw all the layers except the labels.
      The value of this constant is equals to: DRAW_USERS_LAYERS | DRAW_LAYERS | DRAW_BY_REGION_LAYERS | DRAW_STATIC_ELEMENTS
      See Also:
    • elementSelector

      protected final AsyncElementSelectorImpl elementSelector
    • userLayers

      protected final Vector<Layer> userLayers
    • layers

      protected Vector<Layer> layers
    • srvConn

      protected JMapSrvConnection srvConn
    • labelManager

      protected LabelManager labelManager
    • verbose

      protected boolean verbose
    • layerTreeGroup

      protected LayerTreeGroup layerTreeGroup
    • eventDispatcher

      protected final LayerEventDispatcher eventDispatcher
    • memoryCleanupNeeded

      protected boolean memoryCleanupNeeded
    • precisionModel

      protected PrecisionModel precisionModel
  • Constructor Details

    • LayerManager

      public LayerManager(JMapSrvConnection srvConn, boolean useMemRelease, long maxUsedMem, float perRelMem, boolean useCache, long diskCacheSize)
      Creates a new LayerManager associated with the specified JMapSrvConnection.
      Parameters:
      srvConn - a connection to JMapServer.
      useMemRelease - whether to use the memory management.
      maxUsedMem - the maximum memory (in bytes) that can be allocated to data.
      perRelMem - the percentage of memory to release when releasing memory.
      useCache - whether using disk cache.
      diskCacheSize - the maximum size of the disk cache.
    • LayerManager

      public LayerManager(JMapSrvConnection srvConn, boolean useMemRelease, long maxUsedMem, float perRelMem, boolean useCache, File cachePath, long diskCacheSize)
      Creates a new LayerManager associated with the specified JMapSrvConnection.
      Parameters:
      srvConn - a connection to JMapServer.
      useMemRelease - whether to use the memory management.
      maxUsedMem - the maximum memory (in bytes) that can be allocated to data.
      perRelMem - the percentage of memory to release when releasing memory.
      useCache - whether using disk cache.
      cachePath - a File that defined the path of the disk cache.
      diskCacheSize - the maximum size of the disk cache.
    • LayerManager

      public LayerManager(JMapSrvConnection srvConn)
      Creates a new LayerManager instance.
      Parameters:
      srvConn - the connection to JMapServer to use.
      See Also:
  • Method Details

    • initEventDispatcher

      protected LayerEventDispatcher initEventDispatcher()
    • setVerbose

      public void setVerbose(boolean verbose)
      Parameters:
      verbose - The verbose mode
    • getVerbose

      public boolean getVerbose()
      Returns:
      Returns the verbose mode
    • getConnection

      public JMapSrvConnection getConnection()
      Returns the current connection associated with this LayerManager.
      Returns:
      a reference to the current connection.
    • setDefaultSelectionColor

      public void setDefaultSelectionColor(Color selectionColor)
    • close

      public void close()
    • finalize

      public void finalize() throws Throwable
      Overrides:
      finalize in class Object
      Throws:
      Throwable
    • getDiskTileCache

      public JMapLocalTileCache getDiskTileCache()
    • createDrawLayers

      public void createDrawLayers()
      This method creates and adds different drawing layers in the Layer Manager
    • createLayers

      public void createLayers(Project project, LayerInfo[] layerDescs, LayerTreeGroup packedLayerGroup)
      TODO comment
      Parameters:
      project - the project associated
      layerDescs - a vector containing the descriptions of the layers
    • callback

      public void callback(JMapRequest request, JMapResponse response)
      This method will be called when a request is executed.
      Specified by:
      callback in interface JMapRequestClient
      Parameters:
      request - the original request
      response - the resulting response received from the server
      See Also:
    • cancelCallback

      public void cancelCallback(JMapRequest request)
      This method will be called when a request has been ignored by servicing thread.
      Specified by:
      cancelCallback in interface JMapRequestClient
      Parameters:
      request - the original request
      See Also:
    • processVectorDataRegionResponse

      protected void processVectorDataRegionResponse(JMapServerRequest.ExtractElements request, JMapServerResponse.ExtractElements response, boolean sync) throws Exception
      Throws:
      Exception
    • processRasterDataResponse

      protected void processRasterDataResponse(JMapServerRequest.ExtractRasterData request, JMapServerResponse.ExtractRasterData response, boolean sync)
    • processVectorDataTileResponse

      protected void processVectorDataTileResponse(JMapServerRequest.ExtractTile request, JMapServerResponse.ExtractTile response, boolean sync)
    • processVectorDataTileResponseImpl

      protected void processVectorDataTileResponseImpl(JMapServerRequest.ExtractTile request, JMapServerResponse.ExtractTile response, boolean sync)
    • draw

      public void draw(ViewState viewState, GraphicsRef gr, int drawOptions)
      Draws specified layers and auto labels into the specified GraphicsRef object.
      Parameters:
      viewState - the state of the view requesting the draw.
      gr - a wrapper to a Graphics object to draw on.
      drawOptions - a bit field value that specifies what to draw.
    • cleanupMemory

      protected void cleanupMemory()
    • processReceivedTile

      protected void processReceivedTile(VectorLayer layer, Tile tile, byte[] compressedData, long lastUseTime)
    • addUserLayer

      public void addUserLayer(Layer layer)
      Adds a new user layer on top of all other user layers.
      Parameters:
      layer - the layer to be added
      Since:
      JMap 2.5
    • addUserLayer

      public void addUserLayer(Layer layer, int pos)
      Adds a new user layer at a specific position.
      Parameters:
      layer - the layer to be added
      pos - the layer position
      Since:
      JMap 2.5
    • addLayer

      public void addLayer(Layer layer)
      Adds a new layer on top of all others
      Parameters:
      layer - the layer to be added
    • addLayer

      public void addLayer(Layer layer, int pos)
      Inserts a layer at a specific position
      Parameters:
      layer - the layer to be inserted
      pos - the layer position
    • addLayerImpl

      protected void addLayerImpl(Vector<Layer> layerVect, Layer layer, int pos, boolean addToTree)
    • removeAllLayers

      public void removeAllLayers()
      Removes all layers.
    • removeLayer

      public boolean removeLayer(int pos)
      Removes the layer at the specified position.
      Parameters:
      pos - the position
      Returns:
      boolean flag indicating if the layer was removed successfully
    • moveUp

      public int moveUp(int pos, boolean fireEvent)
      Moves the layer (located at specified position) one position up if possible and returns the new position.
      Parameters:
      pos - the initial position
      fireEvent - indicates if an event should be fired
      Returns:
      the final position
    • moveDown

      public int moveDown(int pos, boolean fireEvent)
      Moves the layer (located at specified position) one position down if possible and returns the new position.
      Parameters:
      pos - the initial position
      fireEvent - indicates if an event should be fired
      Returns:
      the final position
    • moveLayerTo

      public void moveLayerTo(int layerPos, int newPos, boolean fireEvent)
      Moves a layer to a specific position
      Parameters:
      layerPos - the initial layer position to move
      newPos - the final position
      fireEvent - if view needs to be refreshed
    • getCount

      public int getCount()
      Returns the number of layers managed by this layer manager.
      Returns:
      the layer count.
    • getLayerByPos

      public Layer getLayerByPos(int pos)
      Returns the layer at the specified position
      Parameters:
      pos - the layer position
      Returns:
      the layer at the specified position
    • getLayer

      public Layer getLayer(int id)
      Returns the layer with the specified id
      Parameters:
      id - the layer id
      Returns:
      the layer with the specified id
    • getLayer

      public Layer getLayer(String name)
      Returns the layer with the specified name
      Parameters:
      name - the layer name
      Returns:
      the layer with the specified name
    • getPosByName

      public int getPosByName(String name)
      Returns the position of the layer with the specified name
      Parameters:
      name - the layer name
      Returns:
      the position of the layer with the specified name
    • getLayerPos

      public int getLayerPos(Layer layer)
      Returns the position of the specified layer object. with the specified name
      Parameters:
      layer - the layer object
      Returns:
      the position of the specified layer
    • getLayers

      public Layer[] getLayers()
      Returns an array containing normal layers.
      Returns:
      an array containing normal layers.
      Since:
      JMap 2.5
    • getUserLayers

      public Layer[] getUserLayers()
      Returns an array containing user layers.
      Returns:
      an array containing user layers.
      Since:
      JMap 2.5
    • getAllLayers

      public Layer[] getAllLayers()
      Returns an array containing both normal and user layers.
      Returns:
      an array containing all layers.
      Since:
      JMap 2.5
    • addLayerEventListener

      public void addLayerEventListener(LayerEventListener listener)
      Adds a layer event listener to the list of listeners.
      Parameters:
      listener - the new listener to be added
    • removeLayerEventListener

      public void removeLayerEventListener(LayerEventListener listener)
      Removes a layer event listener from the list of listeners.
      Parameters:
      listener - the listener to be removed
    • fireLayerReceivedDataEvent

      protected void fireLayerReceivedDataEvent(Layer layer, Tile[] tiles, boolean sync)
    • dispatchEvent

      public void dispatchEvent(JMapEvent event)
      The dispatchEvent method is used to dispatch synchronously JMap events to all registered listeners. The main use of the JMapEventDispatcher interface is to dispatch events that were previously added to the JMap event queue.
      Note: only LayerEvent will be accepted by this method. Any other JMap event types will cause the layer manager to throw an exception.
      Specified by:
      dispatchEvent in interface JMapEventDispatcher
      Parameters:
      event - the event to be dispatched.
      Throws:
      IllegalArgumentException - will be thrown if the JMapEvent instance is no an instance of the LayerEvent class.
      See Also:
    • getTotalLayerExtent

      public Rectangle getTotalLayerExtent()
      Returns a Rectangle that completely contains every layer that is managed by this layer manager. In other words, the addition of all layer extents.
      Returns:
      the combined extent of all layers
    • getDisplaySelectedBounds

      public Rectangle getDisplaySelectedBounds(ViewState viewState)
      Returns a DC Rectangle that completely contains every selection of every layer that is managed by this layer manager.
      Parameters:
      viewState - the state of the current view.
      Returns:
      the DC bounding box of all layer selections
    • getDisplaySelectedBounds

      public Rectangle getDisplaySelectedBounds(ViewState viewState, boolean zoomed)
      Returns a DC Rectangle that completely contains every selection of every layer that is managed by this layer manager.
      Parameters:
      viewState - the state of the current view.
      zoomed - defines if display selected bounds should be computed with the transformation matrix scaled at the geometry extent (zoomed) or at the current scale (not zoomed).
      Returns:
      the DC bounding box of all layer selections
      Since:
      JMap 4.0.2
    • getSelectedExtent

      public Rectangle getSelectedExtent()
    • getSelectionSize

      public int getSelectionSize()
      Returns the total number of selected elements of every layer that is managed by this layer manager.
      Returns:
      the number of selected elements in all layers
    • clearAllSelection

      public void clearAllSelection()
      Empties the selection of every layer that is managed by this layer manager.
    • getLowestSelectPos

      public int getLowestSelectPos()
      Returns the position of the lowest layer that has at least one selected element.
      Returns:
      the position of the lowest layer that has at least one selected element.
    • getSelectedElements

      public K2DElement[] getSelectedElements()
      Returns an array of all selected elements on all layers managed by this layer manager.
      Returns:
      the selected elements from all layers
    • getElementsAtPoint

      public K2DElement[] getElementsAtPoint(Point wcCoord, ViewState viewState, boolean onlySelectable)
      Returns the elements found at the specified point in world coordinate system. All visible and displayed vector layers and elements are considered but, if the specified boolean is true, only selectable layers are searched. The first element found on the highest layer is placed at position 0 in the array and the last element found on the lowest layer is at position length - 1 in the returned array. This method is equivalent to calling the getElementsAtPoint method on all layers of this layer manager, sorted from top layer to bottom layer.
      Parameters:
      wcCoord - the world coordinate where to look for elements
      viewState - the view in which the test is done
      onlySelectable - search only selectable layers
      Returns:
      all visible elements found at the specified point or an empty array if none was found.
      Since:
      JMap 4.0
    • layerPropertyBeforeChangeEventOccurred

      public void layerPropertyBeforeChangeEventOccurred(LayerPropertyBeforeChangeEvent e)
      Handles property before change events.
      Specified by:
      layerPropertyBeforeChangeEventOccurred in interface LayerEventListener
      Overrides:
      layerPropertyBeforeChangeEventOccurred in class LayerAdapter
      Parameters:
      e - the corresponding public
    • layerPropertyChangedEventOccurred

      public void layerPropertyChangedEventOccurred(LayerPropertyChangedEvent e)
      Handles property changed events.
      Specified by:
      layerPropertyChangedEventOccurred in interface LayerEventListener
      Overrides:
      layerPropertyChangedEventOccurred in class LayerAdapter
      Parameters:
      e - the corresponding LayerPropertyChangedEvent
    • layerSelChangedEventOccurred

      public void layerSelChangedEventOccurred(LayerSelChangedEvent e)
      Handles selection change events.
      Specified by:
      layerSelChangedEventOccurred in interface LayerEventListener
      Overrides:
      layerSelChangedEventOccurred in class LayerAdapter
      Parameters:
      e - the corresponding LayerSelChangedEvent
    • layerDataRequestedEventOccurred

      public void layerDataRequestedEventOccurred(LayerDataRequestedEvent event)
      Handles data request events.
      Specified by:
      layerDataRequestedEventOccurred in interface LayerEventListener
      Overrides:
      layerDataRequestedEventOccurred in class LayerAdapter
      Parameters:
      event - the corresponding LayerDataRequestedEvent
    • processVectorDataRegionRequest

      protected void processVectorDataRegionRequest(VectorDataRequestedEvent event)
    • processReceivedRegion

      protected void processReceivedRegion(VectorLayer vectorLayer, JMapGeoElement[] elements, OrientedRectangle requestedExtent, boolean sync)
    • processRasterDataRequest

      protected void processRasterDataRequest(RasterDataRequestedEvent event)
    • processVectorDataTileRequest

      protected void processVectorDataTileRequest(VectorDataRequestedEvent event)
    • getCurrentProject

      public Project getCurrentProject()
    • executeRequest

      protected JMapServerResponse executeRequest(JMapServerRequest request)
    • layerReceivedDataEventOccurred

      public void layerReceivedDataEventOccurred(LayerReceivedDataEvent event)
      Called when new data is received from the server.
      Specified by:
      layerReceivedDataEventOccurred in interface LayerEventListener
      Overrides:
      layerReceivedDataEventOccurred in class LayerAdapter
      Parameters:
      event - the event object.
    • layerDisplayFilterChangedEventOccurred

      public void layerDisplayFilterChangedEventOccurred(LayerDisplayFilterChangedEvent event)
      Specified by:
      layerDisplayFilterChangedEventOccurred in interface LayerEventListener
      Overrides:
      layerDisplayFilterChangedEventOccurred in class LayerAdapter
    • layerQueryFilterChangedEventOccurred

      public void layerQueryFilterChangedEventOccurred(LayerQueryFilterChangedEvent event)
      Specified by:
      layerQueryFilterChangedEventOccurred in interface LayerEventListener
      Overrides:
      layerQueryFilterChangedEventOccurred in class LayerAdapter
    • layerStyleChangedEventOccurred

      public void layerStyleChangedEventOccurred(LayerStyleChangedEvent event)
      Handles style changes events.
      Specified by:
      layerStyleChangedEventOccurred in interface LayerEventListener
      Overrides:
      layerStyleChangedEventOccurred in class LayerAdapter
      Parameters:
      event - the event
      Since:
      JMap 2.5
    • layerRefreshRequestEvent

      public void layerRefreshRequestEvent(LayerRefreshRequestEvent event)
      Handles layerRefreshRequestEvent
      Specified by:
      layerRefreshRequestEvent in interface LayerEventListener
      Overrides:
      layerRefreshRequestEvent in class LayerAdapter
    • layerAddedEventOccurred

      public void layerAddedEventOccurred(LayerAddedEvent event)
      Fires a layerAddedEvent each time a layer is added
      Specified by:
      layerAddedEventOccurred in interface LayerEventListener
      Overrides:
      layerAddedEventOccurred in class LayerAdapter
      Parameters:
      event - the event
    • layerElementsChangedEventOccurred

      public void layerElementsChangedEventOccurred(LayerElementsChangedEvent event)
      Fires a LayerElementsChangedEvent when an element is changed
      Specified by:
      layerElementsChangedEventOccurred in interface LayerEventListener
      Overrides:
      layerElementsChangedEventOccurred in class LayerAdapter
      Parameters:
      event - the event
    • layerElementsAddedEventOccurred

      public void layerElementsAddedEventOccurred(LayerElementsAddedEvent event)
      Fires a LayerElementsAddedEvent when an element is added
      Specified by:
      layerElementsAddedEventOccurred in interface LayerEventListener
      Overrides:
      layerElementsAddedEventOccurred in class LayerAdapter
      Parameters:
      event - the event
    • layerElementsRemovedEventOccurred

      public void layerElementsRemovedEventOccurred(LayerElementsRemovedEvent event)
      Fires a layerElementsRemovedEventOccurred when an element is removed
      Specified by:
      layerElementsRemovedEventOccurred in interface LayerEventListener
      Overrides:
      layerElementsRemovedEventOccurred in class LayerAdapter
      Parameters:
      event - the event
    • layerPosChangedEventOccurred

      public void layerPosChangedEventOccurred(LayerPosChangedEvent event)
      Fires a LayerPosChangedEvent when a layer position is changed
      Specified by:
      layerPosChangedEventOccurred in interface LayerEventListener
      Overrides:
      layerPosChangedEventOccurred in class LayerAdapter
      Parameters:
      event - the event
    • layerRemovedEventOccurred

      public void layerRemovedEventOccurred(LayerRemovedEvent event)
      Fires a layerRemovedEventOccurred when a layer is removed
      Specified by:
      layerRemovedEventOccurred in interface LayerEventListener
      Overrides:
      layerRemovedEventOccurred in class LayerAdapter
      Parameters:
      event - the event
    • getLabelManager

      public LabelManager getLabelManager()
      Returns the KLabelManager object created by this LayerManager instance.
      Returns:
      the KLabelManager object created by this LayerManager instance.
      Since:
      JMap 2.5
    • getLogos

      public Object[] getLogos()
    • getMaxUsedMem

      public long getMaxUsedMem()
      Returns the maximum size of the memory that can be allocated to data.
      Returns:
      the maximum size of the memory in bytes.
    • usesMemRelease

      public boolean usesMemRelease()
      Returns whether to use the memory management.
      Returns:
      a boolean which indicates whether the memory management is currently used.
    • usesCache

      public boolean usesCache()
      Returns whether this LayerManager is using its cache.
      Returns:
      whether this LayerManager is using its cache.
    • setMaxUsedMem

      public void setMaxUsedMem(long maxUsedMem)
      Sets the maximum size of the memory that can be allocated to data.
      Parameters:
      maxUsedMem - the maximum size of the memory in bytes.
    • setUseMemRelease

      public void setUseMemRelease(boolean useMemRelease)
      Sets whether to use the memory management.
      Parameters:
      useMemRelease - indicates whether to use the memory management.
    • setPerMemRelease

      public void setPerMemRelease(float perMemRelease)
      Sets the percentage of memory to release when releasing memory.
      Parameters:
      perMemRelease - the percentage of memory to release when releasing memory.
    • getPerMemRelease

      public float getPerMemRelease()
      Returns the percentage of memory to release when releasing memory.
      Returns:
      the percentage of memory to release when releasing memory.
    • getDiskCacheSize

      public long getDiskCacheSize()
      Returns the maximum size of the disk cache.
      Returns:
      the maximum size of the disk cache.
    • getMemoryMonitoringInfo

      public MemoryMonitoringInfo getMemoryMonitoringInfo()
    • setConnection

      public void setConnection(JMapSrvConnection conn)
    • setPrecisionModel

      public void setPrecisionModel(PrecisionModel precisionModel)
      Sets the precision model to use for geometrical operations.
      Parameters:
      precisionModel - the precision model to use.
      Since:
      4.0.3
    • getPrecisionModel

      public PrecisionModel getPrecisionModel()
      Returns the precision model to use for geometrical operations.
      Returns:
      the precision model to use for geometrical operations.
      Since:
      4.0.3
    • getElementSelector

      public AsyncElementSelector getElementSelector()
      Returns:
      Returns the elementSelector.
    • getLayerTreeVisibility

      public LayerVisibilitySet getLayerTreeVisibility()
    • getLayerTreeGroup

      public LayerTreeGroup getLayerTreeGroup()
    • invalidateLayer

      public void invalidateLayer(int layerId)
      Invalidates the specified layer as well as the Disk Cache
      Parameters:
      layerId -
      Since:
      6.5