Product: MapXtreme 2004/2005
Version: 6.0, 6.1, 6.2, 6.5
Platform: Not Platform Related
Category: Layers
Summary:
Determining the feature layer a label layer is associated with.
Question:
When developing a web application, it is desired to use a custom layer control instead of the one that ships with MapXtreme. Labels are now their own layers. However, it is desired to list all of the feature layers in the layer control and have a checkbox that can be clicked to indicate whether the feature layer is labeled. Is it possible to go about enumerating the layers collection to find out which feature layers the label layers are associated with?
Answer:
One thing to remember is that it is possible to add a label source to a label layer that does not have a corresponding feature layer displayed in the map. Here's an example that uses layer filters to determine label layers and extract the tables used for each label source. Then, it takes the array of tables and uses layer filters to determine feature layers that reference that table list.
C# Code:
MapInfo.Mapping.IMapLayerFilter iml = MapInfo.Mapping.MapLayerFilterFactory.FilterByType(typeof(MapInfo.Mapping.LabelLayer ));
MapInfo.Mapping.MapLayerEnumerator mle = mapControl1.Map.Layers.GetMapLayerEnumerator (iml);
ArrayList al=new ArrayList ();
foreach(MapInfo.Mapping.LabelLayer ll in mle)
{
foreach (MapInfo.Mapping.LabelSource l in ll.Sources )
{
//adds the table object to the array list of table objects
al.Add (l.Table);
}
}
//converts the array list of tables objects to an array of table objects
MapInfo.Data.Table[] t=(MapInfo.Data.Table[] )al.ToArray (typeof(MapInfo.Data.Table));
iml=MapInfo.Mapping.MapLayerFilterFactory.FilterByTable (t);
mle=mapControl1.Map.Layers.GetMapLayerEnumerator (iml);
//this returns the features layers in the map for the label sources that are in the map
foreach(MapInfo.Mapping.FeatureLayer fl in mle)
{
Console.WriteLine (fl.Table.Alias );
}
VB.NET:
Dim iml As MapInfo.Mapping.IMapLayerFilter = MapInfo.Mapping.MapLayerFilterFactory.FilterByType(GetType(MapInfo.Mapping.LabelLayer))
Dim mle As MapInfo.Mapping.MapLayerEnumerator = MapControl1.Map.Layers.GetMapLayerEnumerator(iml)
Dim al As ArrayList = New ArrayList
Dim ll As MapInfo.Mapping.LabelLayer
For Each ll In mle
Dim l As MapInfo.Mapping.LabelSource
For Each l In ll.Sources
al.Add(l.Table)
Next
Next
Dim t() As MapInfo.Data.Table = CType(al.ToArray(GetType(MapInfo.Data.Table)), MapInfo.Data.Table())
iml = MapInfo.Mapping.MapLayerFilterFactory.FilterByTable(t)
mle = MapControl1.Map.Layers.GetMapLayerEnumerator(iml)
Dim fl As MapInfo.Mapping.FeatureLayer
For Each fl In mle
Console.WriteLine(fl.Table.Alias)
Next |
Last Modified: 04/14/2006 11:59:55 AM
|