zoukankan      html  css  js  c++  java
  • FLEX AS3.0 百度地图

    window xp系统 FlashBuilder4.5

    先上百度下载flash api 下载地址http://developer.baidu.com/map/flash.htm

    新建一个flex项目

    右键项目→属性→Flex构件路径   导入BMap.swc(下载的flash api)

     

    map1.mxml

      1 <?xml version="1.0" encoding="utf-8"?>
      2 <s:WindowedApplication xmlns:fx="http://ns.adobe.com/mxml/2009" 
      3                        xmlns:s="library://ns.adobe.com/flex/spark" 
      4                        xmlns:mx="library://ns.adobe.com/flex/mx"
      5                        xmlns:maps="com.earthplayer.maps.*"
      6                        creationComplete="init()"
      7                        width="1200"
      8                        height="700"
      9                        x="0" y="0"
     10                        >
     11     <fx:Declarations>
     12         <!-- Place non-visual elements (e.g., services, value objects) here -->
     13         <mx:HTTPService id="myService" url="area.xml" />
     14     </fx:Declarations>
     15     <fx:Script>
     16         <![CDATA[
     17             import baidu.map.basetype.LngLat;
     18             import baidu.map.basetype.Size;
     19             import baidu.map.control.base.Navigator;
     20             import baidu.map.control.base.Overview;
     21             import baidu.map.control.base.Ruler;
     22             import baidu.map.control.base.Scaler;
     23             import baidu.map.core.Map;
     24             import baidu.map.layer.Layer;
     25             import baidu.map.layer.RasterLayer;
     26             import baidu.map.overlay.InfoWindow;
     27             import baidu.map.overlay.Label;
     28             import baidu.map.overlay.Marker;
     29             import baidu.map.overlay.geometry.Circle;
     30             import baidu.map.overlay.geometry.Polygon;
     31             import baidu.map.overlay.geometry.Polyline;
     32             import baidu.map.symbol.CircleSymbol;
     33             import baidu.map.symbol.PolygonSymbol;
     34             import baidu.map.symbol.PolylineSymbol;
     35             
     36             import mx.collections.ArrayCollection;
     37             import mx.core.UIComponent;
     38             import mx.events.FlexEvent;
     39             import mx.messaging.channels.StreamingAMFChannel;
     40             
     41             import spark.events.IndexChangeEvent;
     42             
     43             [Bindable]
     44             public var store_st:ArrayCollection = new ArrayCollection(
     45                 [   
     46                     {status:"玫瑰园"},
     47                     {status:"北京"}, 
     48                     {status:"上海"}, 
     49                     {status:"广州"},
     50                     {status:"深圳"},
     51                     {status:"佛山"},
     52                     {status:"南宁"},
     53                     {status:"南京"},
     54                     {status:"海口"},
     55                     {status:"哈尔滨"},
     56                     {status:"吉林"},
     57                     {status:"长春"},
     58                     {status:"天津"},
     59                     {status:"石家庄"},
     60                     {status:"郑州"},
     61                     {status:"西安"},
     62                     {status:"长沙"},
     63                     {status:"武汉"},
     64                     {status:"成都"},
     65                     {status:"香港"},
     66                     {status:"杭州"},
     67                 ]               
     68             );
     69             
     70             
     71             public function init():void{
     72                 config();
     73             }
     74             
     75             private function config():void{
     76                 const request:URLRequest = new URLRequest("area.xml");
     77                 const loader:URLLoader = new URLLoader(request);
     78                 loader.addEventListener(Event.COMPLETE, loader_completeHandler);
     79                 function loader_completeHandler(event:Event):void{
     80                     var configXML:XML = XML(loader.data);
     81                     for each (var i:XML in configXML.store_name){
     82                         if (store_cb.text==i.@id.toString()){
     83                             var x:Number=i.store_x.toString();
     84                             var y:Number=i.store_y.toString();                        
     85                         }
     86                     }
     87                     map(x,y);
     88                 }                
     89             }
     90             
     91             public function map(x:Number,y:Number):void{
     92                 // 创建一个大小为600*400的Map对象
     93                 var map:Map = new Map(new Size(Cs.width, Cs.height))
     94                 var uc:UIComponent = new UIComponent(); 
     95                 uc.addChild(map);
     96                 Cs.addChild(uc);                    //addElement(uc); 
     97                                                     //Gp.addElement(uc);  如果是Group容器就用这个
     98                 
     99                 // 初始化Map的中心点和显示级别
    100                 map.centerAndZoom(new LngLat(x,y), 12);
    101                 
    102                 // 添加底图
    103                 var layer:Layer = new RasterLayer("BaiduMap", map);
    104                 map.addLayer(layer);
    105                 
    106                 //添加定位标志
    107                 var marker:Marker = new Marker();
    108                 marker.position = new LngLat(x,y);
    109                 map.addOverlay(marker);
    110                 
    111                 // 添加Overview    缩略图控件        
    112                 var overview:Overview = new Overview(map);
    113                 map.addControl(overview);
    114                 
    115                 // 添加Navigator平移控件
    116                 var nav:Navigator = new Navigator(map);
    117                 map.addControl(nav);
    118                 
    119                 // 添加Scaler    缩放控件        
    120                 var scaler:Scaler = new Scaler(map);
    121                 map.addControl(scaler);
    122                 
    123                 // 添加Ruler        比例尺控件    
    124                 var ruler:Ruler = new Ruler(map);
    125                 map.addControl(ruler);
    126                 
    127                 //添加文本标签
    128                 var label:baidu.map.overlay.Label = new baidu.map.overlay.Label(store_cb.selectedLabel);
    129                 label.position = new LngLat(x,y+0.02);
    130                 label.contentStyle = new TextFormat("宋体", 14, 0xff0000, true);
    131                 map.addOverlay(label);
    132 
    133             }
    134             
    135             public function refresh():void{
    136                 store_cb.selectedIndex = 0;
    137                 map(113.061539,22.885359);                
    138             }
    139             
    140         ]]>
    141     </fx:Script>
    142     <s:layout>
    143         <s:VerticalLayout paddingLeft="5" paddingRight="5" paddingTop="5" paddingBottom="5"/>
    144     </s:layout>
    145     
    146     <s:VGroup width="100%" height="100%">
    147         <s:HGroup width="100%" horizontalAlign="right" verticalAlign="middle">
    148             <s:Spacer width="100%"/>
    149             <s:Label text="门店:"/>
    150             <mx:ComboBox id="store_cb" dataProvider="{store_st}" labelField="status" selectedIndex="0" editable="true"/>
    151             <s:Button id="sreach_btn" label="搜索" click="init()"/>
    152             <s:Button id="refresh_btn" label="刷新" click="refresh()"/>
    153         </s:HGroup>
    154         
    155         <mx:Canvas id="Cs" borderStyle="solid" width="100%" height="100%">            
    156         </mx:Canvas>
    157     </s:VGroup>
    158 </s:WindowedApplication>

    area.xml

     1 <?xml version="1.0" encoding="UTF-8"?>
     2 <Store>
     3     <store_name id="玫瑰园">
     4         <store_x>113.061539</store_x>
     5         <store_y>22.885359</store_y>        
     6     </store_name>
     7         <store_name id="北京">
     8         <store_x>116.395645</store_x>
     9         <store_y>39.929986</store_y>        
    10     </store_name>
    11         <store_name id="上海">
    12         <store_x>121.487899</store_x>
    13         <store_y>31.249162</store_y>        
    14     </store_name>
    15         <store_name id="广州">
    16         <store_x>113.30765</store_x>
    17         <store_y>23.120049</store_y>        
    18     </store_name>
    19 </Store>

    结果:

  • 相关阅读:
    VMware vSphere企业运维实战
    Unity 3D和2D手机游戏开发
    电商店铺装修推广教程
    uiiamgeview 设置圆角
    cgcolor regcolor tttatribute.
    谈待遇,
    不会自己 加的,也不会自己连线,
    代理,其他的类可以实现,而这个类不能实现,
    代理,
    TTTattribute 缺少 coretext
  • 原文地址:https://www.cnblogs.com/fangyu19900812/p/3403513.html
Copyright © 2011-2022 走看看