Select to view content in your preferred language

How do I create a component of just GraphicsLayers?

512
2
02-20-2013 01:44 PM
stevemclaughlin
Occasional Contributor
How do I create a component that has just GraphicsLayers? and then include this component where one layer would normally go?
ex:

<?xml version="1.0" encoding="utf-8"?>
<mx:UIComponent xmlns:fx="http://ns.adobe.com/mxml/2009" 
   xmlns:s="library://ns.adobe.com/flex/spark" 
   xmlns:mx="library://ns.adobe.com/flex/mx" 
   xmlns:esri="http://www.esri.com/2008/ags"
   width="100%" height="100%"
   >

 <esri:WMSLayer  id="wmslayer1" /> 
 <esri:GraphicsLayer id="layer2" />
 <esri:GraphicsLayer id="layer3" />
 <esri:GraphicsLayer id="layer4" />
 <esri:GraphicsLayer id="layer5" />
</mx:UIComponent>


I get this error msg:
'GraphicsLayer' declaration must be contained within the <Declarations> tag since it does not implement 'mx.core.IUIComponent'. 
I thought that all layers extend UIComponent ?

Or do I put them all in the <Declarations> tag , and in the creationsComplete event, add the layers to the parent(map)?

thanks,
Tags (2)
0 Kudos
2 Replies
IvanBespalov
Frequent Contributor
Hi steve.

What is the base idea? Why do you need to keep graphics layers in separate container?

Even if it would have been possible to hold the layers in "UIComponent" it would not give you anything.
UIComponent
The UIComponent class is the base class for all visual components, both interactive and noninteractive.
The UIComponent class is not used as an MXML tag, but is used as a base class for other classes.


But if there is a need in the container, why not take "ArrayCollection"?
private var myGraphicsLayersCollection:ArrayCollection = new ArrayCollection();

private function addGraphicsLayerToCollection():void {
    var grLayer:GraphicsLayer = new GraphicsLayer();
    grLayer.id = "grLayer1";
    grLayer.name = "First Gr Layer";
    myGraphicsLayersCollection.addItem(grLayer);
}

private function getGraphicsLayerFromCollectionById(layerId:String):GraphicsLayer {
    for each (var layer:GraphicsLayer in myGraphicsLayersCollection) {
        if (layerId == layer.id) {
            return layer;
        }
    }
    
    return null;
}

private function removeGraphicsLayerFromCollectionById(layerId:String):Boolean {
    var isRemoved:Boolean = false;
    for each (var layer:GraphicsLayer in myGraphicsLayersCollection) {
        if (layerId == layer.id) {            
            var index:int = layerList.getItemIndex(layer);
     layerList.removeItemAt(index);
            isRemoved = true;
            break;
        }
    }
    return isRemoved;
}

private function collectionToMap():void {
    for each (var layer:GraphicsLayer in myGraphicsLayersCollection) {
        // each layer extends UIComponent, so its ID is unique
        var existingLayer:Layer = mapMap.getLayer(layer.id);
        if (!existingLayer)
            mapMap.addLayer(layer);
    }
}


Sample - [ATTACH=CONFIG]22038[/ATTACH]
0 Kudos
stevemclaughlin
Occasional Contributor
Yes, my basic idea is having a seperate mxml container (component) of layers that I can include in a map.
Is there a mxml equivalent of what you show?
thanks!
0 Kudos