skip to main content
Defense > Programmer's documentation > Programming with JViews Maps > Creating a map application using the API > Using data sources
 
Using data sources
Describes how to use data sources.
*Overview
*Describes the main phases involved in using data sources.
*Integrating the data source
*Explains how to integrate a data source.
*Layer styling considerations
*Describes how to manage layer styles correctly.
Overview
Once you have created your data source (see Creating data source objects), integrate it with the manager properties by:
*Inserting it into the data source tree.
*Inserting the associated map layer into the map layer tree.
You can then use layer styling methods to change the styles. Additionally, at some point, the creation of all graphic objects must be started (usually in a background thread).
Integrating the data source
The source code for the Map Builder demonstration, which contains all of the code described in this section, can be found at <installdir> /jviews-maps/samples/mapbuilder/index.html
To integrate the data source and map layer with the manager properties:
1. Insert the data source into the data source tree. You first need to retrieve the data source model from the property of the manager:
 
IlvMapDataSourceModel dataSourceModel =
IlvMapDataSourceProperty.GetMapDataSourceModel(manager);
dataSourceModel.insert(source);
2. Once all data sources have been inserted, you can start loading the data source model by starting all data sources of this model recursively:
 
dataSourceModel.start();
Alternatively, you can start each data source when you want it by calling.
 
source.start();
3. You should also retrieve (and possibly set up) the map layer attached to the data source, for example:
 
IlvMapLayer layer = dataSource.getInsertionLayer();
layer.setName("name in layer tree panel");
Other settings can be done at this stage, such as changing the layer style.
 
layer.getStyle().setAttribute(IlvPolylineStyle.FOREGROUND,Color.black);
layer.getStyle().setAttribute(IlvPolylineStyle.BACKGROUND,new
Color(1,1,1,0.25f));
4. Insert the layer into the map layer tree of the manager. You first need to retrieve the layer tree model from the property of the manager. Here you can arrange the layer structure by selecting the parent layer as appropriate.
 
IlvMapLayerTreeModel ltm =
IlvMapLayerTreeProperty.GetMapLayerTreeModel(manager);
ltm.addChild(parent, layer);
You can reuse the same parent layer for different data sources, possibly retrieving it from the tree model:
 
IlvMapLayer parent = ltm.findChildLayer(null,"my parent");
if(parent==null) {
  parent = new IlvMapLayer();
  parent.setName("my parent");
  IlvMapCompositeStyle parentStyle= new IlvMapCompositeStyle();
  parent.setStyle(parentStyle);
  ltm.addChild(null, parent);
}
Layer styling considerations
The source code for the Map Builder demonstration, which contains all of the code described in this section, can be found at <installdir> /jviews-maps/samples/mapbuilder/index.html
Managing the style parent
To provide style inheritance (accessible in the Layer Tree Panel), the parent layer style must be a composite style, and you need to manage the style parent on its own:
 
IlvMapStyle childStyle=layer.getStyle();
childStyle.setParent(parent.getStyle());
Using dynamic styles
When the application uses dynamic styles, you need to access the style controller property of the manager:
 
IlvMapStyleController themeController =
IlvMapStyleControllerProperty.GetMapStyleController(manager);
With the controller, you can decide on specific style settings for scale intervals. For example, to change the layer visibility:
 
themeController.addTheme(1/100000.0,source.getInsertionLayer(),"Visible");
themeController.getStyle(source.getInsertionLayer(),1/
100000.0).setVisibleInView(true);
themeController.getStyle(source.getInsertionLayer(),1/
100000.0).setVisibleInOverview(false);
If you use multiple dynamic styles, you have to take care of style inheritance in a slightly more complex way because more than one style is used:
 
IlvMapDynamicStyle []t=themeController.getThemes(layer);
for (int i = 0; i < t.length; i++) {
  t[i].getStyle().setParent(parent.getStyle());
}
Once this is done, you can apply the style you want to use for the current scale of the view:
 
themeController.updateTheme(view,layer);
Alternatively, you can set up the theme for all layers in one single call:
 
themeController.updateCurrentTheme();
Layer ordering
With multithreading data sources, it is often impossible to predict the order in which the underlying manager layers are created. The manager layer order determines which graphic objects are on top of the map or in the background. When data sources have been created and inserted, you can arrange the manager layer order to be coherent with the map layer tree organization, with a call to:
 
ltm.arrangeLayers();

Copyright © 2018, Rogue Wave Software, Inc. All Rights Reserved.