Project

General

Profile

Download (6.13 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
 */
10

    
11
/**
12
 * Class: OpenLayers.Layer.KaMap
13
 * 
14
 * Inherits from:
15
 *  - <OpenLayers.Layer.Grid>
16
 */
17
OpenLayers.Layer.KaMap = OpenLayers.Class(OpenLayers.Layer.Grid, {
18

    
19
    /** 
20
     * APIProperty: isBaseLayer
21
     * {Boolean} KaMap Layer is always a base layer 
22
     */    
23
    isBaseLayer: true,
24

    
25
    /**
26
     * Constant: DEFAULT_PARAMS
27
     * {Object} parameters set by default. The default parameters set 
28
     * the format via the 'i' parameter to 'jpeg'.    
29
     */
30
    DEFAULT_PARAMS: {
31
        i: 'jpeg',
32
        map: ''
33
    },
34
        
35
    /**
36
     * Constructor: OpenLayers.Layer.KaMap
37
     * 
38
     * Parameters:
39
     * name - {String}
40
     * url - {String}
41
     * params - {Object} Parameters to be sent to the HTTP server in the
42
     *    query string for the tile. The format can be set via the 'i'
43
     *    parameter (defaults to jpg) , and the map should be set via 
44
     *    the 'map' parameter. It has been reported that ka-Map may behave
45
     *    inconsistently if your format parameter does not match the format
46
     *    parameter configured in your config.php. (See ticket #327 for more
47
     *    information.)
48
     * options - {Object} Additional options for the layer. Any of the 
49
     *     APIProperties listed on this layer, and any layer types it
50
     *     extends, can be overridden through the options parameter. 
51
     */
52
    initialize: function(name, url, params, options) {
53
        OpenLayers.Layer.Grid.prototype.initialize.apply(this, arguments);
54
        this.params = OpenLayers.Util.applyDefaults(
55
            this.params, this.DEFAULT_PARAMS
56
        );
57
    },
58

    
59
    /**
60
     * Method: getURL
61
     * 
62
     * Parameters:
63
     * bounds - {<OpenLayers.Bounds>} 
64
     * 
65
     * Returns:
66
     * {String} A string with the layer's url and parameters and also the 
67
     *          passed-in bounds and appropriate tile size specified as 
68
     *          parameters
69
     */
70
    getURL: function (bounds) {
71
        bounds = this.adjustBounds(bounds);
72
        var mapRes = this.map.getResolution();
73
        var scale = Math.round((this.map.getScale() * 10000)) / 10000;
74
        var pX = Math.round(bounds.left / mapRes);
75
        var pY = -Math.round(bounds.top / mapRes);
76
        return this.getFullRequestString(
77
                      { t: pY, 
78
                        l: pX,
79
                        s: scale
80
                      });
81
    },
82

    
83
    /** 
84
     * Method: calculateGridLayout
85
     * ka-Map uses the center point of the map as an origin for 
86
     * its tiles. Override calculateGridLayout to center tiles 
87
     * correctly for this case.
88
     *
89
     * Parameters:
90
     * bounds - {<OpenLayers.Bound>}
91
     * origin - {<OpenLayers.LonLat>}
92
     * resolution - {Number}
93
     *
94
     * Returns:
95
     * {Object} Object containing properties tilelon, tilelat, startcol,
96
     * startrow
97
     */
98
    calculateGridLayout: function(bounds, origin, resolution) {
99
        var tilelon = resolution*this.tileSize.w;
100
        var tilelat = resolution*this.tileSize.h;
101
        
102
        var offsetlon = bounds.left;
103
        var tilecol = Math.floor(offsetlon/tilelon) - this.buffer;
104
        
105
        var offsetlat = bounds.top;  
106
        var tilerow = Math.floor(offsetlat/tilelat) + this.buffer;
107
        
108
        return { 
109
          tilelon: tilelon, tilelat: tilelat,
110
          startcol: tilecol, startrow: tilerow
111
        };
112
    },    
113

    
114
    /**
115
     * Method: getTileBoundsForGridIndex
116
     *
117
     * Parameters:
118
     * row - {Number} The row of the grid
119
     * col - {Number} The column of the grid
120
     *
121
     * Returns:
122
     * {<OpenLayers.Bounds>} The bounds for the tile at (row, col)
123
     */
124
    getTileBoundsForGridIndex: function(row, col) {
125
        var origin = this.getTileOrigin();
126
        var tileLayout = this.gridLayout;
127
        var tilelon = tileLayout.tilelon;
128
        var tilelat = tileLayout.tilelat;
129
        var minX = (tileLayout.startcol + col) * tilelon;
130
        var minY = (tileLayout.startrow - row) * tilelat;
131
        return new OpenLayers.Bounds(
132
            minX, minY,
133
            minX + tilelon, minY + tilelat
134
        );
135
    },
136

    
137
    /**
138
     * APIMethod: clone
139
     * 
140
     * Parameters: 
141
     * obj - {Object}
142
     * 
143
     * Returns:
144
     * {<OpenLayers.Layer.Kamap>} An exact clone of this OpenLayers.Layer.KaMap
145
     */
146
    clone: function (obj) {
147
        
148
        if (obj == null) {
149
            obj = new OpenLayers.Layer.KaMap(this.name,
150
                                            this.url,
151
                                            this.params,
152
                                            this.getOptions());
153
        }
154

    
155
        //get all additions from superclasses
156
        obj = OpenLayers.Layer.Grid.prototype.clone.apply(this, [obj]);
157

    
158
        // copy/set any non-init, non-simple values here
159
        if (this.tileSize != null) {
160
            obj.tileSize = this.tileSize.clone();
161
        }
162
        
163
        // we do not want to copy reference to grid, so we make a new array
164
        obj.grid = [];
165

    
166
        return obj;
167
    },    
168
    
169
    /**
170
     * APIMethod: getTileBounds
171
     * Returns The tile bounds for a layer given a pixel location.
172
     *
173
     * Parameters:
174
     * viewPortPx - {<OpenLayers.Pixel>} The location in the viewport.
175
     *
176
     * Returns:
177
     * {<OpenLayers.Bounds>} Bounds of the tile at the given pixel location.
178
     */
179
    getTileBounds: function(viewPortPx) {
180
        var resolution = this.getResolution();
181
        var tileMapWidth = resolution * this.tileSize.w;
182
        var tileMapHeight = resolution * this.tileSize.h;
183
        var mapPoint = this.getLonLatFromViewPortPx(viewPortPx);
184
        var tileLeft = tileMapWidth * Math.floor(mapPoint.lon / tileMapWidth);
185
        var tileBottom = tileMapHeight * Math.floor(mapPoint.lat / tileMapHeight);
186
        return new OpenLayers.Bounds(tileLeft, tileBottom,
187
                                     tileLeft + tileMapWidth,
188
                                     tileBottom + tileMapHeight);
189
    },
190

    
191
    CLASS_NAME: "OpenLayers.Layer.KaMap"
192
});
(13-13/31)