Ok, thanks again to everyone, I thought I'd share my final solution
now that it's stable; it does the following:

- give a placemark consisting of an icon and a text above the icon
- the text is centered and comes in a font of your choice

The placemark is put into a 3d object which (in turn) can be put into
the scene. Things you need to replace are marked with //TODO.

package customobjects  //TODO replace with your package
{
        import away3d.sprites.MovieClipSprite;
        import flash.display.Bitmap;
        import flash.text.TextField;
        import org.aswing.AssetIcon;
        import flash.display.Sprite;
        import flash.text.TextFormat;
        import flash.text.TextFormatAlign;
        import flash.display.PixelSnapping;
        import flash.text.TextFieldAutoSize;
        import flash.text.AntiAliasType;
        import away3d.core.utils.Cast;

        /**
         * @author gabriel
         */
        public class PlacemarkObject extends MovieClipSprite
        {
               // The following two lines embed the font that you are
going to use:
               [Embed(source = "assets/verdana.ttf", fontFamily =
"verdana", mimeType = "application/x-font-truetype")] //TODO replace
"assets/verdana.ttf"
               private var _font:String;

               // The following two lines embed the icon you are going
to use:
               [Embed(source="assets/icon.png")] //TODO replace
"assets/icon.png"
               private var _icon:Class;

                private var placemark:Sprite;
                private var label:TextField;
                private var icon:Bitmap;

                // these options are hard-coded for the moment; you
could give them to your constructor instead, if you like.
                private const FONT_NAME:String = "verdana";
                private const FONT_SIZE:Number = 14;
                private const FONT_COLOR:uint = 0x000000;
                private const PLACEMARK_SIZE:Number = 24;

                public function PlacemarkObject(text:String = "", init:Object =
null)
                {
                        placemark = new Sprite();

                        var format:TextFormat = new TextFormat();
                        format.font = FONT_NAME;
                        format.color = FONT_COLOR;
                        format.size = FONT_SIZE;

                        label = new TextField();
                        label.embedFonts = true;
                        label.autoSize = TextFieldAutoSize.CENTER;
                        label.antiAliasType = AntiAliasType.ADVANCED;
                        label.defaultTextFormat = format;
                        label.text = text;
                        label.selectable = false;
                        label.x = 0;
                        label.y = -PLACEMARK_SIZE * 0.75;   // 0.75 was obtained
empirically, you can put something else here if you wish

                        icon = new Bitmap(Cast.Bitmap(_icon));
                        icon.width = PLACEMARK_SIZE;
                        icon.height = PLACEMARK_SIZE;
                        icon.x = (label.width / 2) - (PLACEMARK_SIZE / 2);
                        icon.y = (label.height/ 2) - (PLACEMARK_SIZE / 2);
                        icon.smoothing = true;
                        icon.pixelSnapping = PixelSnapping.ALWAYS;

                        placemark.addChild(icon);
                        placemark.addChild(label);

                        super(placemark, init);
                        this.rescale = false; //TODO if you set this to true, 
placemark
will scale with camera distance
                        this.deltaZ = -1000; //TODO this lets the placemark be 
rendered
before all other objects, you may or may not need this depending upon
your app
                }

                public function get text():String {
                        return label.text;
                }

                public function set text(value:String):void {
                        label.text = value;
                }


        }

}



On 3 Apr., 14:39, Fabrice <[email protected]> wrote:
> Gabriel,
> Its a very easy thing to do using 2d sprites
> just make a movieclip instance, _mc,  and pass it to the  
> MovieClipSprite Class like this
>
> //if you need some mouse interaction...
>         _mc.addEventListener(MouseEvent.MOUSE_DOWN, dosomething);
> // declare the instance
>         var mymarker: MovieClipSprite = new MovieClipSprite(_mc, {scaling:2,  
> rescale:true, align:"center"});
> // show
>         view.scene.addChild(mymarker);
>
> notice the new "align" property... if you want no align for custom  
> purposes, just {align:"none"}
>
> For the BBC project I'm using a bit more complex pointers, dynamically  
> generated.
> but it come basically to this:
> make a ObjectContainer3D, add your 3D and 2D. Drive the container.
>
> Fabrice
>
> On Apr 3, 2009, at 2:10 PM, gabe wrote:
>
>
>
> > i need to display aplacemark(an icon and a text directly on top of
> > it) over a location in 3d space. i figured out i could use a textbox
> > for the text, which is wrapped into a sprite; however, the text should
> > be right on top of the icon, and the origin of the whole thing should
> > be at the bottom. i am not a flash guru, i merely work with
> > papervision using FlashDevelop. The question is whether the placemarks
> > provided in aforementioned demo were made programmatically (and how)
> > or were they somehow clicked together in a flash (flex?) ide.
>
> > cheers,
> > gabriel

Reply via email to