@yandex/ymaps3-world-utils 0.0.0

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.
package/LICENSE ADDED
@@ -0,0 +1,13 @@
1
+ Copyright 2023 YANDEX LLC
2
+
3
+ Licensed under the Apache License, Version 2.0 (the "License");
4
+ you may not use this file except in compliance with the License.
5
+ You may obtain a copy of the License at
6
+
7
+ http://www.apache.org/licenses/LICENSE-2.0
8
+
9
+ Unless required by applicable law or agreed to in writing, software
10
+ distributed under the License is distributed on an "AS IS" BASIS,
11
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ See the License for the specific language governing permissions and
13
+ limitations under the License.
package/README.md ADDED
@@ -0,0 +1,81 @@
1
+ # @yandex/ymaps3-world-utils
2
+
3
+ Utility package for coordinate transformations in Yandex Maps 3.0.
4
+
5
+ ## Usage
6
+
7
+ ### ES Modules
8
+
9
+ ```bash
10
+ npm install @yandex/ymaps3-world-utils
11
+ ```
12
+
13
+ ```javascript
14
+ import { worldToPixels, pixelsToWorld } from '@yandex/ymaps3-world-utils';
15
+
16
+ // Convert world coordinates to pixels
17
+ const pixels = worldToPixels({ x: 0.5, y: 0.5 }, 10);
18
+ console.log(pixels); // { x: 196608, y: 65536 }
19
+
20
+ // Convert pixels back to world coordinates
21
+ const world = pixelsToWorld({ x: 196608, y: 65536 }, 10);
22
+ console.log(world); // { x: 0.5, y: 0.5 }
23
+ ```
24
+
25
+ ## API Reference
26
+
27
+ ### Coordinate Systems
28
+
29
+ The package works with two coordinate systems:
30
+
31
+ - **WorldCoordinates** - Normalized coordinates in the range `[-1, 1]`
32
+ - Center: `(0, 0)`
33
+ - Bottom-left corner: `(-1, -1)`
34
+ - Top-right corner: `(1, 1)`
35
+
36
+ - **PixelCoordinates** - Global pixel coordinates
37
+ - World size depends on zoom level: `2^(zoom + 8) × 2^(zoom + 8)` pixels
38
+ - At zoom 0: 256×256 pixels
39
+ - At zoom 10: 262,144×262,144 pixels
40
+ - Top-left corner: `(0, 0)`
41
+ - Bottom-right corner: `(2^(zoom + 8), 2^(zoom + 8))`
42
+
43
+ ### Functions
44
+
45
+ #### `worldToPixels(coordinates: WorldCoordinates, zoom: number): PixelCoordinates`
46
+
47
+ Converts world coordinates to pixel coordinates.
48
+
49
+ **Parameters:**
50
+ - `coordinates` - World coordinates object with `x` and `y` properties
51
+ - `zoom` - Zoom level (integer)
52
+
53
+ **Returns:** Pixel coordinates object with `x` and `y` properties
54
+
55
+ **Example:**
56
+ ```javascript
57
+ const pixels = worldToPixels({ x: 0, y: 0 }, 10);
58
+ // Returns: { x: 131072, y: 131072 } - center of the world at zoom 10
59
+ ```
60
+
61
+ ---
62
+
63
+ #### `pixelsToWorld(pixels: PixelCoordinates, zoom: number): WorldCoordinates`
64
+
65
+ Converts pixel coordinates to world coordinates.
66
+
67
+ **Parameters:**
68
+ - `pixels` - Pixel coordinates object with `x` and `y` properties
69
+ - `zoom` - Zoom level (integer)
70
+
71
+ **Returns:** World coordinates object with `x` and `y` properties
72
+
73
+ **Example:**
74
+ ```javascript
75
+ const world = pixelsToWorld({ x: 131072, y: 131072 }, 10);
76
+ // Returns: { x: 0, y: 0 } - center of the world
77
+ ```
78
+
79
+ ## License
80
+
81
+ Apache-2.0
@@ -0,0 +1,34 @@
1
+ interface Vec2 {
2
+ x: number;
3
+ y: number;
4
+ }
5
+
6
+ /**
7
+ * Coordinates in [-1 ... +1].
8
+ * Left bottom is (-1; -1).
9
+ * Right top is (+1; +1).
10
+ * Center is (0; 0).
11
+ */
12
+ interface WorldCoordinates extends Vec2 {
13
+ readonly type?: 'world';
14
+ z?: number;
15
+ }
16
+ /**
17
+ * Global pixel coordinates. World size depends on zoom.
18
+ * Left top is (0; 0).
19
+ * Right bottom is (2**(zoom + 8); 2**(zoom + 8)).
20
+ */
21
+ interface PixelCoordinates extends Vec2 {
22
+ readonly type?: 'pixel';
23
+ }
24
+
25
+ /**
26
+ * Converts world coordinates to pixel coordinates. Pixels are in (0, 0) (width, height) range.
27
+ */
28
+ declare function worldToPixels(coordinates: WorldCoordinates, zoom: number): PixelCoordinates;
29
+ /**
30
+ * Converts pixels in (0, 0) (width, height) to world coordinates.
31
+ */
32
+ declare function pixelsToWorld(pixels: PixelCoordinates, zoom: number): WorldCoordinates;
33
+
34
+ export { pixelsToWorld, worldToPixels };
@@ -0,0 +1 @@
1
+ var i=t(0,0);function t(e,r){return{x:e,y:r}}function n(e,r,o=t(0,0)){return o.x=e.x*r,o.y=e.y*r,o}var{cos:d,sin:s}=Math;var c=256;function x(e,r){let o=2**r/2*c;return n({x:e.x+1,y:1-e.y},o)}function l(e,r){let o=2**r/2*c;return{x:e.x/o-1,y:1-e.y/o}}export{l as pixelsToWorld,x as worldToPixels};
package/dist/index.js ADDED
@@ -0,0 +1 @@
1
+ !function(e,o){"object"==typeof exports&&"object"==typeof module?module.exports=o():"function"==typeof define&&define.amd?define([],o):"object"==typeof exports?exports["@yandex/ymaps3-world-utils"]=o():e["@yandex/ymaps3-world-utils"]=o()}(this,()=>(()=>{"use strict";var e={d:(o,t)=>{for(var n in t)e.o(t,n)&&!e.o(o,n)&&Object.defineProperty(o,n,{enumerable:!0,get:t[n]})},o:(e,o)=>Object.prototype.hasOwnProperty.call(e,o),r:e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})}},o={};function t(e,o){return{x:e,y:o}}e.r(o),e.d(o,{pixelsToWorld:()=>u,worldToPixels:()=>i}),t(0,0);const{cos:n,sin:r}=Math,y=256;function i(e,o){const n=2**o/2*y;return function(e,o,n=t(0,0)){return n.x=e.x*o,n.y=e.y*o,n}({x:e.x+1,y:1-e.y},n)}function u(e,o){const t=2**o/2*y;return{x:e.x/t-1,y:1-e.y/t}}return o})());
package/package.json ADDED
@@ -0,0 +1,49 @@
1
+ {
2
+ "name": "@yandex/ymaps3-world-utils",
3
+ "version": "0.0.0",
4
+ "type": "module",
5
+ "main": "./dist/esm/index.js",
6
+ "module": "./dist/esm/index.js",
7
+ "unpkg": "./dist/index.js",
8
+ "jsdelivr": "./dist/index.js",
9
+ "exports": {
10
+ ".": {
11
+ "types": "./dist/esm/index.d.ts",
12
+ "browser": "./dist/index.js",
13
+ "import": "./dist/esm/index.js",
14
+ "require": "./dist/esm/index.js"
15
+ }
16
+ },
17
+ "files": [
18
+ "dist",
19
+ "README.md",
20
+ "LICENSE"
21
+ ],
22
+ "scripts": {
23
+ "build": "tsup && webpack --config webpack.config.cjs"
24
+ },
25
+ "devDependencies": {
26
+ "tsup": "^8.0.0",
27
+ "typescript": "^5.0.0",
28
+ "webpack": "^5.88.0",
29
+ "webpack-cli": "^5.1.0",
30
+ "ts-loader": "^9.4.0"
31
+ },
32
+ "sideEffects": false,
33
+ "bugs": {
34
+ "url": "https://yandex.ru/maps-api/docs/js-api/feedback/troubleshooting.html"
35
+ },
36
+ "homepage": "https://yandex.ru/maps-api/docs/js-api/index.html",
37
+ "license": "Apache-2.0",
38
+ "description": "Yandex Maps 3 World Utilities - coordinate transformation functions",
39
+ "keywords": [
40
+ "ymaps3",
41
+ "api",
42
+ "map",
43
+ "ymaps",
44
+ "js api"
45
+ ],
46
+ "publishConfig": {
47
+ "registry": "https://registry.npmjs.org"
48
+ }
49
+ }