Skip to content

Commit

Permalink
exiting beta (#1)
Browse files Browse the repository at this point in the history
  • Loading branch information
shtyr-maxim authored Oct 23, 2023
1 parent 56a25ce commit fac09a1
Show file tree
Hide file tree
Showing 6 changed files with 71 additions and 35 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,4 @@ jobs:
- name: Publish
run: |
NPM_TOKEN=${{ secrets.NPM_TOKEN }} npm publish ./ --access public --tag beta
NPM_TOKEN=${{ secrets.NPM_TOKEN }} npm publish ./ --access public
71 changes: 48 additions & 23 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,42 +1,67 @@
# @mappable-world/mappable-cartesian-projection package

---

Mappable JS API package

[![npm version](https://badge.fury.io/js/@mappable-world%2Fmappable-cartesian-projection.svg)](https://badge.fury.io/js/@mappable-world%2Fmappable-cartesian-projection)
[![npm](https://img.shields.io/npm/dm/@mappable-world/mappable-cartesian-projection.svg)](https://www.npmjs.com/package/@mappable-world/mappable-cartesian-projection)
[![Build Status](https://github.com/mappable-world/mappable-cartesian-projection/workflows/Run%20tests/badge.svg)](https://github.com/mappable-world/mappable-cartesian-projection/actions/workflows/tests.yml)

## How use
This package will project your cartesian dimensions to Mappable JS API world representation (see scheme of work below). Then you can use it as `MMap` `location` property, in `MMapListener` handlers, etc.

![projection scheme](https://github.com/mappable-world/mappable-cartesian-projection/blob/main/projection_scheme.png?raw=true)

The package is located in the `dist` folder:
## Install

- `dist/types` TypeScript types
- `dist/esm` es6 modules for direct connection in your project
- `dist/index.js` Mappable JS Module
You can install this package via npm:

to use Mappable JS Module you need to add your module loading handler to JS API
```bash
npm install --save @mappable-world/mappable-cartesian-projection
```

## How use

To use Cartesian projection, just import it:

```js
mappable.import.loaders.unshift(async (pkg) => {
if (!pkg.includes('@mappable-world/mappable-cartesian-projection')) {
return;
}

if (location.href.includes('localhost')) {
await mappable.import.script(`/dist/index.js`);
} else {
// You can use another CDN
await mappable.import.script(`https://unpkg.com/${pkg}/dist/index.js`);
}
import {Cartesian} from '@mappable-world/mappable-cartesian-projection';

return window[pkg];
});
const projection = new Cartesian([
// these boundaries define the limits of the world map in the Cartesian coordinate system.
[-400, -600],
[400, 600],
]);

console.log(projection.toWorldCoordinates([-400, 600])) // {x: -1, y: 1}
console.log(projection.toWorldCoordinates([200, 0])) // {x: 0.5, y: 0}
console.log(projection.toWorldCoordinates([0, -75])) // {x: 0, y: -0.125}

console.log(projection.fromWorldCoordinates({x: -1, y: 1})) // [-400, 600]
console.log(projection.fromWorldCoordinates({x: 0.5, y: 0})) // [200, 0]
console.log(projection.fromWorldCoordinates({x: 0, y: -0.125})) // [0, -75]
```

### Usage without npm

You can use some CDN with `mappable.import` JS API module loading handler on your page:

```js
const pkg = await mappable.import('@mappable-world/mappable-cartesian-projection');
```

and in your final code just use `mappable.import`
**_NOTE:_**
By default `mappable.import` can load self modules, scripts or style.
To make the code above work, you should add a loader:

```js
const pkg = await mappable.import('@mappable-world/mappable-cartesian-projection')
// Add loader at the beginning of the loader queue
mappable.import.loaders.unshift(async (pkg) => {
// Process only this package
if (!pkg.includes('@mappable-world/mappable-cartesian-projection')) return;

// Load script directly. You can use another CDN
await mappable.import.script(`https://unpkg.com/${pkg}/dist/index.js`);

// Return result object
return window['@mappable-world/mappable-cartesian-projection'];
});
```
7 changes: 2 additions & 5 deletions example/common.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
mappable.import.loaders.unshift(async (pkg) => {
if (!pkg.includes('@mappable-world/mappable-cartesian-projection')) {
return;
}
if (!pkg.includes('@mappable-world/mappable-cartesian-projection')) return;

if (location.href.includes('localhost')) {
await mappable.import.script(`/dist/index.js`);
} else {
await mappable.import.script(`https://unpkg.com/${pkg}/dist/index.js`);
}

Object.assign(mappable, window[`${pkg}`]);
return window[`${pkg}`];
return window['@mappable-world/mappable-cartesian-projection'];
})

const TILE_SIZE = 256;
Expand Down
22 changes: 18 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@
"build:esm": "rm -rf ./dist/esm && tsc --project tsconfig.build.json --target es2018 --module es6 --outDir dist/esm",
"watch": "webpack --watch",
"start": "webpack serve",
"bump": "npm version prerelease --preid=beta --no-git-tag-version && npm run bump:git",
"bump": "npm version prerelease --no-git-tag-version && npm run bump:git",
"bump:git": "git add --all && git commit -m \"New version $npm_package_version\" && git tag $npm_package_version && git push --tags origin HEAD:main"
},
"devDependencies": {
"html-webpack-plugin": "^5.5.3",
"@mappable-world/mappable-cli": "^0.0.3",
"@mappable-world/mappable-cli": "^0.0.25",
"@mappable-world/mappable-types": "^0.0.4",
"@types/got": "9.6.12",
"@types/jest": "29.5.3",
Expand Down
Binary file added projection_scheme.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit fac09a1

Please sign in to comment.