Add ol.TileCoord

This commit is contained in:
Tom Payne
2012-07-05 14:31:03 +02:00
committed by Tom Payne
parent b4e2e45166
commit 9f0738aa99
4 changed files with 50 additions and 3 deletions

View File

@@ -3,9 +3,6 @@ CLASS HIERARCHY
```
goog.math.Coordinate // Simple 2D point
goog.math.Coordinate3
|
+- TileCoord

View File

@@ -2,3 +2,4 @@ goog.provide('ol');
goog.require('ol.MVCObject');
goog.require('ol.MVCArray');
goog.require('ol.TileCoord');

32
src/ol/tilecoord.js Normal file
View File

@@ -0,0 +1,32 @@
goog.provide('ol.TileCoord');
goog.require('goog.math.Coordinate');
/**
* @constructor
* @extends {goog.math.Coordinate}
* @param {number} z Z.
* @param {number} x X.
* @param {number} y Y.
*/
ol.TileCoord = function(z, x, y) {
goog.base(this, x, y);
/**
* @type {number}
*/
this.z = z;
};
goog.inherits(ol.TileCoord, goog.math.Coordinate);
/**
* @return {number} Hash.
*/
ol.TileCoord.prototype.hash = function() {
return (this.x << this.z) + this.y;
};

17
src/ol/tilecoord_test.js Normal file
View File

@@ -0,0 +1,17 @@
goog.require('goog.testing.jsunit');
goog.require('ol.TileCoord');
function testConstructorOrderZXY() {
var tc1 = new ol.TileCoord(1, 2, 3);
assertEquals(1, tc1.z);
assertEquals(2, tc1.x);
assertEquals(3, tc1.y);
}
function testHashX() {
var tc1 = new ol.TileCoord(3, 2, 1);
var tc2 = new ol.TileCoord(3, 1, 1);
assertTrue(tc1.hash() != tc2.hash());
}