@loaders.gl/wkt 4.3.2 → 4.4.0-alpha.2

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.
Files changed (111) hide show
  1. package/dist/dist.dev.js +1281 -1266
  2. package/dist/dist.min.js +2 -2
  3. package/dist/hex-wkb-loader.d.ts +6 -5
  4. package/dist/hex-wkb-loader.d.ts.map +1 -1
  5. package/dist/hex-wkb-loader.js +4 -4
  6. package/dist/index.cjs +51 -1622
  7. package/dist/index.cjs.map +4 -4
  8. package/dist/index.d.ts +0 -5
  9. package/dist/index.d.ts.map +1 -1
  10. package/dist/index.js +0 -5
  11. package/dist/lib/version.d.ts.map +1 -0
  12. package/dist/lib/{utils/version.js → version.js} +1 -1
  13. package/dist/twkb-loader.d.ts +3 -3
  14. package/dist/twkb-loader.d.ts.map +1 -1
  15. package/dist/twkb-loader.js +4 -4
  16. package/dist/twkb-writer.d.ts +2 -1
  17. package/dist/twkb-writer.d.ts.map +1 -1
  18. package/dist/twkb-writer.js +5 -4
  19. package/dist/wkb-loader.d.ts +13 -11
  20. package/dist/wkb-loader.d.ts.map +1 -1
  21. package/dist/wkb-loader.js +14 -6
  22. package/dist/wkb-writer.d.ts +3 -2
  23. package/dist/wkb-writer.d.ts.map +1 -1
  24. package/dist/wkb-writer.js +5 -4
  25. package/dist/wkt-crs-loader.d.ts +1 -1
  26. package/dist/wkt-crs-loader.d.ts.map +1 -1
  27. package/dist/wkt-crs-loader.js +2 -2
  28. package/dist/wkt-crs-writer.d.ts +1 -1
  29. package/dist/wkt-crs-writer.d.ts.map +1 -1
  30. package/dist/wkt-crs-writer.js +2 -2
  31. package/dist/wkt-loader.d.ts +2 -2
  32. package/dist/wkt-loader.d.ts.map +1 -1
  33. package/dist/wkt-loader.js +4 -4
  34. package/dist/wkt-worker.js +26 -13
  35. package/dist/wkt-writer.d.ts +6 -5
  36. package/dist/wkt-writer.d.ts.map +1 -1
  37. package/dist/wkt-writer.js +10 -7
  38. package/package.json +6 -6
  39. package/src/hex-wkb-loader.ts +8 -8
  40. package/src/index.ts +0 -10
  41. package/src/twkb-loader.ts +5 -5
  42. package/src/twkb-writer.ts +6 -5
  43. package/src/wkb-loader.ts +24 -12
  44. package/src/wkb-writer.ts +8 -7
  45. package/src/wkt-crs-loader.ts +3 -3
  46. package/src/wkt-crs-writer.ts +3 -5
  47. package/src/wkt-loader.ts +6 -5
  48. package/src/wkt-writer.ts +11 -8
  49. package/dist/lib/encode-twkb.d.ts +0 -6
  50. package/dist/lib/encode-twkb.d.ts.map +0 -1
  51. package/dist/lib/encode-twkb.js +0 -195
  52. package/dist/lib/encode-wkb.d.ts +0 -33
  53. package/dist/lib/encode-wkb.d.ts.map +0 -1
  54. package/dist/lib/encode-wkb.js +0 -286
  55. package/dist/lib/encode-wkt-crs.d.ts +0 -10
  56. package/dist/lib/encode-wkt-crs.d.ts.map +0 -1
  57. package/dist/lib/encode-wkt-crs.js +0 -35
  58. package/dist/lib/encode-wkt.d.ts +0 -8
  59. package/dist/lib/encode-wkt.d.ts.map +0 -1
  60. package/dist/lib/encode-wkt.js +0 -47
  61. package/dist/lib/parse-hex-wkb.d.ts +0 -1
  62. package/dist/lib/parse-hex-wkb.d.ts.map +0 -1
  63. package/dist/lib/parse-hex-wkb.js +0 -1
  64. package/dist/lib/parse-twkb.d.ts +0 -9
  65. package/dist/lib/parse-twkb.d.ts.map +0 -1
  66. package/dist/lib/parse-twkb.js +0 -253
  67. package/dist/lib/parse-wkb-header.d.ts +0 -39
  68. package/dist/lib/parse-wkb-header.d.ts.map +0 -1
  69. package/dist/lib/parse-wkb-header.js +0 -134
  70. package/dist/lib/parse-wkb.d.ts +0 -5
  71. package/dist/lib/parse-wkb.d.ts.map +0 -1
  72. package/dist/lib/parse-wkb.js +0 -241
  73. package/dist/lib/parse-wkt-crs.d.ts +0 -15
  74. package/dist/lib/parse-wkt-crs.d.ts.map +0 -1
  75. package/dist/lib/parse-wkt-crs.js +0 -120
  76. package/dist/lib/parse-wkt.d.ts +0 -30
  77. package/dist/lib/parse-wkt.d.ts.map +0 -1
  78. package/dist/lib/parse-wkt.js +0 -288
  79. package/dist/lib/utils/base64-encoder.d.ts +0 -5
  80. package/dist/lib/utils/base64-encoder.d.ts.map +0 -1
  81. package/dist/lib/utils/base64-encoder.js +0 -153
  82. package/dist/lib/utils/binary-reader.d.ts +0 -18
  83. package/dist/lib/utils/binary-reader.d.ts.map +0 -1
  84. package/dist/lib/utils/binary-reader.js +0 -69
  85. package/dist/lib/utils/binary-writer.d.ts +0 -28
  86. package/dist/lib/utils/binary-writer.d.ts.map +0 -1
  87. package/dist/lib/utils/binary-writer.js +0 -121
  88. package/dist/lib/utils/hex-encoder.d.ts +0 -15
  89. package/dist/lib/utils/hex-encoder.d.ts.map +0 -1
  90. package/dist/lib/utils/hex-encoder.js +0 -54
  91. package/dist/lib/utils/hex-transcoder.d.ts +0 -15
  92. package/dist/lib/utils/hex-transcoder.d.ts.map +0 -1
  93. package/dist/lib/utils/hex-transcoder.js +0 -50
  94. package/dist/lib/utils/version.d.ts.map +0 -1
  95. package/src/lib/encode-twkb.ts +0 -308
  96. package/src/lib/encode-wkb.ts +0 -390
  97. package/src/lib/encode-wkt-crs.ts +0 -41
  98. package/src/lib/encode-wkt.ts +0 -56
  99. package/src/lib/parse-hex-wkb.ts +0 -0
  100. package/src/lib/parse-twkb.ts +0 -365
  101. package/src/lib/parse-wkb-header.ts +0 -174
  102. package/src/lib/parse-wkb.ts +0 -343
  103. package/src/lib/parse-wkt-crs.ts +0 -149
  104. package/src/lib/parse-wkt.ts +0 -327
  105. package/src/lib/utils/base64-encoder.ts +0 -157
  106. package/src/lib/utils/binary-reader.ts +0 -76
  107. package/src/lib/utils/binary-writer.ts +0 -127
  108. package/src/lib/utils/hex-encoder.ts +0 -60
  109. package/src/lib/utils/hex-transcoder.ts +0 -54
  110. /package/dist/lib/{utils/version.d.ts → version.d.ts} +0 -0
  111. /package/src/lib/{utils/version.ts → version.ts} +0 -0
@@ -1,69 +0,0 @@
1
- // loaders.gl
2
- // SPDX-License-Identifier: MIT
3
- // Copyright (c) vis.gl contributors
4
- /** A DataView that tracks byte offset when reading. */
5
- export class BinaryReader {
6
- arrayBuffer;
7
- dataView;
8
- byteOffset;
9
- littleEndian;
10
- constructor(arrayBuffer, isBigEndian = false) {
11
- this.arrayBuffer = arrayBuffer;
12
- this.dataView = new DataView(arrayBuffer);
13
- this.byteOffset = 0;
14
- this.littleEndian = !isBigEndian;
15
- }
16
- readUInt8() {
17
- const value = this.dataView.getUint8(this.byteOffset);
18
- this.byteOffset += 1;
19
- return value;
20
- }
21
- readUInt16() {
22
- const value = this.dataView.getUint16(this.byteOffset, this.littleEndian);
23
- this.byteOffset += 2;
24
- return value;
25
- }
26
- readUInt32() {
27
- const value = this.dataView.getUint32(this.byteOffset, this.littleEndian);
28
- this.byteOffset += 4;
29
- return value;
30
- }
31
- readInt8() {
32
- const value = this.dataView.getInt8(this.byteOffset);
33
- this.byteOffset += 1;
34
- return value;
35
- }
36
- readInt16() {
37
- const value = this.dataView.getInt16(this.byteOffset, this.littleEndian);
38
- this.byteOffset += 2;
39
- return value;
40
- }
41
- readInt32() {
42
- const value = this.dataView.getInt32(this.byteOffset, this.littleEndian);
43
- this.byteOffset += 4;
44
- return value;
45
- }
46
- readFloat() {
47
- const value = this.dataView.getFloat32(this.byteOffset, this.littleEndian);
48
- this.byteOffset += 4;
49
- return value;
50
- }
51
- readDouble() {
52
- const value = this.dataView.getFloat64(this.byteOffset, this.littleEndian);
53
- this.byteOffset += 8;
54
- return value;
55
- }
56
- readVarInt() {
57
- let result = 0;
58
- let bytesRead = 0;
59
- let nextByte;
60
- do {
61
- // TODO - this needs to be accessed via data view?
62
- nextByte = this.dataView.getUint8(this.byteOffset + bytesRead);
63
- result += (nextByte & 0x7f) << (7 * bytesRead);
64
- bytesRead++;
65
- } while (nextByte >= 0x80);
66
- this.byteOffset += bytesRead;
67
- return result;
68
- }
69
- }
@@ -1,28 +0,0 @@
1
- export declare class BinaryWriter {
2
- arrayBuffer: ArrayBuffer;
3
- dataView: DataView;
4
- byteOffset: number;
5
- allowResize: boolean;
6
- constructor(size: number, allowResize?: boolean);
7
- writeUInt8(value: number): void;
8
- writeUInt16LE(value: number): void;
9
- writeUInt16BE(value: number): void;
10
- writeUInt32LE(value: number): void;
11
- writeUInt32BE(value: number): void;
12
- writeInt8(value: number): void;
13
- writeInt16LE(value: number): void;
14
- writeInt16BE(value: number): void;
15
- writeInt32LE(value: number): void;
16
- writeInt32BE(value: number): void;
17
- writeFloatLE(value: number): void;
18
- writeFloatBE(value: number): void;
19
- writeDoubleLE(value: number): void;
20
- writeDoubleBE(value: number): void;
21
- /** A varint uses a variable number of bytes */
22
- writeVarInt(value: number): number;
23
- /** Append another ArrayBuffer to this ArrayBuffer */
24
- writeBuffer(arrayBuffer: ArrayBuffer): void;
25
- /** Resizes this.arrayBuffer if not enough space */
26
- _ensureSize(size: number): void;
27
- }
28
- //# sourceMappingURL=binary-writer.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"binary-writer.d.ts","sourceRoot":"","sources":["../../../src/lib/utils/binary-writer.ts"],"names":[],"mappings":"AAQA,qBAAa,YAAY;IACvB,WAAW,EAAE,WAAW,CAAC;IACzB,QAAQ,EAAE,QAAQ,CAAC;IACnB,UAAU,EAAE,MAAM,CAAK;IACvB,WAAW,EAAE,OAAO,CAAS;gBAEjB,IAAI,EAAE,MAAM,EAAE,WAAW,CAAC,EAAE,OAAO;IAO/C,UAAU,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI;IAK/B,aAAa,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI;IAKlC,aAAa,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI;IAKlC,aAAa,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI;IAKlC,aAAa,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI;IAKlC,SAAS,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI;IAK9B,YAAY,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI;IAKjC,YAAY,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI;IAKjC,YAAY,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI;IAKjC,YAAY,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI;IAKjC,YAAY,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI;IAKjC,YAAY,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI;IAKjC,aAAa,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI;IAKlC,aAAa,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI;IAMlC,+CAA+C;IAC/C,WAAW,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM;IAYlC,qDAAqD;IACrD,WAAW,CAAC,WAAW,EAAE,WAAW,GAAG,IAAI;IAO3C,mDAAmD;IACnD,WAAW,CAAC,IAAI,EAAE,MAAM;CAYzB"}
@@ -1,121 +0,0 @@
1
- // loaders.gl
2
- // SPDX-License-Identifier: MIT
3
- // Copyright (c) vis.gl contributors
4
- // Forked from https://github.com/cschwarz/wkx under MIT license, Copyright (c) 2013 Christian Schwarz
5
- const LE = true;
6
- const BE = false;
7
- export class BinaryWriter {
8
- arrayBuffer;
9
- dataView;
10
- byteOffset = 0;
11
- allowResize = false;
12
- constructor(size, allowResize) {
13
- this.arrayBuffer = new ArrayBuffer(size);
14
- this.dataView = new DataView(this.arrayBuffer);
15
- this.byteOffset = 0;
16
- this.allowResize = allowResize || false;
17
- }
18
- writeUInt8(value) {
19
- this._ensureSize(1);
20
- this.dataView.setUint8(this.byteOffset, value);
21
- this.byteOffset += 1;
22
- }
23
- writeUInt16LE(value) {
24
- this._ensureSize(2);
25
- this.dataView.setUint16(this.byteOffset, value, LE);
26
- this.byteOffset += 2;
27
- }
28
- writeUInt16BE(value) {
29
- this._ensureSize(2);
30
- this.dataView.setUint16(this.byteOffset, value, BE);
31
- this.byteOffset += 2;
32
- }
33
- writeUInt32LE(value) {
34
- this._ensureSize(4);
35
- this.dataView.setUint32(this.byteOffset, value, LE);
36
- this.byteOffset += 4;
37
- }
38
- writeUInt32BE(value) {
39
- this._ensureSize(4);
40
- this.dataView.setUint32(this.byteOffset, value, BE);
41
- this.byteOffset += 4;
42
- }
43
- writeInt8(value) {
44
- this._ensureSize(1);
45
- this.dataView.setInt8(this.byteOffset, value);
46
- this.byteOffset += 1;
47
- }
48
- writeInt16LE(value) {
49
- this._ensureSize(2);
50
- this.dataView.setInt16(this.byteOffset, value, LE);
51
- this.byteOffset += 2;
52
- }
53
- writeInt16BE(value) {
54
- this._ensureSize(2);
55
- this.dataView.setInt16(this.byteOffset, value, BE);
56
- this.byteOffset += 2;
57
- }
58
- writeInt32LE(value) {
59
- this._ensureSize(4);
60
- this.dataView.setInt32(this.byteOffset, value, LE);
61
- this.byteOffset += 4;
62
- }
63
- writeInt32BE(value) {
64
- this._ensureSize(4);
65
- this.dataView.setInt32(this.byteOffset, value, BE);
66
- this.byteOffset += 4;
67
- }
68
- writeFloatLE(value) {
69
- this._ensureSize(4);
70
- this.dataView.setFloat32(this.byteOffset, value, LE);
71
- this.byteOffset += 4;
72
- }
73
- writeFloatBE(value) {
74
- this._ensureSize(4);
75
- this.dataView.setFloat32(this.byteOffset, value, BE);
76
- this.byteOffset += 4;
77
- }
78
- writeDoubleLE(value) {
79
- this._ensureSize(8);
80
- this.dataView.setFloat64(this.byteOffset, value, LE);
81
- this.byteOffset += 8;
82
- }
83
- writeDoubleBE(value) {
84
- this._ensureSize(8);
85
- this.dataView.setFloat64(this.byteOffset, value, BE);
86
- this.byteOffset += 8;
87
- }
88
- /** A varint uses a variable number of bytes */
89
- writeVarInt(value) {
90
- // TODO - ensure size?
91
- let length = 1;
92
- while ((value & 0xffffff80) !== 0) {
93
- this.writeUInt8((value & 0x7f) | 0x80);
94
- value >>>= 7;
95
- length++;
96
- }
97
- this.writeUInt8(value & 0x7f);
98
- return length;
99
- }
100
- /** Append another ArrayBuffer to this ArrayBuffer */
101
- writeBuffer(arrayBuffer) {
102
- this._ensureSize(arrayBuffer.byteLength);
103
- const tempArray = new Uint8Array(this.arrayBuffer);
104
- tempArray.set(new Uint8Array(arrayBuffer), this.byteOffset);
105
- this.byteOffset += arrayBuffer.byteLength;
106
- }
107
- /** Resizes this.arrayBuffer if not enough space */
108
- _ensureSize(size) {
109
- if (this.arrayBuffer.byteLength < this.byteOffset + size) {
110
- if (this.allowResize) {
111
- const newArrayBuffer = new ArrayBuffer(this.byteOffset + size);
112
- const tempArray = new Uint8Array(newArrayBuffer);
113
- tempArray.set(new Uint8Array(this.arrayBuffer));
114
- this.arrayBuffer = newArrayBuffer;
115
- }
116
- else {
117
- throw new Error('BinaryWriter overflow');
118
- }
119
- }
120
- }
121
- }
@@ -1,15 +0,0 @@
1
- /**
2
- * Simple helper to decode and encode "hex encoded" binary buffers
3
- * without first converting to string.
4
- */
5
- export declare class HexEncoder {
6
- /** Get length in bytes required to store encoded data */
7
- getEncodedLength(array: Uint8Array): number;
8
- /** Get length in bytes required to store decoded data */
9
- getDecodedLength(array: Uint8Array): number;
10
- /** Decode hexadecimal */
11
- decode(array: Uint8Array, result: Uint8Array): Uint8Array;
12
- /** Encode hexadecimal */
13
- encode(array: Uint8Array, result: Uint8Array): Uint8Array;
14
- }
15
- //# sourceMappingURL=hex-encoder.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"hex-encoder.d.ts","sourceRoot":"","sources":["../../../src/lib/utils/hex-encoder.ts"],"names":[],"mappings":"AAIA;;;GAGG;AACH,qBAAa,UAAU;IACrB,yDAAyD;IACzD,gBAAgB,CAAC,KAAK,EAAE,UAAU,GAAG,MAAM;IAI3C,yDAAyD;IACzD,gBAAgB,CAAC,KAAK,EAAE,UAAU,GAAG,MAAM;IAI3C,yBAAyB;IACzB,MAAM,CAAC,KAAK,EAAE,UAAU,EAAE,MAAM,EAAE,UAAU,GAAG,UAAU;IAazD,yBAAyB;IACzB,MAAM,CAAC,KAAK,EAAE,UAAU,EAAE,MAAM,EAAE,UAAU,GAAG,UAAU;CAQ1D"}
@@ -1,54 +0,0 @@
1
- // loaders.gl
2
- // SPDX-License-Identifier: MIT
3
- // Copyright (c) vis.gl contributors
4
- /**
5
- * Simple helper to decode and encode "hex encoded" binary buffers
6
- * without first converting to string.
7
- */
8
- export class HexEncoder {
9
- /** Get length in bytes required to store encoded data */
10
- getEncodedLength(array) {
11
- return array.byteLength * 2;
12
- }
13
- /** Get length in bytes required to store decoded data */
14
- getDecodedLength(array) {
15
- return Math.ceil(array.byteLength / 2);
16
- }
17
- /** Decode hexadecimal */
18
- decode(array, result) {
19
- for (let i = 0; i < array.byteLength / 2; ++i) {
20
- const halfByte1 = hexDecode(array[i]);
21
- const halfByte2 = hexDecode(array[i + 1]);
22
- result[i] = halfByte1 * 16 + halfByte2;
23
- }
24
- // Check if final half byte (is that legal?)
25
- // if (array.byteLength % 2) {
26
- // const halfByte1 = hexDecode(array[i]);
27
- // }
28
- return result;
29
- }
30
- /** Encode hexadecimal */
31
- encode(array, result) {
32
- for (let i = 0; i < array.byteLength; ++i) {
33
- const byte = array[i];
34
- result[i * 2] = hexEncode(byte & 0x0f);
35
- result[i * 2 + 1] = hexEncode(byte & 0xf0);
36
- }
37
- return result;
38
- }
39
- }
40
- function hexEncode(value) {
41
- if (value < 10) {
42
- return value + 48; // ASCII of 0
43
- }
44
- return value - 10 + 65; // ASCII of capital A
45
- }
46
- function hexDecode(value) {
47
- if (value >= 65) {
48
- return value - 65 + 10; // ASCII of A
49
- }
50
- if (value >= 97) {
51
- return value - 97 + 10; // ASCII of a
52
- }
53
- return value - 48; // ASCII of 0
54
- }
@@ -1,15 +0,0 @@
1
- /**
2
- * Encode a Uint8Array to a hex string
3
- *
4
- * @param array Bytes to encode to string
5
- * @return hex string
6
- */
7
- export declare function encodeHex(array: Uint8Array): string;
8
- /**
9
- * Decodes a hex string to a Uint8Array
10
- *
11
- * @param string hex string to decode to Uint8Array
12
- * @return Uint8Array
13
- */
14
- export declare function decodeHex(string: string): Uint8Array;
15
- //# sourceMappingURL=hex-transcoder.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"hex-transcoder.d.ts","sourceRoot":"","sources":["../../../src/lib/utils/hex-transcoder.ts"],"names":[],"mappings":"AAqBA;;;;;GAKG;AACH,wBAAgB,SAAS,CAAC,KAAK,EAAE,UAAU,GAAG,MAAM,CAQnD;AAED;;;;;GAKG;AACH,wBAAgB,SAAS,CAAC,MAAM,EAAE,MAAM,GAAG,UAAU,CAUpD"}
@@ -1,50 +0,0 @@
1
- // loaders.gl
2
- // SPDX-License-Identifier: MIT
3
- // Copyright (c) vis.gl contributors
4
- // Forked from https://github.com/jessetane/hex-transcoder under MIT license
5
- const alphabet = '0123456789abcdef';
6
- const encodeLookup = [];
7
- const decodeLookup = [];
8
- for (let i = 0; i < 256; i++) {
9
- encodeLookup[i] = alphabet[(i >> 4) & 0xf] + alphabet[i & 0xf];
10
- if (i < 16) {
11
- if (i < 10) {
12
- decodeLookup[0x30 + i] = i;
13
- }
14
- else {
15
- decodeLookup[0x61 - 10 + i] = i;
16
- }
17
- }
18
- }
19
- /**
20
- * Encode a Uint8Array to a hex string
21
- *
22
- * @param array Bytes to encode to string
23
- * @return hex string
24
- */
25
- export function encodeHex(array) {
26
- const length = array.length;
27
- let string = '';
28
- let i = 0;
29
- while (i < length) {
30
- string += encodeLookup[array[i++]];
31
- }
32
- return string;
33
- }
34
- /**
35
- * Decodes a hex string to a Uint8Array
36
- *
37
- * @param string hex string to decode to Uint8Array
38
- * @return Uint8Array
39
- */
40
- export function decodeHex(string) {
41
- const sizeof = string.length >> 1;
42
- const length = sizeof << 1;
43
- const array = new Uint8Array(sizeof);
44
- let n = 0;
45
- let i = 0;
46
- while (i < length) {
47
- array[n++] = (decodeLookup[string.charCodeAt(i++)] << 4) | decodeLookup[string.charCodeAt(i++)];
48
- }
49
- return array;
50
- }
@@ -1 +0,0 @@
1
- {"version":3,"file":"version.d.ts","sourceRoot":"","sources":["../../../src/lib/utils/version.ts"],"names":[],"mappings":"AAOA,eAAO,MAAM,OAAO,KAA8D,CAAC"}
@@ -1,308 +0,0 @@
1
- // loaders.gl
2
- // SPDX-License-Identifier: MIT
3
- // Copyright (c) vis.gl contributors
4
- // Forked from https://github.com/cschwarz/wkx under MIT license, Copyright (c) 2013 Christian Schwarz
5
-
6
- import type {
7
- Point,
8
- MultiPoint,
9
- LineString,
10
- MultiLineString,
11
- Polygon,
12
- MultiPolygon,
13
- GeometryCollection,
14
- Geometry
15
- } from '@loaders.gl/schema';
16
-
17
- import {BinaryWriter} from './utils/binary-writer';
18
- import {WKBGeometryType} from './parse-wkb-header';
19
-
20
- type TWKBPrecision = {
21
- xy: number;
22
- z: number;
23
- m: number;
24
- xyFactor: number;
25
- zFactor: number;
26
- mFactor: number;
27
- };
28
-
29
- type TWKBEncoderContext = TWKBPrecision & {
30
- hasZ?: boolean;
31
- hasM?: boolean;
32
- };
33
-
34
- export function encodeTWKB(
35
- geometry: Geometry,
36
- options?: {hasZ?: boolean; hasM?: boolean}
37
- ): ArrayBuffer {
38
- const writer = new BinaryWriter(0, true);
39
-
40
- const context: TWKBEncoderContext = {
41
- ...getTwkbPrecision(5, 0, 0),
42
- hasZ: options?.hasZ,
43
- hasM: options?.hasM
44
- };
45
-
46
- encodeGeometry(writer, geometry, context);
47
-
48
- // TODO - we need to slice it?
49
- return writer.arrayBuffer;
50
- }
51
-
52
- function encodeGeometry(writer: BinaryWriter, geometry: Geometry, context: TWKBEncoderContext) {
53
- switch (geometry.type) {
54
- case 'Point':
55
- return encodePoint(writer, context, geometry);
56
- case 'LineString':
57
- return encodeLineString(writer, context, geometry);
58
- case 'Polygon':
59
- return encodePolygon(writer, context, geometry);
60
- case 'MultiPoint':
61
- return encodeMultiPoint(writer, context, geometry);
62
- case 'MultiLineString':
63
- return encodeMultiLineString(writer, context, geometry);
64
- case 'MultiPolygon':
65
- return encodeMultiPolygon(writer, context, geometry);
66
- case 'GeometryCollection':
67
- return encodeGeometryCollection(writer, context, geometry);
68
- default:
69
- throw new Error('unsupported geometry type');
70
- }
71
- }
72
-
73
- function encodePoint(writer: BinaryWriter, context: TWKBEncoderContext, point: Point): void {
74
- const isEmpty =
75
- point.coordinates.length === 0 || point[0] === 'undefined' || point[1] === 'undefined';
76
-
77
- writeTwkbHeader(writer, context, WKBGeometryType.Point, isEmpty);
78
-
79
- if (!isEmpty) {
80
- const previousPoint = [0, 0, 0, 0];
81
- writeTwkbPoint(writer, context, point.coordinates, previousPoint);
82
- }
83
- }
84
-
85
- function encodeLineString(
86
- writer: BinaryWriter,
87
- context: TWKBEncoderContext,
88
- lineString: LineString
89
- ): ArrayBuffer {
90
- const points = lineString.coordinates;
91
- const isEmpty = points.length === 0;
92
-
93
- writeTwkbHeader(writer, context, WKBGeometryType.LineString, isEmpty);
94
-
95
- if (!isEmpty) {
96
- writer.writeVarInt(points.length);
97
- const previousPoint = [0, 0, 0, 0];
98
- for (const point of points) {
99
- writeTwkbPoint(writer, context, point, previousPoint);
100
- }
101
- }
102
-
103
- return writer.arrayBuffer;
104
- }
105
-
106
- function encodePolygon(
107
- writer: BinaryWriter,
108
- context: TWKBEncoderContext,
109
- polygon: Polygon
110
- ): ArrayBuffer {
111
- const polygonRings = polygon.coordinates;
112
-
113
- const isEmpty = polygonRings.length === 0;
114
-
115
- writeTwkbHeader(writer, context, WKBGeometryType.Polygon, isEmpty);
116
-
117
- if (!isEmpty) {
118
- writer.writeVarInt(polygonRings.length);
119
-
120
- const previousPoint = [0, 0, 0, 0];
121
- for (const ring of polygonRings) {
122
- writer.writeVarInt(ring.length);
123
- for (const point of ring) {
124
- writeTwkbPoint(writer, context, previousPoint, point);
125
- }
126
- }
127
- }
128
-
129
- return writer.arrayBuffer;
130
- }
131
-
132
- function encodeMultiPoint(
133
- writer: BinaryWriter,
134
- context: TWKBEncoderContext,
135
- multiPoint: MultiPoint
136
- ): void {
137
- const points = multiPoint.coordinates;
138
- const isEmpty = points.length === 0;
139
-
140
- writeTwkbHeader(writer, context, WKBGeometryType.MultiPoint, isEmpty);
141
-
142
- if (!isEmpty) {
143
- writer.writeVarInt(points.length);
144
-
145
- const previousPoint = [0, 0, 0, 0];
146
- for (let i = 0; i < points.length; i++) {
147
- writeTwkbPoint(writer, context, previousPoint, points[i]);
148
- }
149
- }
150
- }
151
-
152
- function encodeMultiLineString(
153
- writer: BinaryWriter,
154
- context: TWKBEncoderContext,
155
- multiLineStrings: MultiLineString
156
- ): ArrayBuffer {
157
- const lineStrings = multiLineStrings.coordinates;
158
- const isEmpty = lineStrings.length === 0;
159
-
160
- writeTwkbHeader(writer, context, WKBGeometryType.MultiLineString, isEmpty);
161
-
162
- if (!isEmpty) {
163
- writer.writeVarInt(lineStrings.length);
164
-
165
- const previousPoint = [0, 0, 0, 0];
166
- for (const lineString of lineStrings) {
167
- writer.writeVarInt(lineString.length);
168
-
169
- for (const point of lineString) {
170
- writeTwkbPoint(writer, context, previousPoint, point);
171
- }
172
- }
173
- }
174
-
175
- return writer.arrayBuffer;
176
- }
177
-
178
- function encodeMultiPolygon(
179
- writer: BinaryWriter,
180
- context: TWKBEncoderContext,
181
- multiPolygon: MultiPolygon
182
- ): void {
183
- const {coordinates} = multiPolygon;
184
- const isEmpty = coordinates.length === 0;
185
-
186
- writeTwkbHeader(writer, context, WKBGeometryType.MultiPolygon, isEmpty);
187
-
188
- if (!isEmpty) {
189
- const polygons = coordinates;
190
- writer.writeVarInt(polygons.length);
191
-
192
- const previousPoint = [0, 0, 0, 0];
193
-
194
- for (const polygonRings of polygons) {
195
- writer.writeVarInt(polygonRings.length);
196
- for (const ring of polygonRings) {
197
- writer.writeVarInt(ring.length);
198
- for (const point of ring) {
199
- writeTwkbPoint(writer, context, previousPoint, point);
200
- }
201
- }
202
- }
203
- }
204
- }
205
-
206
- function encodeGeometryCollection(
207
- writer: BinaryWriter,
208
- context: TWKBEncoderContext,
209
- geometryCollection: GeometryCollection
210
- ): void {
211
- const {geometries} = geometryCollection;
212
- const isEmpty = geometries.length === 0;
213
-
214
- writeTwkbHeader(writer, context, WKBGeometryType.GeometryCollection, isEmpty);
215
-
216
- if (geometries.length > 0) {
217
- writer.writeVarInt(geometries.length);
218
- for (const geometry of geometries) {
219
- encodeGeometry(writer, geometry, context);
220
- }
221
- }
222
- }
223
-
224
- /**
225
- *
226
- * @param writer
227
- * @param context
228
- * @param geometryType
229
- * @param isEmpty
230
- */
231
- function writeTwkbHeader(
232
- writer: BinaryWriter,
233
- context: TWKBEncoderContext,
234
- geometryType: WKBGeometryType,
235
- isEmpty: boolean
236
- ) {
237
- const type = (zigZagEncode(context.xy) << 4) + geometryType;
238
- let metadataHeader = context.hasZ || context.hasM ? 1 << 3 : 0;
239
- metadataHeader += isEmpty ? 1 << 4 : 0;
240
-
241
- writer.writeUInt8(type);
242
- writer.writeUInt8(metadataHeader);
243
-
244
- if (context.hasZ || context.hasM) {
245
- let extendedPrecision = 0;
246
- if (context.hasZ) {
247
- extendedPrecision |= 0x1;
248
- }
249
- if (context.hasM) {
250
- extendedPrecision |= 0x2;
251
- }
252
- writer.writeUInt8(extendedPrecision);
253
- }
254
- }
255
-
256
- /**
257
- * Write one point to array buffer. ZigZagEncoding the delta fdrom the previous point. Mutates previousPoint.
258
- * @param writer
259
- * @param context
260
- * @param previousPoint - Mutated by this function
261
- * @param point
262
- */
263
- function writeTwkbPoint(
264
- writer: BinaryWriter,
265
- context: TWKBEncoderContext,
266
- point: number[],
267
- previousPoint: number[]
268
- ): void {
269
- const x = point[0] * context.xyFactor;
270
- const y = point[1] * context.xyFactor;
271
- const z = point[2] * context.zFactor;
272
- const m = point[3] * context.mFactor;
273
-
274
- writer.writeVarInt(zigZagEncode(x - previousPoint[0]));
275
- writer.writeVarInt(zigZagEncode(y - previousPoint[1]));
276
- if (context.hasZ) {
277
- writer.writeVarInt(zigZagEncode(z - previousPoint[2]));
278
- }
279
- if (context.hasM) {
280
- writer.writeVarInt(zigZagEncode(m - previousPoint[3]));
281
- }
282
-
283
- previousPoint[0] = x;
284
- previousPoint[1] = y;
285
- previousPoint[2] = z;
286
- previousPoint[3] = m;
287
- }
288
-
289
- // HELPERS
290
-
291
- function zigZagEncode(value: number): number {
292
- return (value << 1) ^ (value >> 31);
293
- }
294
-
295
- function getTwkbPrecision(
296
- xyPrecision: number,
297
- zPrecision: number,
298
- mPrecision: number
299
- ): TWKBPrecision {
300
- return {
301
- xy: xyPrecision,
302
- z: zPrecision,
303
- m: mPrecision,
304
- xyFactor: Math.pow(10, xyPrecision),
305
- zFactor: Math.pow(10, zPrecision),
306
- mFactor: Math.pow(10, mPrecision)
307
- };
308
- }