label in polygon

78 views
Skip to first unread message

Amal

unread,
Apr 26, 2012, 12:37:47 PM4/26/12
to openscales-dev
hi everybody,
i found code that add label of featurelayer (point geometry), and i
plane to arrange it, to work with polygon.


the class


package Couches
{
import flash.display.DisplayObject;
import flash.text.TextField;
import flash.text.TextFieldAutoSize;

import mx.controls.Alert;

import org.openscales.core.feature.Feature;
import org.openscales.core.style.marker.Marker;
import org.openscales.geometry.Polygon;

public class MyMarker extends Marker
{
private var _x:int;
private var _y:int;
public function MyMarker(size:Object=6, opacity:Number=1,
rotation:Number=0)
{
super(size, opacity, rotation);
}


override protected function
generateGraphic(feature:Feature):DisplayObject {
var label:TextField = new TextField();
label.autoSize = TextFieldAutoSize.LEFT;
label.x = feature.geometry.bounds.center.lon; // here you can
define the x offset
label.y = feature.geometry.bounds.center.lat;// here you can define
the y offset
// Alert.show("test x="+ feature.geometry.bounds.center.x+" et
y="+feature.geometry.bounds.center.y);
label.text = feature.attributes["CODE"]; // you need to pass in
parameters and

return label;
}
......
}
}


in thes lines

label.x = feature.geometry.bounds.center.lon; // here you can define
the x offset
label.y = feature.geometry.bounds.center.lat;// here you can define
the y offset

i need to put application coordinate, but i don't know the way!!
--->my question is how i can convert a geographic coordinates to
application coordinates???

Amal

unread,
Apr 26, 2012, 12:51:05 PM4/26/12
to openscales-dev

i found it :)
i make the code if someone have the same problem

override protected function
generateGraphic(feature:Feature):DisplayObject {
var label:TextField = new TextField();
label.autoSize = TextFieldAutoSize.LEFT;
var _model:Model=Model.getModel();

var px:Pixel = new Pixel();
px =
_model.map.getMapPxFromLocation(feature.geometry.bounds.center);

label.x =px.x; // here you can define the y offset
label.y = px.y;// here you can define the x offset
Reply all
Reply to author
Forward
0 new messages