Project

General

Profile

Download (4.76 KB) Statistics
| Branch: | Tag: | Revision:
1
/* Copyright (c) 2006-2013 by OpenLayers Contributors (see authors.txt for
2
 * full list of contributors). Published under the 2-clause BSD license.
3
 * See license.txt in the OpenLayers distribution or repository for the
4
 * full text of the license. */
5

    
6

    
7
/**
8
 * @requires OpenLayers/Layer/Grid.js
9
 * @requires OpenLayers/Layer/KaMap.js
10
 */
11

    
12
/**
13
 * Class: OpenLayers.Layer.KaMapCache
14
 * 
15
 * This class is designed to talk directly to a web-accessible ka-Map
16
 * cache generated by the precache2.php script.
17
 * 
18
 * To create a a new KaMapCache layer, you must indicate also the "i" parameter
19
 * (that will be used to calculate the file extension), and another special
20
 * parameter, object names "metaTileSize", with "h" (height) and "w" (width)
21
 * properties.
22
 * 
23
 *     // Create a new kaMapCache layer. 
24
 *     var kamap_base = new OpenLayers.Layer.KaMapCache(
25
 *         "Satellite",
26
 *         "http://www.example.org/web/acessible/cache",
27
 *         {g: "satellite", map: "world", i: 'png24', metaTileSize: {w: 5, h: 5} }
28
 *       );
29
 *    
30
 *     // Create an kaMapCache overlay layer (using "isBaseLayer: false"). 
31
 *     // Forces the output to be a "gif", using the "i" parameter.
32
 *     var kamap_overlay = new OpenLayers.Layer.KaMapCache(
33
 *         "Streets",
34
 *         "http://www.example.org/web/acessible/cache",
35
 *         {g: "streets", map: "world", i: "gif", metaTileSize: {w: 5, h: 5} },
36
 *         {isBaseLayer: false}
37
 *       );
38
 *
39
 * The cache URLs must look like: 
40
 *   var/cache/World/50000/Group_Name/def/t-440320/l20480
41
 * 
42
 * This means that the cache generated via tile.php will *not* work with
43
 *     this class, and should instead use the KaMap layer.
44
 *
45
 * More information is available in Ticket #1518.
46
 * 
47
 * Inherits from:
48
 *  - <OpenLayers.Layer.KaMap>
49
 *  - <OpenLayers.Layer.Grid>
50
 */
51
OpenLayers.Layer.KaMapCache = OpenLayers.Class(OpenLayers.Layer.KaMap, {
52

    
53
    /**
54
     * Constant: IMAGE_EXTENSIONS
55
     * {Object} Simple hash map to convert format to extension.
56
     */
57
    IMAGE_EXTENSIONS: {
58
        'jpeg': 'jpg',
59
        'gif' : 'gif',
60
        'png' : 'png',
61
        'png8' : 'png',
62
        'png24' : 'png',
63
        'dithered' : 'png'
64
    },
65
    
66
    /**
67
     * Constant: DEFAULT_FORMAT
68
     * {Object} Simple hash map to convert format to extension.
69
     */
70
    DEFAULT_FORMAT: 'jpeg',
71
    
72
    /**
73
     * Constructor: OpenLayers.Layer.KaMapCache
74
     * 
75
     * Parameters:
76
     * name - {String}
77
     * url - {String}
78
     * params - {Object} Parameters to be sent to the HTTP server in the
79
     *    query string for the tile. The format can be set via the 'i'
80
     *    parameter (defaults to jpg) , and the map should be set via 
81
     *    the 'map' parameter. It has been reported that ka-Map may behave
82
     *    inconsistently if your format parameter does not match the format
83
     *    parameter configured in your config.php. (See ticket #327 for more
84
     *    information.)
85
     * options - {Object} Additional options for the layer. Any of the 
86
     *     APIProperties listed on this layer, and any layer types it
87
     *     extends, can be overridden through the options parameter. 
88
     */
89
    initialize: function(name, url, params, options) {
90
        OpenLayers.Layer.KaMap.prototype.initialize.apply(this, arguments);
91
        this.extension = this.IMAGE_EXTENSIONS[this.params.i.toLowerCase() || this.DEFAULT_FORMAT];
92
    },
93

    
94
    /**
95
     * Method: getURL
96
     * 
97
     * Parameters:
98
     * bounds - {<OpenLayers.Bounds>} 
99
     * 
100
     * Returns:
101
     * {String} A string with the layer's url and parameters and also the 
102
     *          passed-in bounds and appropriate tile size specified as 
103
     *          parameters
104
     */
105
    getURL: function (bounds) {
106
        bounds = this.adjustBounds(bounds);
107
        var mapRes = this.map.getResolution();
108
        var scale = Math.round((this.map.getScale() * 10000)) / 10000;
109
        var pX = Math.round(bounds.left / mapRes);
110
        var pY = -Math.round(bounds.top / mapRes);
111

    
112
        var metaX = Math.floor(pX / this.tileSize.w / this.params.metaTileSize.w) * this.tileSize.w * this.params.metaTileSize.w;
113
        var metaY = Math.floor(pY / this.tileSize.h / this.params.metaTileSize.h) * this.tileSize.h * this.params.metaTileSize.h;
114
    
115
        var components = [
116
            "/",
117
            this.params.map,
118
            "/",
119
            scale,
120
            "/",
121
            this.params.g.replace(/\s/g, '_'),
122
            "/def/t", 
123
            metaY,
124
            "/l",
125
            metaX,
126
            "/t",
127
            pY,
128
            "l",
129
            pX,
130
            ".",
131
            this.extension
132
          ];
133

    
134
        var url = this.url;
135

    
136
        if (OpenLayers.Util.isArray(url)) {
137
            url = this.selectUrl(components.join(''), url);
138
        }
139
        return url + components.join("");
140
    },
141

    
142
    CLASS_NAME: "OpenLayers.Layer.KaMapCache"
143
});
(14-14/31)