dgeoutils 2.4.4 → 2.4.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -27,7 +27,9 @@ export declare class DPoint {
27
27
  static parse(c: LatLng | number[] | DCoord): DPoint;
28
28
  static parseFromWKT(wkt: string): DPoint;
29
29
  static random(): DPoint;
30
+ static getTileFromQuadKey(quadKey: string): DPoint;
30
31
  getTileFromCoords(zoom?: number): DPoint;
32
+ getQuadKeyFromTile(zoom?: number): string;
31
33
  getCoordsFromTile(zoom?: number): DPoint;
32
34
  toCoords(): DCoord;
33
35
  findLine(p: DPoint): DLine;
@@ -75,6 +75,29 @@ var DPoint = (function () {
75
75
  DPoint.random = function () {
76
76
  return new DPoint(Math.random(), Math.random());
77
77
  };
78
+ DPoint.getTileFromQuadKey = function (quadKey) {
79
+ var p = new DPoint(0, 0, quadKey.length);
80
+ for (var i = p.z; i > 0; i--) {
81
+ var mask = 1 << (i - 1);
82
+ switch (quadKey[p.z - i]) {
83
+ case '0':
84
+ break;
85
+ case '1':
86
+ p.x |= mask;
87
+ break;
88
+ case '2':
89
+ p.y |= mask;
90
+ break;
91
+ case '3':
92
+ p.x |= mask;
93
+ p.y |= mask;
94
+ break;
95
+ default:
96
+ throw new Error('Invalid QuadKey digit sequence.');
97
+ }
98
+ }
99
+ return p;
100
+ };
78
101
  DPoint.prototype.getTileFromCoords = function (zoom) {
79
102
  if (zoom === void 0) { zoom = this.z; }
80
103
  (0, utils_1.checkFunction)('getTileFromCoords')
@@ -84,6 +107,23 @@ var DPoint = (function () {
84
107
  var y = Math.floor((1 - Math.log(Math.tan(this.y * exports.PI_TO_DEGREE) + 1 / Math.cos(this.y * exports.PI_TO_DEGREE)) / Math.PI) / 2 * (Math.pow(2, zoom)));
85
108
  return new DPoint(x, y, zoom);
86
109
  };
110
+ DPoint.prototype.getQuadKeyFromTile = function (zoom) {
111
+ if (zoom === void 0) { zoom = this.z; }
112
+ var quadKey = [];
113
+ for (var i = zoom; i > 0; i--) {
114
+ var digit = 0;
115
+ var mask = 1 << (i - 1);
116
+ if ((this.x & mask) !== 0) {
117
+ digit++;
118
+ }
119
+ if ((this.y & mask) !== 0) {
120
+ digit++;
121
+ digit++;
122
+ }
123
+ quadKey.push(digit);
124
+ }
125
+ return quadKey.join('');
126
+ };
87
127
  DPoint.prototype.getCoordsFromTile = function (zoom) {
88
128
  if (zoom === void 0) { zoom = this.z; }
89
129
  (0, utils_1.checkFunction)('getCoordsFromTile')
@@ -43,6 +43,29 @@ export class DPoint {
43
43
  static random() {
44
44
  return new DPoint(Math.random(), Math.random());
45
45
  }
46
+ static getTileFromQuadKey(quadKey) {
47
+ const p = new DPoint(0, 0, quadKey.length);
48
+ for (let i = p.z; i > 0; i--) {
49
+ const mask = 1 << (i - 1);
50
+ switch (quadKey[p.z - i]) {
51
+ case '0':
52
+ break;
53
+ case '1':
54
+ p.x |= mask;
55
+ break;
56
+ case '2':
57
+ p.y |= mask;
58
+ break;
59
+ case '3':
60
+ p.x |= mask;
61
+ p.y |= mask;
62
+ break;
63
+ default:
64
+ throw new Error('Invalid QuadKey digit sequence.');
65
+ }
66
+ }
67
+ return p;
68
+ }
46
69
  getTileFromCoords(zoom = this.z) {
47
70
  checkFunction('getTileFromCoords')
48
71
  .checkArgument('this')
@@ -51,6 +74,22 @@ export class DPoint {
51
74
  const y = Math.floor((1 - Math.log(Math.tan(this.y * PI_TO_DEGREE) + 1 / Math.cos(this.y * PI_TO_DEGREE)) / Math.PI) / 2 * (Math.pow(2, zoom)));
52
75
  return new DPoint(x, y, zoom);
53
76
  }
77
+ getQuadKeyFromTile(zoom = this.z) {
78
+ const quadKey = [];
79
+ for (let i = zoom; i > 0; i--) {
80
+ let digit = 0;
81
+ const mask = 1 << (i - 1);
82
+ if ((this.x & mask) !== 0) {
83
+ digit++;
84
+ }
85
+ if ((this.y & mask) !== 0) {
86
+ digit++;
87
+ digit++;
88
+ }
89
+ quadKey.push(digit);
90
+ }
91
+ return quadKey.join('');
92
+ }
54
93
  getCoordsFromTile(zoom = this.z) {
55
94
  checkFunction('getCoordsFromTile')
56
95
  .checkArgument('this')
@@ -72,6 +72,29 @@ var DPoint = (function () {
72
72
  DPoint.random = function () {
73
73
  return new DPoint(Math.random(), Math.random());
74
74
  };
75
+ DPoint.getTileFromQuadKey = function (quadKey) {
76
+ var p = new DPoint(0, 0, quadKey.length);
77
+ for (var i = p.z; i > 0; i--) {
78
+ var mask = 1 << (i - 1);
79
+ switch (quadKey[p.z - i]) {
80
+ case '0':
81
+ break;
82
+ case '1':
83
+ p.x |= mask;
84
+ break;
85
+ case '2':
86
+ p.y |= mask;
87
+ break;
88
+ case '3':
89
+ p.x |= mask;
90
+ p.y |= mask;
91
+ break;
92
+ default:
93
+ throw new Error('Invalid QuadKey digit sequence.');
94
+ }
95
+ }
96
+ return p;
97
+ };
75
98
  DPoint.prototype.getTileFromCoords = function (zoom) {
76
99
  if (zoom === void 0) { zoom = this.z; }
77
100
  checkFunction('getTileFromCoords')
@@ -81,6 +104,23 @@ var DPoint = (function () {
81
104
  var y = Math.floor((1 - Math.log(Math.tan(this.y * PI_TO_DEGREE) + 1 / Math.cos(this.y * PI_TO_DEGREE)) / Math.PI) / 2 * (Math.pow(2, zoom)));
82
105
  return new DPoint(x, y, zoom);
83
106
  };
107
+ DPoint.prototype.getQuadKeyFromTile = function (zoom) {
108
+ if (zoom === void 0) { zoom = this.z; }
109
+ var quadKey = [];
110
+ for (var i = zoom; i > 0; i--) {
111
+ var digit = 0;
112
+ var mask = 1 << (i - 1);
113
+ if ((this.x & mask) !== 0) {
114
+ digit++;
115
+ }
116
+ if ((this.y & mask) !== 0) {
117
+ digit++;
118
+ digit++;
119
+ }
120
+ quadKey.push(digit);
121
+ }
122
+ return quadKey.join('');
123
+ };
84
124
  DPoint.prototype.getCoordsFromTile = function (zoom) {
85
125
  if (zoom === void 0) { zoom = this.z; }
86
126
  checkFunction('getCoordsFromTile')