Possible to use addChild() to add display objects to a map object?

778
8
05-13-2013 10:33 AM
JasonCantrell
New Contributor III
I've got a display object component from an older application that I'm trying to integrate into my current application.  Is it possible to use the addChild method of the map object to add this display object to the map (like I would on a Flex canvas or BorderContainer object, using x/y instead of lat/long)?  FlashBuilder tells me it's an accepted method of the map component, but the display objects I'm trying to add are currently not showing up.
Tags (2)
0 Kudos
8 Replies
RobertScheitlin__GISP
MVP Emeritus
Jason,

    If you are trying to add a static item like a logo or text on top of the map then you need to use the map static layer. If you need your object to move with the map when it is panned then you will have to use a true Map XY.
0 Kudos
JasonCantrell
New Contributor III
Jason,

    If you are trying to add a static item like a logo or text on top of the map then you need to use the map static layer. If you need your object to move with the map when it is panned then you will have to use a true Map XY.



I do need the object to move with the map as it is panned.  I believe I am using the true map x/y coordinates when placing them.  I used the MapCoordinates sample that came with my ArcGIS API download to find the map x/y coordinates of the locations I need.

So are you saying that I can use the addChild method to add these objects as long as I'm using the true map XY coordinates?
0 Kudos
RobertScheitlin__GISP
MVP Emeritus
Jason,

   I guess I should be more specific... I depends on what kind of object you are adding. An example of adding a child to the map can be found in Tom Hills Swipe/Spotlight sample:

    private function applyMask( mousePt:Point ):void {
        if (_currentRegion == NONE) {
            return;
        }
        if (!_mask) {
            const w:Number = map.width / Math.abs(map.scaleX);
            const h:Number = map.height / Math.abs(map.scaleY);
            const x:Number = mousePt.x;
            const y:Number = mousePt.y;
            const xy:Number = x + y;
            
            _mask = new Shape();
            
            var g:Graphics = _mask.graphics;
            g.clear();
            g.beginFill(0x000000);
            
            // Render the mask based on the clicked region and the current mouse position
            switch (_currentRegion) {
                case LEFT:
                    g.drawRect(x, 0, w - x, h);
                    break;
                case TOP:
                    g.drawRect(0, y, w, h - y);
                    break;
                case RIGHT:
                    g.drawRect(0, 0, x, h);
                    break;
                case BOTTOM:
                    g.drawRect(0, 0, w, y);
                    break;
                case TOP_LEFT:
                    g.moveTo(w, h);
                    if (xy <= h) {
                        g.lineTo(0, h);
                        g.lineTo(0, xy);
                    } else {
                        g.lineTo(xy - h, h);
                    }
                    if (xy <= w) {
                        g.lineTo(xy, 0);
                        g.lineTo(w, 0);
                    } else {
                        g.lineTo(w, xy - w);
                    }
                    g.lineTo(w, h);
                    break;
                case BOTTOM_RIGHT:
                    g.moveTo(0, 0);
                    if (xy <= w) {
                        g.lineTo(xy, 0);
                    } else {
                        g.lineTo(w, 0);
                        g.lineTo(w, xy - w);
                    }
                    if (xy <= h) {
                        g.lineTo(0, xy);
                    } else {
                        g.lineTo(xy - h, h);
                        g.lineTo(0, h);
                    }
                    g.lineTo(0, 0);
                    break;
                case TOP_RIGHT:
                    g.moveTo(0, h);
                    if (x < y) {
                        g.lineTo(0, y - x);
                    } else {
                        g.lineTo(0, 0);
                        g.lineTo(x - y, 0);
                    }
                    if (w - x < h - y) {
                        g.lineTo(w, y + w - x);
                        g.lineTo(w, h);
                    } else {
                        g.lineTo(x + h - y, h);
                    }
                    g.lineTo(0, h);
                    break;
                case BOTTOM_LEFT:
                    g.moveTo(w, 0);
                    if (w - x < h - y) {
                        g.lineTo(w, y + w - x);
                    } else {
                        g.lineTo(w, h);
                        g.lineTo(x + h - y, h);
                    }
                    if (x < y) {
                        g.lineTo(0, y - x);
                        g.lineTo(0, 0);
                    } else {
                        g.lineTo(x - y, 0);
                    }
                    g.lineTo(w, 0);
                    break;
            }
            
            g.endFill();
            
            // Add the mask to the display list
            map.addChild(_mask);
            
            // Apply the mask to the target layer
            layer.mask = _mask;
        }
    }
0 Kudos
JasonCantrell
New Contributor III
The object I'm trying to add is a custom component that displays a SWF file.  The object represents a wind sensor.  I'm getting a data feed from the wind sensor, and the data is fed into the SWF which shows the data as a waving windsock that changes with the data.  The component itself is a Canvas component with a SWFLoader and various actionscript functions that manage the data for the SWF.

Do I need to have a specific layer to add these objects to?
0 Kudos
RobertScheitlin__GISP
MVP Emeritus
Jason,

   Sorry I have no experience trying to add something like that to the map. I have only done simple objects.
0 Kudos
JasonCantrell
New Contributor III
Could you point me to some examples of adding simple objects to a map with the addChild method?
0 Kudos
RobertScheitlin__GISP
MVP Emeritus
I did in post # 4
0 Kudos
DasaPaddock
Esri Regular Contributor
You can add components to the Map's staticLayer:
http://resources.arcgis.com/en/help/flex-api/apiref/com/esri/ags/Map.html#staticLayer

Using Map.addChild() is not supported.
0 Kudos