Use existing methods on XYZ layer.
This commit is contained in:
@@ -4,17 +4,16 @@
|
|||||||
* full text of the license. */
|
* full text of the license. */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @requires OpenLayers/Layer/Grid.js
|
* @requires OpenLayers/Layer/XYZ.js
|
||||||
* @requires OpenLayers/Tile/UTFGrid.js
|
* @requires OpenLayers/Tile/UTFGrid.js
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class: OpenLayers.Layer.UTFGrid
|
* Class: OpenLayers.Layer.UTFGrid
|
||||||
* This Layer reads from UTFGrid tiled data sources.
|
* This Layer reads from UTFGrid tiled data sources. Since UTFGrids are
|
||||||
* Since UTFGrids are essentially JSON-based ASCII art
|
* essentially JSON-based ASCII art with attached attributes, they are not
|
||||||
* with attached attributes, they are not visibly rendered.
|
* visibly rendered. In order to use them in the map, you must add a
|
||||||
* In order to use them in the map,
|
* <OpenLayers.Control.UTFGrid> ontrol as well.
|
||||||
* you must add a UTFGrid Control as well.
|
|
||||||
*
|
*
|
||||||
* Example:
|
* Example:
|
||||||
*
|
*
|
||||||
@@ -37,9 +36,9 @@
|
|||||||
*
|
*
|
||||||
*
|
*
|
||||||
* Inherits from:
|
* Inherits from:
|
||||||
* - <OpenLayers.Layer.Grid>
|
* - <OpenLayers.Layer.XYZ>
|
||||||
*/
|
*/
|
||||||
OpenLayers.Layer.UTFGrid = OpenLayers.Class(OpenLayers.Layer.Grid, {
|
OpenLayers.Layer.UTFGrid = OpenLayers.Class(OpenLayers.Layer.XYZ, {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* APIProperty: isBaseLayer
|
* APIProperty: isBaseLayer
|
||||||
@@ -54,36 +53,6 @@ OpenLayers.Layer.UTFGrid = OpenLayers.Class(OpenLayers.Layer.Grid, {
|
|||||||
*/
|
*/
|
||||||
projection: new OpenLayers.Projection("EPSG:900913"),
|
projection: new OpenLayers.Projection("EPSG:900913"),
|
||||||
|
|
||||||
/**
|
|
||||||
* APIProperty: zoomOffset
|
|
||||||
* {Number} If your cache has more zoom levels than you want to provide
|
|
||||||
* access to with this layer, supply a zoomOffset. This zoom offset
|
|
||||||
* is added to the current map zoom level to determine the level
|
|
||||||
* for a requested tile. For example, if you supply a zoomOffset
|
|
||||||
* of 3, when the map is at the zoom 0, tiles will be requested from
|
|
||||||
* level 3 of your cache. Default is 0 (assumes cache level and map
|
|
||||||
* zoom are equivalent). Using <zoomOffset> is an alternative to
|
|
||||||
* setting <serverResolutions> if you only want to expose a subset
|
|
||||||
* of the server resolutions.
|
|
||||||
*/
|
|
||||||
zoomOffset: 0,
|
|
||||||
|
|
||||||
/**
|
|
||||||
* APIProperty: serverResolutions
|
|
||||||
* {Array} A list of all resolutions available on the server. Only set this
|
|
||||||
* property if the map resolutions differ from the server. This
|
|
||||||
* property serves two purposes. (a) <serverResolutions> can include
|
|
||||||
* resolutions that the server supports and that you don't want to
|
|
||||||
* provide with this layer; you can also look at <zoomOffset>, which is
|
|
||||||
* an alternative to <serverResolutions> for that specific purpose.
|
|
||||||
* (b) The map can work with resolutions that aren't supported by
|
|
||||||
* the server, i.e. that aren't in <serverResolutions>. When the
|
|
||||||
* map is displayed in such a resolution data for the closest
|
|
||||||
* server-supported resolution is loaded and the layer div is
|
|
||||||
* stretched as necessary.
|
|
||||||
*/
|
|
||||||
serverResolutions: null,
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Property: useJSONP
|
* Property: useJSONP
|
||||||
* {Boolean}
|
* {Boolean}
|
||||||
@@ -160,28 +129,6 @@ OpenLayers.Layer.UTFGrid = OpenLayers.Class(OpenLayers.Layer.Grid, {
|
|||||||
obj = OpenLayers.Layer.Grid.prototype.clone.apply(this, [obj]);
|
obj = OpenLayers.Layer.Grid.prototype.clone.apply(this, [obj]);
|
||||||
|
|
||||||
return obj;
|
return obj;
|
||||||
},
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Method: getURL
|
|
||||||
*
|
|
||||||
* Parameters:
|
|
||||||
* bounds - {<OpenLayers.Bounds>}
|
|
||||||
*
|
|
||||||
* Returns:
|
|
||||||
* {String} A string with the layer's url and parameters and also the
|
|
||||||
* passed-in bounds and appropriate tile size specified as
|
|
||||||
* parameters
|
|
||||||
*/
|
|
||||||
getURL: function (bounds) {
|
|
||||||
var xyz = this.getXYZ(bounds);
|
|
||||||
var url = this.url;
|
|
||||||
if (OpenLayers.Util.isArray(url)) {
|
|
||||||
var s = '' + xyz.x + xyz.y + xyz.z;
|
|
||||||
url = this.selectUrl(s, url);
|
|
||||||
}
|
|
||||||
|
|
||||||
return OpenLayers.String.format(url, xyz);
|
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -295,53 +242,5 @@ OpenLayers.Layer.UTFGrid = OpenLayers.Class(OpenLayers.Layer.Grid, {
|
|||||||
return id;
|
return id;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Method: getXYZ
|
|
||||||
* Calculates x, y and z for the given bounds.
|
|
||||||
*
|
|
||||||
* Parameters:
|
|
||||||
* bounds - {<OpenLayers.Bounds>}
|
|
||||||
*
|
|
||||||
* Returns:
|
|
||||||
* {Object} - an object with x, y and z properties.
|
|
||||||
*/
|
|
||||||
getXYZ: function(bounds) {
|
|
||||||
var res = this.getServerResolution();
|
|
||||||
var x = Math.round((bounds.left - this.maxExtent.left) /
|
|
||||||
(res * this.tileSize.w));
|
|
||||||
var y = Math.round((this.maxExtent.top - bounds.top) /
|
|
||||||
(res * this.tileSize.h));
|
|
||||||
var resolutions = this.serverResolutions || this.resolutions;
|
|
||||||
var z = this.getServerZoom();
|
|
||||||
if (this.zoomOffset > 0) {
|
|
||||||
z += this.zoomOffset;
|
|
||||||
}
|
|
||||||
|
|
||||||
var limit = Math.pow(2, z);
|
|
||||||
if (this.wrapDateLine)
|
|
||||||
{
|
|
||||||
x = ((x % limit) + limit) % limit;
|
|
||||||
}
|
|
||||||
|
|
||||||
return {'x': x, 'y': y, 'z': z};
|
|
||||||
},
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Method: setMap
|
|
||||||
* When the layer is added to a map, then we can fetch our origin
|
|
||||||
* (if we don't have one.)
|
|
||||||
*
|
|
||||||
* Parameters:
|
|
||||||
* map - {<OpenLayers.Map>}
|
|
||||||
*/
|
|
||||||
setMap: function(map) {
|
|
||||||
OpenLayers.Layer.Grid.prototype.setMap.apply(this, arguments);
|
|
||||||
if (!this.tileOrigin) {
|
|
||||||
this.tileOrigin = new OpenLayers.LonLat(this.maxExtent.left,
|
|
||||||
this.maxExtent.top);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
|
|
||||||
CLASS_NAME: "OpenLayers.Layer.UTFGrid"
|
CLASS_NAME: "OpenLayers.Layer.UTFGrid"
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user