PageRenderTime 21ms CodeModel.GetById 1ms app.highlight 13ms RepoModel.GetById 2ms app.codeStats 0ms

/src/com/google/maps/extras/arcgislink/ArcGISMapType.as

http://gmaps-utility-library-flash.googlecode.com/
ActionScript | 87 lines | 64 code | 10 blank | 13 comment | 13 complexity | d96cec32aea49f09d87afe9c8bd9bc76 MD5 | raw file
 1/*
 2 * ArcGIS for Google Maps Flash API
 3 *
 4 * License http://www.apache.org/licenses/LICENSE-2.0
 5 */
 6 /**
 7 * @author nianwei at gmail dot com
 8 */ 
 9
10package com.google.maps.extras.arcgislink {
11  import com.google.maps.MapType;
12  import com.google.maps.MapTypeOptions;
13  import com.google.maps.interfaces.*;
14  
15  import flash.events.*;
16 
17
18/**
19 * A customized map type that can be used as background map.
20 */ 
21  public class ArcGISMapType extends MapType {// MapType already implements IEventDispatcher {
22    
23    private var projection_:ArcGISTileConfig;
24    
25    public function ArcGISMapType(tileLayers:*, opt_typeOpts:ArcGISMapTypeOptions=null) {
26      var me:ArcGISMapType = this;
27      opt_typeOpts=opt_typeOpts || new ArcGISMapTypeOptions();
28      var layers:Array;
29      var i:int;
30      if (tileLayers is String){
31        layers = [new ArcGISTileLayer(tileLayers)];
32      } else if (tileLayers is Array){
33        if (tileLayers[0] is String){
34          layers = [];
35          for (i = 0; i < tileLayers.length; i++){
36            layers.push(new ArcGISTileLayer(tileLayers[i]));
37          }
38        } else {
39          layers = tileLayers;
40        }
41         
42      }
43      var layer0:ArcGISTileLayer=layers[0] as ArcGISTileLayer;
44      var prj:ArcGISTileConfig=opt_typeOpts.projection||layer0.getProjection();
45     // var gOpts:MapTypeOptions=new MapTypeOptions({tileSize: prj.getTileSize()});
46     // ArcGISUtil.augmentObject(opt_typeOpts, gOpts);
47      opt_typeOpts.tileSize =prj.getTileSize(); 
48      super(layers, prj, opt_typeOpts.name || layer0.getMapService().name, opt_typeOpts);
49      
50      function checkLoaded():void{
51        if (layersLoaded == layers.length){
52          me.init_(layers, opt_typeOpts);
53          me.dispatchEvent(new ServiceEvent(ServiceEvent.LOAD));
54        }
55      }
56      var layersLoaded:int;
57      for (i = 0 ; i < layers.length; i++){
58        var layer:ArcGISTileLayer = layers[i];
59        if (opt_typeOpts.projection){
60          layer.projection_ = opt_typeOpts.projection;
61        }
62        var svc:MapService = layer.getMapService();
63        if (svc.hasLoaded()){
64          layersLoaded++;
65        }else {
66          svc.addEventListener(ServiceEvent.LOAD, function(evt:Event):void{
67            layersLoaded++;
68            checkLoaded();
69          });
70        }
71      }
72      checkLoaded();
73    }
74    private function init_(tileLayers:Array, opt_typeOpts:ArcGISMapTypeOptions):void{
75      var layer:ArcGISTileLayer = tileLayers[0] as ArcGISTileLayer;
76      this.projection_ = layer.getProjection();
77    }
78    
79    public override function getTileSize():Number {
80      return this.projection_?this.projection_.getTileSize():super.getTileSize();
81    }
82    public override function getProjection():IProjection {
83      return this.projection_?this.projection_:super.getProjection();
84    }
85    
86  }
87}