root/trunk/as2/lib/com/modestmaps/mapproviders/AbstractZoomifyMapProvider.as

Revision 448, 4.3 kB (checked in by migurski, 1 year ago)

Merged 1.0b branch onto trunk in preparation for 1.0 release

  • Property svn:keywords set to Id
Line 
1 import org.casaframework.event.DispatchableInterface;
2
3 import com.modestmaps.core.Coordinate;
4 import com.modestmaps.geo.LinearProjection;
5 import com.modestmaps.geo.Transformation;
6 import com.modestmaps.mapproviders.AbstractImageBasedMapProvider;
7 import com.modestmaps.mapproviders.IMapProvider;
8
9 /**
10  * @author migurski
11  * $Id$
12  */
13
14 class com.modestmaps.mapproviders.AbstractZoomifyMapProvider
15 extends AbstractImageBasedMapProvider
16 implements IMapProvider, DispatchableInterface
17 {
18     private var __baseDirectory:String;
19     private var __groups:/*Coordinate*/Array;
20
21     public function AbstractZoomifyMapProvider()
22     {
23         super();
24        
25        /*
26         * Example sub-class constructor:
27         *
28         *   public function MyZoomifyMapProvider()
29         *   {
30         *       super();
31         *
32         *       // defineImageProperties() *must* be called!
33         *       defineImageProperties('http://example.com/', 256, 256);
34         *
35         *       // Calculate the transformation and projectionbased on chosen markers. 
36         *       // See http://modestmaps.com/calculator.html
37         *       var t:Transformation = new Transformation(1, 0, 0, 0, 1, 0);
38         *       __projection = new LinearProjection(0, t);
39         *   }
40         *
41         */
42     }
43
44     public function toString():String
45     {
46         return "ABSTRACT_ZOOMIFY";
47     }
48
49    /**
50     * Zoomifyer EZ (download: http://www.zoomify.com/express.htm) cuts a base
51     * image into tiles, and creates a metadata file named ImageProperties.xml
52     * in the same directory. Instead of parsing that file, pass the relevant
53     * bits to this method. Base directory *must* have a trailing slash.
54     *
55     * Example:
56     *
57     *   ImageProperties.xml content:
58     *       <IMAGE_PROPERTIES WIDTH="11258" HEIGHT="7085" NUMTILES="1650" NUMIMAGES="1" VERSION="1.8" TILESIZE="256" />
59     *
60     *   URL of ImageProperties.xml:
61     *       http://example.com/ImageProperties.xml
62     *
63     *   Corresponding call to defineImageProperties():
64     *       defineImageProperties('http://example.com/', 11258, 7085);
65     *
66     * Tiles created by Zoomifyer EZ are placed in folders named "TileGroup{0..n}",
67     * in groups of 256, so we need to quickly iterate through the entire set of
68     * tile coordinates to determine where the group boundaries are. These are
69     * stored in the __groups array.
70     */
71         private function defineImageProperties(baseDirectory:String, width:Number, height:Number):Void
72         {
73         __baseDirectory = baseDirectory;
74
75         var zoom:Number = Math.ceil(Math.log(Math.max(width, height)) / Math.log(2));
76
77         __topLeftOutLimit = new Coordinate(0, 0, 0);
78         __bottomRightInLimit = (new Coordinate(height, width, zoom)).zoomTo(zoom - 8);
79
80         __groups = [];
81         var i:Number = 0;
82        
83        /*
84         * Iterate over all possible tiles in order: left to right, top to
85         * bottom, zoomed-out to zoomed-in. Note the first tile coordinate
86         * in each group of 256.
87         */
88         for(var c:Coordinate = __topLeftOutLimit.copy(); c.zoom <= __bottomRightInLimit.zoom; c.zoom += 1) {
89            
90             // edges of the image at current zoom level
91             var tlo:Coordinate = __topLeftOutLimit.zoomTo(c.zoom);
92             var bri:Coordinate = __bottomRightInLimit.zoomTo(c.zoom);
93        
94             // left-to-right, top-to-bottom, like reading a book
95             for(c.row = tlo.row; c.row <= bri.row; c.row += 1) {
96                 for(c.column = tlo.column; c.column <= bri.column; c.column += 1) {
97                
98                     // zoomify groups tiles into folders of 256 each
99                     if(i % 256 == 0)
100                         __groups.push(c.copy());
101                    
102                     i += 1;
103                 }
104             }   
105         }
106     }
107    
108     private function coordinateGroup(c:Coordinate):Number
109     {
110         for(var i:Number = 0; i < __groups.length; i += 1) {
111             if(i+1 == __groups.length)
112                 return i;
113        
114             var g:Coordinate = __groups[i+1].copy();
115
116             if(c.zoom < g.zoom || (c.zoom == g.zoom && (c.row < g.row || (c.row == g.row && c.column < g.column))))
117                 return i;
118         }
119     }
120
121     private function getTileUrl(coord:Coordinate):String
122     {
123         return __baseDirectory+'TileGroup'+coordinateGroup(coord)+'/'+(coord.zoom)+'-'+(coord.column)+'-'+(coord.row)+'.jpg';
124     }
125 }
Note: See TracBrowser for help on using the browser.