If you have an action that is designed to work on a map, typically you want to insert it on each existing map, and on each
new map.
You can do this by adding a listener to the TLcyCombinedMapManager
:
TLcyActionBarManager actionBarManager = aLucyEnv.getUserInterfaceManager().getActionBarManager();
//Obtain a parsed version of the configuration file, e.g. by using a TLcyStringPropertiesCodec
//If using an ALcyPreferencesAddOn, you can use ALcyPreferencesAddOn#getPreferences()
ALcyProperties properties = parseConfigurationFile();
//Create a listener which listens for the creation of map components,
//and which creates and inserts an action for the created map
ILcyGenericMapManagerListener<ILcdView, ILcdLayer> actionCreationListener =
ILcyGenericMapManagerListener.onMapAdded(map -> {
// create a new action for each map.
ILcdAction action = createActionForMap(map);
// insert the action with the map as context
action.putValue(TLcyActionBarUtil.ID_KEY, "MyActionID");
TLcyActionBarUtil.insertInConfiguredActionBars(action,
map,
actionBarManager,
properties);
});
//Register the listener to the map manager,
//and invoke it for all current and future maps
TLcyCombinedMapManager mapManager = aLucyEnv.getCombinedMapManager();
mapManager.addMapManagerListener(actionCreationListener, true);
This listener will create and add a new action instance for each new map.
By using true
as second parameter, you also trigger this listener for already existing maps.
This ensures that the action is also inserted on all existing maps.
If you only want to add the action to a Lightspeed map, you can specify the view type to the |
See:
-
How to create your own configurable action for more information about creating your own actions and configuring them.
-
How to execute code for each current and future map for more information about using a map manager listener.