显示标记Google Map API的标签

时间:2012-05-17 14:56:28

标签: c# wpf actionscript-3 flash

我的WPF应用程序使用Flash API进行谷歌地图。一切正常,但我需要在用户点击气球时显示一些自定义细节。

动作脚本代码如下:

var map:Map = new Map(); 
map.key = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"; 
map.sensor = "true"; 
var marker : Marker; 
map.setSize(new Point(stage.stageWidth, stage.stageHeight)); 
map.addEventListener(MapEvent.MAP_READY, onMapReady); 
this.addChild(map);  

var CustN:String;

function onMapReady(event:Event):void 
{   
    var centerLL : LatLng = new LatLng(38.05,-77.036562); 
    map.setCenter( centerLL, 10, MapType.NORMAL_MAP_TYPE); 
    map.addControl(new ZoomControl());
    map.addControl(new PositionControl()); 
    map.addControl(new MapTypeControl());   
    marker = new Marker( centerLL );  
    map.addOverlay( marker );   
    ExternalInterface.addCallback("Search",onSearch); 
}

function onSearch(lat:Number, lon:Number, CustName:String ):void 
{
    CustN  = CustName; 
    var centerLL : LatLng = new LatLng(lat,lon); 
    map.setCenter(centerLL, 10, MapType.NORMAL_MAP_TYPE);   
    marker = new Marker( centerLL );  
    marker.addEventListener(MapMouseEvent.CLICK, onMapClick); 
    map.addOverlay( marker ); 
}

function onMapClick(event:MapMouseEvent):void 
{  
    map.openInfoWindow(event.latLng, new InfoWindowOptions({title: "Click Event", content: CustN})); 
}

我从C#代码中调用onSearch函数,如下所示:

 foreach (var rec in LstCoOrdinates)
        {
            XElement call = new XElement("invoke", new XAttribute("name", "Search"), new XAttribute("returntype", "xml"), new XElement("arguments", new XElement("number", rec.latitude)),
                new XElement("arguments", new XElement("number", rec.longitude)), new XElement("arguments", new XElement("string", rec.name)));
            axFlash.CallFunction(call.ToString(SaveOptions.DisableFormatting));
        }

我需要显示与点击气球相对应的名称

1 个答案:

答案 0 :(得分:0)

您可以在g标记中指定DisplayObject .icon属性。并改变它在点击时的可见性。 预定义标签或单击任意设置它。

marker = new Marker( centerLL );  
marker.icon = new LabelSprite();
marker.icon.visible = false;
marker.addEventListener(MapMouseEvent.CLICK, onMapClick); 
map.addOverlay( marker );

function onMapClick( e:Event ):void
{
  if(selectedMarker) 
     selectedMarker.icon.visible = false;

  selectedMarker = e.currentTarget as Marker;
  selectedMarker.icon.visible = true;
}


public class LabelSprite extends Sprite
{
  private var labelTextField:TextField;

  public function LabelSprite()
  {
    labelTextField = new TextField();
    addChild(labelTextField);
  }

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