Marker: how to set an image normally defined by a Class by using an object that inherits from UIMovieClip ?

53 views
Skip to first unread message

ABA

unread,
Feb 7, 2010, 6:39:47 AM2/7/10
to openscales-dev
Hi,

My problem is not a GIS problem but "simply" an ActionScript problem
about UIMovieClip and Class (embedded object).

My goal is to define a map with some POI represented by numeric
markers as Google Maps do but by replacing "A,B,C,..." with "1, 2,
3,...":
http://maps.google.fr/maps?f=q&source=s_q&hl=fr&geocode=&q=pizzeria,+lyon&sll=46.75984,1.738281&sspn=6.849099,19.753418&ie=UTF8&hq=pizzeria,&hnear=Lyon&z=13

So I define the layer:
var poiLayer:FeatureLayer = new FeatureLayer(poiLayerId, false,
true, srsCode);
then I define the markers:
var marker:Marker;
for each(var poi:Array in poiArray) {
marker = new Marker(new Point(poi[0], poi[1])); // x and y
coordinates
poiLayer.addFeature(marker);
}
and finally I add the layer to the map:
map.addLayer(poiLayer);
and all is ok.

My problem is that I have to change the marker.image to use a marker
that display the number defined by poi[2].
For that I use a swc library that defines:
public dynamic class puceNum extends mx.flash.UIMovieClip { /* ...
*/ }
So before to call poiLayer.addFeature(marker), I've tried to add this:
var markerImage:puceNum = new puceNum();
markerImage.puceColor = poiNumberColor;
markerImage.puceValue = poi[2];
marker.image = transformUIMovieClipInClass(markerImage);
But I've have no idea on how to transform a UIMovieClip in a Class :-(

In Marker.as, the image setter is defined like that:
public function set image(value:Class):void { /* ... */ }
and the default value is:
[Embed(source="/assets/images/marker-blue.png")]
private var _image:Class;

If somebody could help me today it would be great ;-)
Regards,

Aurelien.

ABA

unread,
Feb 7, 2010, 12:35:20 PM2/7/10
to openscales-dev
In fact it seems that the "Marker.set image" function does not do what
it should :-(

Otherwise, I've found a very interesting idea to deal with runtime
assets:

/
*******************************************************************************
*
* Copyright (c) 2007 Ben Stucki
*
* Permission is hereby granted, free of charge, to any person
obtaining a copy
* of this software and associated documentation files (the
"Software"), to deal
* in the Software without restriction, including without limitation
the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/
or sell
* copies of the Software, and to permit persons to whom the Software
is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be
included in
* all copies or substantial portions of the Software.
*
* ------------
*
* 2009, two years later:
*
* some minor changes to the class so it provides displaying any
DisplayObject.
* thanks to ben for sharing his code!
*
* changes by kris (http://krisrok.de)
*
* ------------
*
* 2010, for more details, see :
* http://blog.benstucki.net/?p=42
* http://krisrok.de/blok/?p=70
* and for more ideas, see:
* http://www.adobe.com/devnet/flex/samples/fig_callout/
* the comments of http://blog.benstucki.net/?p=42
*

******************************************************************************/
package
{
import flash.display.BitmapData;
import flash.display.DisplayObject;
import flash.display.Loader;
import flash.display.LoaderInfo;
import flash.display.Sprite;
import flash.events.Event;
import flash.geom.Matrix;
import flash.geom.Rectangle;
import flash.net.URLRequest;
import flash.system.LoaderContext;
import flash.utils.Dictionary;

import mx.containers.accordionClasses.AccordionHeader;
import mx.controls.tabBarClasses.Tab;
import mx.core.BitmapAsset;
import mx.core.UIComponent;

/**
* Provides a workaround for using run-time loaded and created
graphics in
* styles and properties which require a Class reference.
*/
public class IconUtilityPlus extends BitmapAsset
{

private static var dictionary:Dictionary;
private var _animated:Boolean;
private var _displayObject:DisplayObject;

/**
* Used to associate run-time graphics with a target
* @param target A reference to the component associated with this
icon
* @param source Any DisplayObject or a url to a JPG, PNG or GIF
file
* you wish to be loaded and displayed
* @param width Defines the width of the graphic when displayed
* @param height Defines the height of the graphic when displayed
* @return A reference to the IconUtility class which may be treated
* as a BitmapAsset
* @example <mx:Button id="button"
icon="{IconUtility.getClass(button,
* 'http://www.yourdomain.com/images/test.jpg')}" />
*/
public static function getClass(target:UIComponent, source:Object,
animated:Boolean=false, width:Number=-1, height:Number=-1):Class {

if (! dictionary) {
dictionary = new Dictionary(false);
}

var displayObject:DisplayObject;
if (source is String) {
var loader:Loader = new Loader();
loader.load(new URLRequest(source as String), new
LoaderContext(true));
displayObject = loader;
} else {
if (source is DisplayObject) {
displayObject = source as DisplayObject;
}
}
dictionary[target] = { source:displayObject, width:width,
height:height, animated:animated };
return IconUtilityPlus;
}

/**
* @private
*/
public function IconUtilityPlus():void {
addEventListener(Event.ADDED, addedHandler, false, 0, true);
}

private function addedHandler(event:Event):void {
if (parent) {
if (parent is AccordionHeader) {
var header:AccordionHeader = parent as AccordionHeader;
getData(header.data);
} else if (parent is Tab) {
var tab:Tab = parent as Tab;
getData(tab.data);
} else {
getData(parent);
}
}
}

private function getData(object:Object):void {
var data:Object = dictionary[object];
var source:DisplayObject = data.source;
_animated = data.animated;

if(data.width > 0 && data.height > 0) {
bitmapData = new BitmapData(data.width, data.height, true,
0x00FFFFFF);
}

if (source is Loader) {
var loader:Loader = source as Loader;
if (! loader.content) {
loader.contentLoaderInfo.addEventListener(Event.COMPLETE,
completeHandler, false, 0, true);
} else {
_displayObject = loader.content;
startDisplaySource();
}
} else {
if (source is DisplayObject) {
_displayObject = source;
startDisplaySource();
}
}
}

private function startDisplaySource():void {
if (_animated) {
addEventListener(Event.ENTER_FRAME, onEnterFrame);
addEventListener(Event.REMOVED_FROM_STAGE, onRemoveFromStage);
} else {
displaySource();
}
}

private function onRemoveFromStage(e:Event):void {
removeEventListener(Event.ENTER_FRAME, onEnterFrame);
removeEventListener(Event.REMOVED_FROM_STAGE, onRemoveFromStage);
}

private function onEnterFrame(e:Event):void {
if (_animated) {
displaySource();
}
}

private function displaySource():void {
if (! bitmapData) {
bitmapData = new BitmapData(_displayObject.width,
_displayObject.height, true, 0x00FFFFFF);
}

var bounds:Rectangle = _displayObject.getBounds(_displayObject);
bitmapData.draw(_displayObject, new Matrix(bitmapData.width/
bounds.width, 0, 0, bitmapData.height/bounds.height, -
bounds.x*(bitmapData.width/bounds.width), -bounds.y*(bitmapData.height/
bounds.height)));

if (parent is UIComponent) {
var component:UIComponent = parent as UIComponent;
component.invalidateSize();
}
}

private function completeHandler(event:Event):void {
if (event && event.target && event.target is LoaderInfo) {
LoaderInfo(event.target).removeEventListener(Event.COMPLETE,
completeHandler);
_displayObject = LoaderInfo(event.target).content;
startDisplaySource();
}
}

public function get animated():Boolean {
return this._animated;
}
public function set animated(value:Boolean):void {
this._animated = value;
}

}
}

The problem is still open but I've found some

On 7 fév, 12:39, ABA <aurel...@barbier-accary.info> wrote:
> Hi,
>
> My problem is not a GIS problem but "simply" an ActionScript problem
> about UIMovieClip and Class (embedded object).
>
> My goal is to define a map with some POI represented by numeric
> markers as Google Maps do but by replacing "A,B,C,..." with "1, 2,

> 3,...":http://maps.google.fr/maps?f=q&source=s_q&hl=fr&geocode=&q=pizzeria,+...

ABA

unread,
Feb 8, 2010, 11:47:35 PM2/8/10
to openscales-dev
Generally, the IconUtilityPlus class is the solution to the problem of
the summary but for the specific case of the parametrization of a
Marker there is still a problem of conception in OpenScales.
So, we are doing a complete refactor of Marker.as to manage the
different cases related in the discussions of this group.

>  *   the comments ofhttp://blog.benstucki.net/?p=42

ABA

unread,
Feb 8, 2010, 11:55:05 PM2/8/10
to openscales-dev
Please follow news about the refactoing of Marker.as at
http://groups.google.com/group/openscales-dev/browse_thread/thread/9d541c1334217542

> ...
>
> plus de détails »

wei xingfeng

unread,
Feb 9, 2010, 3:52:55 AM2/9/10
to openscales-dev
How to use this plus? Any example I can learn?

I tried the code in this way , and found it can't work:

********************************************************************************************
point=new org.openscales.core.geometry.Point(108, 22);
style=new Style();
style.rules[0]=new Rule();
style.rules[0].symbolizers.push(new PointSymbolizer(new
DisplayObjectMarker(IconUtilityPlus.getClass(point,"http://
maps.google.com/mapfiles/kml/pushpin/ylw-pushpin.png"))));
layer.addFeature(new PointFeature(point, null, style));

**********************************************************************************

The function IconUtilityPlus.getClass() 's first parma is an
UIComponent , then how to use it?

On 8 Feb., 01:35, ABA <aurel...@barbier-accary.info> wrote:
> In fact it seems that the "Marker.set image" function does not do what
> it should :-(
>
> Otherwise, I've found a very interesting idea to deal with runtime
> assets:
>
> /

> ***************************************************************************­****

> ***************************************************************************­***/

Reply all
Reply to author
Forward
0 new messages