破晓 发表于 2015-1-12 17:57:40

百度地图测试示例

直接上代码:

<?xml version="1.0" encoding="utf-8"?>
<mx:Canvas xmlns:fx="http://ns.adobe.com/mxml/2009"
         xmlns:s="library://ns.adobe.com/flex/spark"
         xmlns:mx="library://ns.adobe.com/flex/mx"
         xmlns:handler="com.sdhd.azri.handler.*"
         xmlns:propertiesEdit="cn.propertiesEdit.*"
         creationComplete="init()" xmlns:control="com.sdhd.azri.control.*" xmlns:layerManage="com.sdhd.azri.layerManage.*" xmlns:drawFeatureBar="com.sdhd.azri.drawFeatureBar.*"
         >
<fx:Style>
</fx:Style>
<fx:Declarations>
    <!-- 将非可视元素(例如服务、值对象)放在此处 -->
    <handler:MapDragHandler id="drag" map="{map}"/>
    <handler:MapMouseWheelHandler id="mouseWheel" map="{map}"/>
</fx:Declarations>
<fx:Script>
    <![CDATA[
      import com.sdhd.azri.control.Overview;
      import com.sdhd.azri.control.Ruler;
      import com.sdhd.azri.core.Map;
      import com.sdhd.azri.data.model.LngLat;
      import com.sdhd.azri.data.model.Size;
      import com.sdhd.azri.events.FeatureEvent;
      import com.sdhd.azri.events.MapEvent;
      import com.sdhd.azri.graphic.core.RadioGroup;
      import com.sdhd.azri.layer.FeatureLayer;
      import com.sdhd.azri.layer.InfoWindowLayer;
      import com.sdhd.azri.overlay.*;
      import com.sdhd.azri.propertiesEdit.FeaturePropertiesEditBaseWindow;
      
      import mx.core.UIComponent;
      
      
      
      
      private var map:Map;
      private        var infoWindowLayer:InfoWindowLayer;
      private function init():void{
      map = new Map();
      map.size = new Size(1000, 600);
      map.center = new LngLat(116.404, 39.915);
      map.zoom = 11;
      map.setOldStatus();
      var ui:UIComponent = new UIComponent();
      contentBox.addChild(ui);
      ui.addChild(map);
      /**添加地图*/
      map.addMapLayer();
      
      var ruler:Ruler = new Ruler(map);
      map.addControl( ruler );
      
      var ovView:Overview = new Overview(map);
      map.addControl( ovView );
      
      infoWindowLayer = new InfoWindowLayer(map);
      infoWindowLayer.layerName = "infoWindowLayer";
      map.addInfoWindowLayer(infoWindowLayer);
      
      var infoWindow:InfoWindow = new InfoWindow(infoWindowLayer,map.center);
      infoWindowLayer.addChild( infoWindow );
      drag.enable = true;
      mouseWheel.enable = true;
      map.addLngLatLayer();
      
      featureLayer = new FeatureLayer(map);
      featureLayer.layerName = "featureLayer";
      featureLayer.map = map;
      map.addNormalLayer(featureLayer);
      addEventListener(MapEvent.MAPLOADPROGRESS,doViewProgressHandler);
      addEventListener(FeatureEvent.FEATUREEVENT_CLICK,doDelFeatureHandler,true);
      map.addEventListener(MouseEvent.MOUSE_DOWN,doMapMouseDownHandler);
      
      
      layerManage.map = map;
      }
      
      private function doMapMouseDownHandler(e:MouseEvent):void{
      
      }
      private var delFlag:Boolean = false;
      private var editFlag:Boolean = false;
      private var editWindow:FeaturePropertiesEditBaseWindow;
      private functiondoDelFeatureHandler(e:FeatureEvent):void{
      if( delFlag ){
          featureLayer.delChild( e.data );
      }
      if(editFlag ){
          if(editWindow){
            editWindow.shutDownWindow();
            editWindow = null;
          }
          editWindow = new FeaturePropertiesEditBaseWindow();
          editWindow.showWindow( e.data);
      }
      }
      
      private var featureLayer:FeatureLayer ;
      private function doViewProgressHandler(e:MapEvent):void{
      var textString:String = "";
      textString ="下载总数据 :";
      var totalKB:Number = parseInt(e.data.totalBytes+"");
      if( totalKB > 1000 ){
          totalKB = totalKB/1000;
          textString+= totalKB+"KB ";
      }else{
          textString+= totalKB+"B ";
      }
      textString+= "已下载数据 ";
      var loadKB:Number = parseInt(e.data.loadedBytes+"");
      if( loadKB > 1000 ){
          loadKB = loadKB/1000;
          textString += loadKB +" KB ";
      }else{
          textString += loadKB +" B ";
      }
      textString += "下载速度 ";
      var speedKB:Number =parseInt(e.data.speed+"");
      if( speedKB > 1000 ){
          speedKB =speedKB/1000;
          textString+= speedKB+" KB/S";
      }else{
          textString+= speedKB+" B/S";
      }
      
      viewProgress.text = textString;
      }
      
      
      private var group:RadioGroup = new RadioGroup();
    ]]>
</fx:Script>
    <s:Group width="100%" height="100%">
      <mx:Canvas id="contentBox" width="100%" height="100%">
      </mx:Canvas>
      <s:Group width="100%" height="100%">
      <s:Label id="viewProgress" top="30" right="30" />
      <s:Label id="areaOrLeng" top="60" right="30" />
      <layerManage:LayerManage id="layerManage"
                                 right="0" top="30"
                                 width="380" height="200"
                                    />
       <control:Navigation_fx width="100" height="500" map="{map}" x="30" y="50" />
      </s:Group>
   
      <drawFeatureBar:DrawFeatureBar x="50" y="80"
                                     map="{map}" normalLayer="{featureLayer}" dragHandler="{drag}"
                                     group="{group}"
                                     />
    </s:Group>
</mx:Canvas>


页: [1]
查看完整版本: 百度地图测试示例