Control the visibility of IlvMapLayers depending on the scale

Article ID: 2418
Last updated: 29 May, 2018
Article ID: 2418
Last updated: 29 May, 2018
Revision: 3
Views: 501
Posted: 16 Feb, 2012
by Dean J.
Updated: 29 May, 2018
by Gargani A.

Question

How to control the visibility of IlvMapLayers depending on the scale ?

Answer

It may be interesting to control the visibility of map layers so that some layers are always visible, and others will only be visible when we zoom in. This can improve performance of loading a map, when not zoomed.

The idea is to define IlvMapDynamicStyles and to add them to the IlvMapStyleController associated to your view. Then you can set a given mapDynamicStyle to be visible or not in the view and this will depend on the scale it is associated to.

IlvMapDynamicStyle is a record associating the IlvMapStyle of an IlvMapLayer and a scale.

IlvMapStyleController is used to manage the association of a set of IlvMapStyle and IlvMapLayer objects. Each style is used for a specific layer with a given scale range. This class also provides a TransformerListener that can affect the style in an IlvMapLayer corresponding to a given scale. For that listener to correctly update the theme, you need to make sure a view is attached to the controller through setView(IlvManagerView).

You can see below the key code lines for such implementation. And you will find attached a java class which expects to load a VMAP and for which two map layers have been loaded and their visibility has been defined as follows:

* the "Coastline/Shoreline (Polylines)" layer is set to be always visible,

* the "Administrative Boundary (Polylines)" layer is set to be visible only if scale is greater than 0.000000025.

See attached vmap.java

Key code:

final IlvMapStyleController themeControler = IlvMapStyleControllerProperty.GetMapStyleController(view.getManager());

themeControler.setView(view);

layer.setStyle(new IlvMapCompositeStyle());

mapSource.start();

IlvMapDynamicStyle[] themes = new IlvMapDynamicStyle[2];

int i=0;

int j= 1;

final IlvMapLayer[] childLayers = layer.getChildren();

for (final IlvMapLayer ilvMapLayer: childLayers) {

System.out.println("The layer name = " + ilvMapLayer.getName() );

System.out.println("ilvMapLayer.getStyle " + ilvMapLayer.getStyle());

System.out.println("color " + ilvMapLayer.getStyle().getAttribute(IlvPolylineStyle.FOREGROUND));

themes[i] = new IlvMapDynamicStyle(0.000000025*j, ilvMapLayer.getStyle(), ilvMapLayer.getName());

themeControler.addTheme(ilvMapLayer, themes[i]);

if (ilvMapLayer.getName().trim().equals("Coastline/Shoreline (Polylines)")) {

themeControler.getStyle(ilvMapLayer, 0.000000025*j).setVisibleInView(true);

}

else {

themeControler.getStyle(ilvMapLayer, 0.000000025*j).setVisibleInView(false);

}

i++; j++;

}

This article was:   Helpful | Not helpful
Report an issue
Article ID: 2418
Last updated: 29 May, 2018
Revision: 3
Views: 501
Posted: 16 Feb, 2012 by Dean J.
Updated: 29 May, 2018 by Gargani A.
Attached files


Others in this category