新建mxml外观, <fx:Script>
<![CDATA[
import com.esri.ags.components.ScaleBar;
[Bindable]private var barLength:Number = 0;
[Bindable]private var barHeight:Number = 5;
private var useMetric:Boolean = false;
override protected function measure():void
{
barLength = useMetric == false ? hostComponent.lengthUS : hostComponent.lengthMetric;
scaleLbl.text = useMetric == false ? hostComponent.textUS : hostComponent.textMetric;
// scaleLbl.x = barLength + 3;
// scaleLbl.y = -(scaleLbl.getExplicitOrMeasuredHeight() / 4);
var metric:String = hostComponent.textMetric;
var us:String = hostComponent.textUS;
if(metric)
{
// if(metric.indexOf("km") > 0)
// metric = metric.slice(0,metric.indexOf("km")) +"千米";
// else if(metric.indexOf("m") > 0)
// metric = metric.slice(0,metric.indexOf("m")) + "米";
}
if(us)
{
if(us.indexOf("mi") > 0)
us = us.slice(0,us.indexOf("mi")) + "千米";
if(us.indexOf("ft") > 0)
us = us.slice(0,us.indexOf("ft")) + "米";
}
hostComponent.textUS = us;
// hostComponent.textMetric =metric;
scaleLbl.x = barLength + 3;
scaleLbl.y = -(scaleLbl.getExplicitOrMeasuredHeight() / 4);
super.measure();
}
]]>
</fx:Script>
<fx:Declarations>
<!-- 将非可视元素(例如服务、值对象)放在此处 -->
</fx:Declarations>
<s:Label id="scaleLbl"
fontFamily="Verdana"
fontSize="10"
fontWeight="bold"/>
<s:Rect id="baseRect"
x="0.5" width="{barLength}" height="{barHeight}">
<s:fill>
<s:SolidColor color="#ee0202"/>
</s:fill>
</s:Rect>
<s:Rect x="{baseRect.width/4}" width="{baseRect.width/4}" height="{barHeight}">
<s:fill>
<s:SolidColor color="#009cff"/>
</s:fill>
</s:Rect>
<s:Rect x="{(baseRect.width/4)*3}" width="{baseRect.width/4}" height="{barHeight}">
<s:fill>
<s:SolidColor color="#009cff"/>
</s:fill>
</s:Rect>
05-31