守望者--AIR技术交流

标题: 百度地图测试示例 [打印本页]

作者: 破晓    时间: 2015-1-12 17:57
标题: 百度地图测试示例
直接上代码:

  1. <?xml version="1.0" encoding="utf-8"?>
  2. <mx:Canvas 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:handler="com.sdhd.azri.handler.*"
  6.            xmlns:propertiesEdit="cn.propertiesEdit.*"
  7.            creationComplete="init()" xmlns:control="com.sdhd.azri.control.*" xmlns:layerManage="com.sdhd.azri.layerManage.*" xmlns:drawFeatureBar="com.sdhd.azri.drawFeatureBar.*"
  8.            >
  9.   <fx:Style>
  10.   </fx:Style>
  11.   <fx:Declarations>
  12.     <!-- 将非可视元素(例如服务、值对象)放在此处 -->
  13.     <handler:MapDragHandler id="drag" map="{map}"/>
  14.     <handler:MapMouseWheelHandler id="mouseWheel" map="{map}"  />
  15.   </fx:Declarations>
  16.   <fx:Script>
  17.     <![CDATA[
  18.       import com.sdhd.azri.control.Overview;
  19.       import com.sdhd.azri.control.Ruler;
  20.       import com.sdhd.azri.core.Map;
  21.       import com.sdhd.azri.data.model.LngLat;
  22.       import com.sdhd.azri.data.model.Size;
  23.       import com.sdhd.azri.events.FeatureEvent;
  24.       import com.sdhd.azri.events.MapEvent;
  25.       import com.sdhd.azri.graphic.core.RadioGroup;
  26.       import com.sdhd.azri.layer.FeatureLayer;
  27.       import com.sdhd.azri.layer.InfoWindowLayer;
  28.       import com.sdhd.azri.overlay.*;
  29.       import com.sdhd.azri.propertiesEdit.FeaturePropertiesEditBaseWindow;
  30.       
  31.       import mx.core.UIComponent;
  32.       
  33.       
  34.       
  35.       [Bindable]
  36.       private var map:Map;
  37.       private        var infoWindowLayer:InfoWindowLayer;
  38.       private function init():void{
  39.         map = new Map();
  40.         map.size = new Size(1000, 600);
  41.         map.center = new LngLat(116.404, 39.915);
  42.         map.zoom = 11;
  43.         map.setOldStatus();
  44.         var ui:UIComponent = new UIComponent();
  45.         contentBox.addChild(ui);
  46.         ui.addChild(map);
  47.         /**添加地图*/
  48.         map.addMapLayer();
  49.         
  50.         var ruler:Ruler = new Ruler(map);
  51.         map.addControl( ruler );
  52.         
  53.         var ovView:Overview = new Overview(map);
  54.         map.addControl( ovView );
  55.         
  56.         infoWindowLayer = new InfoWindowLayer(map);
  57.         infoWindowLayer.layerName = "infoWindowLayer";
  58.         map.addInfoWindowLayer(infoWindowLayer);
  59.         
  60.         var infoWindow:InfoWindow = new InfoWindow(infoWindowLayer,map.center);
  61.         infoWindowLayer.addChild( infoWindow );
  62.         drag.enable = true;
  63.         mouseWheel.enable = true;
  64.         map.addLngLatLayer();
  65.         
  66.         featureLayer = new FeatureLayer(map);
  67.         featureLayer.layerName = "featureLayer";
  68.         featureLayer.map = map;
  69.         map.addNormalLayer(featureLayer);
  70.         addEventListener(MapEvent.MAPLOADPROGRESS,doViewProgressHandler);
  71.         addEventListener(FeatureEvent.FEATUREEVENT_CLICK,doDelFeatureHandler,true);
  72.         map.addEventListener(MouseEvent.MOUSE_DOWN,doMapMouseDownHandler);
  73.         
  74.         
  75.         layerManage.map = map;
  76.       }
  77.       
  78.       private function doMapMouseDownHandler(e:MouseEvent):void{
  79.         
  80.       }
  81.       private var delFlag:Boolean = false;
  82.       private var editFlag:Boolean = false;
  83.       private var editWindow:FeaturePropertiesEditBaseWindow;
  84.       private function  doDelFeatureHandler(e:FeatureEvent):void{
  85.         if( delFlag ){
  86.           featureLayer.delChild( e.data );
  87.         }
  88.         if(editFlag ){
  89.           if(editWindow){
  90.             editWindow.shutDownWindow();
  91.             editWindow = null;
  92.           }
  93.           editWindow = new FeaturePropertiesEditBaseWindow();
  94.           editWindow.showWindow( e.data);
  95.         }
  96.       }
  97.       [Bindable]
  98.       private var featureLayer:FeatureLayer ;
  99.       private function doViewProgressHandler(e:MapEvent):void{
  100.         var textString:String = "";
  101.         textString =  "下载总数据 :";
  102.         var totalKB:Number = parseInt(e.data.totalBytes+"");
  103.         if( totalKB > 1000 ){
  104.           totalKB = totalKB/1000;
  105.           textString+= totalKB+"KB ";
  106.         }else{
  107.           textString+= totalKB+"B ";
  108.         }
  109.         textString+= "  已下载数据 ";
  110.         var loadKB:Number = parseInt(e.data.loadedBytes+"");
  111.         if( loadKB > 1000 ){
  112.           loadKB = loadKB/1000;
  113.           textString += loadKB +" KB ";
  114.         }else{
  115.           textString += loadKB +" B ";
  116.         }
  117.         textString += "  下载速度 ";
  118.         var speedKB:Number =  parseInt(e.data.speed+"");
  119.         if( speedKB > 1000 ){
  120.           speedKB =speedKB/1000;
  121.           textString+= speedKB+" KB/S";
  122.         }else{
  123.           textString+= speedKB+" B/S";
  124.         }
  125.         
  126.         viewProgress.text = textString;
  127.       }
  128.       
  129.       [Bindable]
  130.       private var group:RadioGroup = new RadioGroup();
  131.     ]]>
  132.   </fx:Script>
  133.     <s:Group width="100%" height="100%">
  134.       <mx:Canvas id="contentBox" width="100%" height="100%">
  135.       </mx:Canvas>
  136.       <s:Group width="100%" height="100%">
  137.         <s:Label id="viewProgress" top="30" right="30" />
  138.         <s:Label id="areaOrLeng" top="60" right="30" />
  139.         <layerManage:LayerManage id="layerManage"  
  140.                                    right="0" top="30"
  141.                                    width="380" height="200"
  142.                                     />
  143.        <control:Navigation_fx width="100" height="500" map="{map}" x="30" y="50" />
  144.       </s:Group>
  145.    
  146.       <drawFeatureBar:DrawFeatureBar x="50" y="80"
  147.                                      map="{map}" normalLayer="{featureLayer}" dragHandler="{drag}"
  148.                                      group="{group}"
  149.                                      />
  150.     </s:Group>
  151. </mx:Canvas>
复制代码







欢迎光临 守望者--AIR技术交流 (http://www.airmyth.com/)