The IlvMapLayerTreeProperty class stores an IlvMapLayerTreeModel.
This layer tree model controls the order and style inheritance of IlvMapLayer you add into your manager. This
model is also persistent data that is saved when you save the map.
The source code for the Map Builder demonstration, which contains
all of the code described in this section, can be found at <installdir> /jviews-maps810/samples/mapbuilder/index.html.
Accessing the map layer tree model
You can access the layer tree model by
calling:
IlvMapLayerTreeModel ltm = IlvMapLayerTreeProperty.GetMapLayerTreeModel(manager);
Controlling the map layer tree
You can allow users to edit and control individual layer styles
by adding an IlvLayerTree bean in your application, see
Using the GUI beans.
Usually, applications only need to add layers with the addChild method, or remove them with the removeChild method of the layer model.
For more information about the map layer tree, see Creating data source objects, Using
data sources, and Developing
a new data source
Adding a listener for layer organization changes
The map tree model is a subclass of
DefaultTreeModel
, so you can add a
TreeModelListener
to your application to trap any change in the layer organization.
Adding a listener for tree structure changes
As the IlvMapLayerTreeProperty is also a named
property of the manager, you can add a listener that is called
whenever the entire tree structure is changed, for example:
manager.addNamedPropertyListener(new NamedPropertyListener() { public void propertyChanged(NamedPropertyEvent event) { if (event.getPropertyName().equals(IlvMapLayerTreeProperty.NAME)) { IlvMapLayerTreeProperty p = (IlvMapLayerTreeProperty) event.getNewValue(); if (event.getType() == NamedPropertyEvent.PROPERTY_SET) { ...do something } } } });
Adding code to all layers
If your application needs to apply a piece of code to all layers,
whatever their depth in the tree, you should call the getEnumeration method of the tree model,
such as:
Enumeration e = ltm.getEnumeration(); while(e.hasMoreElements()) { Object o = e.nextElement(); if(o instanceof IlvMapLayerTreeNode) { IlvMapLayer layer = (IlvMapLayer)((IlvMapLayerTreeNode)o).getUserObject(); ... act on the layer } }
For example, the method clearAllObjects in IlvMapLayerTreeModel calls the
removeAllObjects
for each layer found.