PageRenderTime 78ms CodeModel.GetById 69ms app.highlight 7ms RepoModel.GetById 1ms app.codeStats 0ms

/src/com/google/maps/extras/planetary/MarsTileLayer.as

http://gmaps-utility-library-flash.googlecode.com/
ActionScript | 77 lines | 51 code | 9 blank | 17 comment | 7 complexity | 8afaa1c9ede2e72bbcf3010a71469b66 MD5 | raw file
 1/*
 2* Copyright 2008 Google Inc. 
 3* Licensed under the Apache License, Version 2.0:
 4*  http://www.apache.org/licenses/LICENSE-2.0
 5*/
 6package com.google.maps.extras.planetary {
 7
 8import com.google.maps.CopyrightCollection;
 9import com.google.maps.TileLayerBase;
10
11import flash.display.DisplayObject;
12import flash.display.Loader;
13import flash.events.*;
14import flash.geom.Point;
15import flash.net.URLRequest;
16
17/**
18 * @private
19 */
20public class MarsTileLayer extends TileLayerBase {
21
22  private var _baseUrl:String;
23  
24  /**
25   * Constructor for the class.
26   */
27  public function MarsTileLayer(baseUrl:String, copyrightCollection:CopyrightCollection, zoomLevels:Number) {
28    super(copyrightCollection, 0, zoomLevels);
29    this._baseUrl = baseUrl; 
30  }
31
32  /**
33   * Creates and loads a tile (x, y) at the given zoom level.
34   * @param tilePos  Tile coordinates.
35   * @param zoom  Tile zoom.
36   * @return  Display object representing the tile.
37   */
38  public override function loadTile(tilePos:Point, zoom:Number):DisplayObject {
39    var bound:Number = Math.pow(2, zoom);
40    var x:Number = tilePos.x;
41	var y:Number = tilePos.y;
42	var quads:Array = ['t'];
43
44	for (var z:Number = 0; z < zoom; z++) {
45	   bound = bound / 2;
46	   if (y < bound) {
47	       if (x < bound) {
48	           quads.push('q');
49      		} else {
50        	   quads.push('r');
51        	   x -= bound;
52      	     }
53    	} else {
54    	   if (x < bound) {
55        	   quads.push('t');
56        	   y -= bound;
57      	   } else {
58        	   quads.push('s');
59        	   x -= bound;
60        	   y -= bound;
61      	   }
62        }
63    }
64
65    var testLoader:Loader = new Loader();
66    var urlRequest:URLRequest = new URLRequest(
67       this._baseUrl + quads.join("") + ".jpg"); 
68    testLoader.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR, ioErrorHandler);
69    testLoader.load(urlRequest);	
70    return testLoader;
71  }
72
73  private function ioErrorHandler(event:IOErrorEvent):void {
74    trace("ioErrorHandler: " + event);
75  }
76}
77}