Class Layers
- java.lang.Object
-
- com.supermap.mapping.Layers
-
public class Layers extends java.lang.Object
The Layers class is a collection of the Layer objects. This class manages all the layers in a Map.A layers object can contain various types of common layers and thematic layers and provides the construction methods for the two types of layers.
This class provides methods such as adding, deleting, searching layers. Also layers can be set to be editable or non-editable. In the meantime, multiple layers in a layers object can be editable at the same time. Thus the users can edit multiple layers simultaneously and achieve higher working efficiency. This allows you to edit multiple layers at the same time, improving productivity.
- Example:
- The following code demonstrates the use of layer collection class to the layer to clear, add, delete and other operations.
public void layersTest() { // Return captial, world, ocean datasets String rootPath = android.os.Environment.getExternalStorageDirectory().getAbsolutePath(); Workspace workspace = new Workspace(); WorkspaceConnectionInfo workspaceConnectionInfo = new WorkspaceConnectionInfo(); workspaceConnectionInfo.setServer(rootPath + "/SampleData/World/World.smwu"); workspaceConnectionInfo.setType(WorkspaceType.SMWU); workspace.open(workspaceConnectionInfo); Datasource datasource = workspace.getDatasources().get(0); Dataset dataset0 = datasource.getDatasets().get("capital"); Dataset dataset1 = datasource.getDatasets().get("world"); Dataset dataset2 = datasource.getDatasets().get("ocean"); // Open map Map map = new Map(workspace); map.open(workspace.getMaps().get(0)); map.refresh(); // Return layer collection Layers layers = map.getLayers(); // Operate on layer collection, including clear, add, delete, etc. layers.clear(); layers.add(dataset1, true); layers.add(dataset0, true); layers.add(dataset2, true); System.out.println(layers.getCount()); layers.remove(2); System.out.println(layers.getCount()); //Release resource map.close(); datasourceConnectInfo.dispose(); workspace.dispose(); }
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method and Description Layer
add(Dataset dataset, boolean addToHead)
Loads a dataset to display it as a common layer in this layers object, namely creates a common layer and adds it to this layers.Layer
add(Dataset dataset, Theme theme, boolean addToHead)
Loads a dataset to display it as a thematic layer in this layers object, namely creates a thematic layer and adds it to this layers, and this thematic layer use the specified Theme object.void
add(Datasource datasource, java.lang.String strSLDFilePath)
Add a layer to the layer collection through the SLD fileboolean
add(Layer layer)
Add a layer to the layer group.LayerGridAggregation
addGridAggregation(Dataset dataset)
Creates a grid map according to the given point datasetLayerGridAggregation
addGridAggregation(Dataset dataset, Color maxColor, Color minColor)
Creates a grid map according to the given point dataset and parameter settingsLayerGroup
addGroup(java.lang.String groupName)
Add a group layer to the layer set.LayerHeatmap
addHeatmap(Dataset dataset, int kernelRadius)
Creates a heat map according to the given point dataset and parameter settingsLayerHeatmap
addHeatmap(Dataset dataset, int kernelRadius, Color maxColor, Color minColor)
Creates a heat map according to the given point dataset and parameter settingsvoid
addLayerAddedListener(LayerAddedListener l)
Adds a listener used to receiveLayerAddedEvent
.void
addLayerGroupAddedListener(LayerGroupAddedListener l)
Adds a listener used to receiveLayerGroupAddedEvent
.void
addLayerGroupRemovedListener(LayerGroupRemovedListener l)
Adds a listener used to receiveLayerGroupRemovedEvent
.void
addLayerRemovedListener(LayerRemovedListener l)
Adds a listener used to receiveLayerRemovedEvent
.void
clear()
Deletes all the layers in this layers object.boolean
contains(java.lang.String name)
Determines whether this layers contains the layer with the specified name.Layer
find(java.lang.String name)
Finds the layer from the layer groupLayer
get(int index)
Returns the layer object with the specified index in the Layers.Layer
get(java.lang.String name)
Returns the layer object with the specified name in the Layers.java.lang.String[]
getAllSubLayersTitle()
Gets a collection of all layer titles, returns an array of strings (for OGC services)Layer
getByCaption(java.lang.String caption)
Gets the layer for the specified aliasint
getCount()
Returns the count of the layer objects in this Layers.int
indexOf(java.lang.String name)
Returns the index of the layer object with the specified name in this layers object.int
indexOfByCaption(java.lang.String caption)
Gets the layer index through the layer aliasLayer
insert(int index, Dataset dataset)
Inserts a dataset to display it as a common layer in this layers object.boolean
insert(int index, Layer layer)
Inserts a layer to the layer group.Layer
insert(int index, java.lang.String strXML)
Inserts a layerLayerGroup
insertGroup(int index, java.lang.String groupName)
Add a group layer to the layer set.boolean
moveDown(int index)
Moves the layer with the specified index backward to below the former lower layer.boolean
moveTo(int srcIndex, int desIndex)
Moves the Layer with the specified index to the target index.boolean
moveToBottom(int index)
Moves the layer with the specified index to the bottom in this layers.boolean
moveToTop(int index)
Moves the layer with the specified index to the topmost position in this layers.boolean
moveUp(int index)
Moves the Layer with the specified index upward to above the former upper layer.boolean
remove(int index)
Deletes a layer with the specified index in this layers.True, if the layer has been deleted successfully.boolean
remove(Layer layer)
Removes the specified layer from the layer set.boolean
remove(java.lang.String name)
Deletes a layer with the specified name in this layers.boolean
removeGroup(LayerGroup group)
Removes the specified group layer from the layer set.void
removeLayerAddedListener(LayerAddedListener l)
Removes a listener used to receiveLayerAddedEvent
.void
removeLayerGroupAddedListener(LayerGroupAddedListener l)
Removes a listener used to receiveLayerGroupAddedEvent
.void
removeLayerGroupRemovedListener(LayerGroupRemovedListener l)
Removes a listener used to receiveLayerGroupRemovedEvent
.void
removeLayerRemovedListener(LayerRemovedListener l)
Removes a listener used to receiveLayerRemovedEvent
.boolean
removeLayersStateListener(LayersStateListener listener)
Removes a listener to receive layer adding, modifying, editing events.int
removeRange(int startIndex, int count)
Deletes the specified count of layers in this layers from the specified index and returns the count of the layer objects that have been deleted.void
setLayersStateListener(LayersStateListener listener)
Add a listener to receive layer adding, modifying, editing events.
-
-
-
Method Detail
-
add
public Layer add(Dataset dataset, boolean addToHead)
Loads a dataset to display it as a common layer in this layers object, namely creates a common layer and adds it to this layers. The style is specified by system.- Parameters:
dataset
- The dataset to add to the layer.addToHead
- Specifies whether the newly created layer is placed at the top level of the layer collection. When set to false, the newly created layer is placed at the bottom.- Returns:
- newly added layers.
- Example:
- See the example of the class
Layers
.
-
add
public Layer add(Dataset dataset, Theme theme, boolean addToHead)
Loads a dataset to display it as a thematic layer in this layers object, namely creates a thematic layer and adds it to this layers, and this thematic layer use the specified Theme object.Note that the thematic map objects of the thematic layer can not be changed to other types of thematic map objects once specified. For example, when you create a thematic map object that specifies the layer as a thematic map object, you can not change it to other thematic map objects such as label thematic maps or statistical thematic maps.
- Parameters:
dataset
- The dataset to add to the layer.theme
- Specifies the thematic map of the thematic layer.addToHead
- Specifies whether the newly created layer is placed at the top level of the layer collection. When set to false, the newly created layer is placed at the bottom.- Returns:
- Newly added thematic layer.
- Example:
- See the example of the class
Layers
.
-
getCount
public int getCount()
Returns the count of the layer objects in this Layers.- Returns:
- the total number of layer objects in this layer collection.
- Default:
- The default value is 0, that is, there is no layer object in the layer collection.
-
removeRange
public int removeRange(int startIndex, int count)
Deletes the specified count of layers in this layers from the specified index and returns the count of the layer objects that have been deleted.- Parameters:
startIndex
- The starting index of the layer to be deleted.count
- The number of layers to delete.- Returns:
- Delete the number of layers.
-
remove
public boolean remove(int index)
Deletes a layer with the specified index in this layers.True, if the layer has been deleted successfully.- Parameters:
index
- The index of the layer to be deleted.- Returns:
- Returns true if the deletion succeeds, false otherwise.
- Example:
- See the example of the class
Layers
.
-
remove
public boolean remove(java.lang.String name)
Deletes a layer with the specified name in this layers.- Parameters:
name
- Remove the name of the layer.- Returns:
- Returns true if the deletion succeeds, false otherwise.
-
clear
public void clear()
Deletes all the layers in this layers object.- Example:
- See the example of the class
Layers
.
-
get
public Layer get(java.lang.String name)
Returns the layer object with the specified name in the Layers.- Parameters:
name
- The name of the layer to return.- Returns:
- A layer object that specifies the name in this layer collection.
- Example:
- See the example
Layer
.
-
get
public Layer get(int index)
Returns the layer object with the specified index in the Layers. The index of the layer in the Layers starts from 0.- Parameters:
index
- The index of the layer to return.- Returns:
- The layer object that specifies the index in this layer collection.
-
indexOf
public int indexOf(java.lang.String name)
Returns the index of the layer object with the specified name in this layers object.- Parameters:
name
- The name of the layer to find.- Returns:
- returns the specified layer to return to the layer index, otherwise returns -1.
-
insert
public Layer insert(int index, Dataset dataset)
Inserts a dataset to display it as a common layer in this layers object.- Parameters:
index
- The index of the inserted data set in the layer.dataset
- The dataset to be inserted.- Returns:
- newly inserted layers.
-
setLayersStateListener
public void setLayersStateListener(LayersStateListener listener)
Add a listener to receive layer adding, modifying, editing events.- Parameters:
listener
- A listener for receiving a layer collection change event.
-
removeLayersStateListener
public boolean removeLayersStateListener(LayersStateListener listener)
Removes a listener to receive layer adding, modifying, editing events.- Parameters:
listener
- A listener for receiving a layer collection change event.- Returns:
- returns true if the listener is removed, false otherwise.
-
contains
public boolean contains(java.lang.String name)
Determines whether this layers contains the layer with the specified name.- Parameters:
name
- may contain the name of the layer object in this layer collection.- Returns:
- Returns true if this layer contains a layer with the specified name, false otherwise.
-
moveToTop
public boolean moveToTop(int index)
Moves the layer with the specified index to the topmost position in this layers.- Parameters:
index
- The index to move to the topmost layer.- Returns:
- Returns true if the move succeeds, false otherwise.
-
moveToBottom
public boolean moveToBottom(int index)
Moves the layer with the specified index to the bottom in this layers.- Parameters:
index
- The index of the layer to move to the bottom layer.- Returns:
- Returns true if the move succeeds, false otherwise.
-
moveUp
public boolean moveUp(int index)
Moves the Layer with the specified index upward to above the former upper layer.- Parameters:
index
- The index of the layer to move.- Returns:
- Returns true if the move succeeds, false otherwise.
-
moveDown
public boolean moveDown(int index)
Moves the layer with the specified index backward to below the former lower layer.- Parameters:
index
- The index of the layer to move.- Returns:
- Returns true if the move succeeds, false otherwise.
-
moveTo
public boolean moveTo(int srcIndex, int desIndex)
Moves the Layer with the specified index to the target index.- Parameters:
srcIndex
- To move the original index of the layer.desIndex
- The target index to which the layer is to be moved.- Returns:
- Returns true if the move succeeds, false otherwise.
-
addGroup
public LayerGroup addGroup(java.lang.String groupName)
Add a group layer to the layer set.- Parameters:
groupName
- The display name of the grouping layer.- Returns:
- Returns the newly added grouping layer.
-
insertGroup
public LayerGroup insertGroup(int index, java.lang.String groupName)
Add a group layer to the layer set.- Parameters:
index
- Specifies the location of the inserted grouping layer.groupName
- The display name of the grouping layer.- Returns:
- the inserted grouping layer.
-
removeGroup
public boolean removeGroup(LayerGroup group)
Removes the specified group layer from the layer set.- Parameters:
group
- Specifies the grouping layer to be removed.- Returns:
- A Boolean value indicating whether the removal of the grouping layer was successful, true for success, and false for failure.
-
add
public boolean add(Layer layer)
Add a layer to the layer group. It is primarily used to move layers in layer group to layer collection. If the layer already exists, it will not be added to the layer collection and false will return.- Parameters:
layer
- Specifies the layer to add.- Returns:
- A boolean indicating whether the layer was successful, true for success, and false for failure.
-
insert
public boolean insert(int index, Layer layer)
Inserts a layer to the layer group. It is primarily used to move layers in layer group to layer collection. If the layer already exists, it will not be added to the layer collection and false will return.- Parameters:
index
- Specifies the index position of the inserted layer.layer
- Specifies the layer to be inserted.- Returns:
- A Boolean value indicating whether the insert layer was successful, true for success, and false for failure.
-
remove
public boolean remove(Layer layer)
Removes the specified layer from the layer set.- Parameters:
layer
- Specifies the layer to be removed.- Returns:
- A Boolean value indicating whether the layer was successful, true for success, and false for failure.
-
addLayerGroupAddedListener
public void addLayerGroupAddedListener(LayerGroupAddedListener l)
Adds a listener used to receiveLayerGroupAddedEvent
.- Parameters:
l
- A listener that receives events that add a grouping layer end event to a layer collection.
-
removeLayerGroupAddedListener
public void removeLayerGroupAddedListener(LayerGroupAddedListener l)
Removes a listener used to receiveLayerGroupAddedEvent
.- Parameters:
l
- A listener that receives events that add a grouping layer end event to a layer collection.
-
addLayerGroupRemovedListener
public void addLayerGroupRemovedListener(LayerGroupRemovedListener l)
Adds a listener used to receiveLayerGroupRemovedEvent
.- Parameters:
l
- A listener that is used to receive a dropout event from a layer collection.
-
removeLayerGroupRemovedListener
public void removeLayerGroupRemovedListener(LayerGroupRemovedListener l)
Removes a listener used to receiveLayerGroupRemovedEvent
.- Parameters:
l
- A listener that is used to receive a dropout event from a layer collection.
-
addLayerAddedListener
public void addLayerAddedListener(LayerAddedListener l)
Adds a listener used to receiveLayerAddedEvent
.- Parameters:
l
- A listener for receiving layers to be added events.
-
removeLayerAddedListener
public void removeLayerAddedListener(LayerAddedListener l)
Removes a listener used to receiveLayerAddedEvent
.- Parameters:
l
- A listener for receiving layers to be added events.
-
addLayerRemovedListener
public void addLayerRemovedListener(LayerRemovedListener l)
Adds a listener used to receiveLayerRemovedEvent
.- Parameters:
l
- A listener for receiving a layer's deleted event.
-
removeLayerRemovedListener
public void removeLayerRemovedListener(LayerRemovedListener l)
Removes a listener used to receiveLayerRemovedEvent
.- Parameters:
l
- A listener for receiving a layer's deleted event.
-
add
public void add(Datasource datasource, java.lang.String strSLDFilePath)
Add a layer to the layer collection through the SLD file- Parameters:
datasource
- The data source where the data is locatedstrSLDFilePath
- SLD file path
-
getAllSubLayersTitle
public java.lang.String[] getAllSubLayersTitle()
Gets a collection of all layer titles, returns an array of strings (for OGC services)- Returns:
- String[] A collection of all layer titles
-
getByCaption
public Layer getByCaption(java.lang.String caption)
Gets the layer for the specified alias- Parameters:
caption
- Layer alias- Returns:
- the layers found out
-
indexOfByCaption
public int indexOfByCaption(java.lang.String caption)
Gets the layer index through the layer alias- Parameters:
caption
- Layer alias- Returns:
- the layer index
-
addHeatmap
public LayerHeatmap addHeatmap(Dataset dataset, int kernelRadius)
Creates a heat map according to the given point dataset and parameter settings- Parameters:
dataset
- Data involved in creating a heat map. The dataset must be a vector point dataset.kernelRadius
- A radius to calculate denisty- Returns:
- The heat map layer
-
addHeatmap
public LayerHeatmap addHeatmap(Dataset dataset, int kernelRadius, Color maxColor, Color minColor)
Creates a heat map according to the given point dataset and parameter settings- Parameters:
dataset
- Data involved in creating a heat map. The dataset must be a vector point dataset.kernelRadius
- A radius to calculate denistymaxColor
- the color of high-value point densityminColor
- the color of low-value point density- Returns:
- The heat map layer
-
addGridAggregation
public LayerGridAggregation addGridAggregation(Dataset dataset)
Creates a grid map according to the given point dataset- Parameters:
dataset
- the point dataset- Returns:
- The grid map
-
addGridAggregation
public LayerGridAggregation addGridAggregation(Dataset dataset, Color maxColor, Color minColor)
Creates a grid map according to the given point dataset and parameter settings- Parameters:
dataset
- the point datasetmaxColor
- the color of high-value point densityminColor
- the color of low-value point density- Returns:
- The grid map
-
insert
public Layer insert(int index, java.lang.String strXML)
Inserts a layer- Parameters:
index
- indexstrXML
- xml layer data- Returns:
- a layer
-
find
public Layer find(java.lang.String name)
Finds the layer from the layer group- Parameters:
name
- Name- Returns:
- a layer
-
-