-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Simple README and prepare for publish
- Loading branch information
Showing
12 changed files
with
358 additions
and
107 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
The MIT License (MIT) | ||
Copyright © 2024 itanka9 <[email protected]> | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
# @2gis/mapgl-share | ||
|
||
A sharing control for the `@2gis/mapgl` library. | ||
|
||
## Table of Contents | ||
|
||
- [Installation](#installation) | ||
- [Usage](#usage) | ||
- [ShareControlOptions](#sharecontroloptions) | ||
- [Development](#development) | ||
- [Build](#build) | ||
- [Preview](#preview) | ||
- [License](#license) | ||
|
||
## Installation | ||
|
||
To install the dependencies, run: | ||
|
||
```bash | ||
npm install | ||
``` | ||
|
||
## Usage | ||
|
||
Here's an example of how to use the sharing control with @2gis/mapgl: | ||
|
||
```js | ||
import { Map } from '@2gis/mapgl'; | ||
import { ShareControl } from '@2gis/mapgl-share'; | ||
|
||
const map = new Map('map-container', { | ||
center: [55.751244, 37.618423], | ||
zoom: 10, | ||
}); | ||
|
||
const control = new ShareControl(map, { | ||
locale: navigator.language, | ||
urlMaker: (center, zoom, rotation, pitch) => { | ||
const viewport = `${center.toString()}/${zoom}/p/${pitch}/r/${rotation}`; | ||
|
||
return `${self.origin}${location.pathname}?m=${encodeURIComponent(viewport)}`; | ||
}, | ||
}) | ||
|
||
``` | ||
|
||
|
||
## Control Options | ||
|
||
| Option | Type | Description | | ||
|--------------|------------|-----------------------------------------------------------------------------------------------| | ||
| `position` | `ControlPosition` | Position of the control. | | ||
| `locale` | `string` | Locale to use for UI elements. | | ||
| `content` | `string` | Content of the control. Use this to customize the control button via providing custom HTML code. | | ||
| `cssPrefix` | `string` | Prefix for CSS classes. Use this to customize the control appearance with your own styles. | | ||
| `urlMaker` | `UrlMaker` | Function to construct sharing URL. | | ||
| `mapCodeMaker` | `MapCode` | Function to construct map code. | | ||
|
||
### ControlPosition | ||
|
||
Possible values for `ControlPosition`: | ||
|
||
- `topLeft` | ||
- `topCenter` | ||
- `topRight` | ||
- `centerLeft` | ||
- `centerRight` | ||
- `bottomLeft` | ||
- `bottomCenter` | ||
- `bottomRight` | ||
|
||
## Development | ||
|
||
Install deps | ||
|
||
```bash | ||
npm i | ||
``` | ||
|
||
To start the development server, run: | ||
|
||
``` | ||
npm run dev | ||
``` | ||
|
||
Build | ||
|
||
``` | ||
npm run build | ||
``` | ||
|
||
## License | ||
|
||
This project is licensed under the MIT License. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { resolve } from 'path' | ||
import { defineConfig } from 'vite' | ||
|
||
export default defineConfig({ | ||
build: { | ||
lib: { | ||
entry: resolve(__dirname, 'src/index.ts'), | ||
name: 'mapglShare' | ||
} | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
const locales: Record<string, Record<string, string>> = { | ||
buttonTitle: { | ||
en: 'Share', | ||
fr: 'Partager', | ||
de: 'Teilen', | ||
zh: '分享', | ||
hy: 'Կիսվել', | ||
ka: 'გაზიარება', | ||
ru: 'Поделиться', | ||
}, | ||
copyButton: { | ||
en: 'Copy', | ||
}, | ||
previewButton: { | ||
en: 'Preview', | ||
fr: 'Aperçu', | ||
de: 'Vorschau', | ||
zh: '预览', | ||
hy: 'Նախադիտել', | ||
ka: 'წინასწარი ნახვა', | ||
ru: 'Предпросмотр', | ||
}, | ||
popupTitle: { | ||
en: 'Share the map', | ||
fr: 'Partager la carte', | ||
de: 'Karte teilen', | ||
zh: '分享地图', | ||
hy: 'Կիսվել քարտեզով', | ||
ka: 'გაზიარება რუკის', | ||
ru: 'Поделиться картой', | ||
}, | ||
linkLabel: { | ||
en: 'Get a link', | ||
fr: 'Obtenir un lien', | ||
de: 'Link erhalten', | ||
zh: '获取链接', | ||
hy: 'Ստանալ հղում', | ||
ka: 'ბმულის მიღება', | ||
ru: 'Получить ссылку', | ||
}, | ||
embedLabel: { | ||
en: 'Embed into page', | ||
fr: 'Intégrer dans la page', | ||
de: 'In die Seite einbetten', | ||
zh: '嵌入页面', | ||
hy: 'Ներդնել էջում', | ||
ka: 'ჩასმა გვერდზე', | ||
ru: 'Встроить в страницу', | ||
}, | ||
}; | ||
|
||
export default locales; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export declare function copyTextToClipboard(text: string): void; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
import type * as MapGL from "@2gis/mapgl/types"; | ||
import { ControlOptions } from "@2gis/mapgl/types"; | ||
declare global { | ||
interface Window { | ||
mapgl: typeof MapGL; | ||
} | ||
} | ||
export type UrlMaker = (center: number[], zoom: number, rotation: number, pitch: number) => string; | ||
export type MapCodeMaker = (center: number[], zoom: number, rotation: number, pitch: number) => string; | ||
export interface ShareControlOptions extends Partial<ControlOptions> { | ||
/** | ||
* Locale to use for UI elements. | ||
*/ | ||
locale?: string; | ||
/** | ||
* Content of the control. Use this to customize the control button via providing custom HTML code. | ||
*/ | ||
content?: string; | ||
/** | ||
* Prefix for CSS classes. Use this to customize the control appearance with your own styles. | ||
*/ | ||
cssPrefix?: string; | ||
/** | ||
* Function to construct sharing URL. | ||
*/ | ||
urlMaker?: UrlMaker; | ||
/** | ||
* Function to construct map code. | ||
*/ | ||
mapCodeMaker?: MapCodeMaker; | ||
} | ||
/** | ||
* Control for sharing map view for MapGL JS API. | ||
* | ||
* @param map - MapGL instance. | ||
* @param options - Control options. | ||
* @returns ShareControl instance. | ||
* | ||
* @example | ||
* | ||
* ```js | ||
* import { ShareControl } from 'mapgl-share'; | ||
* import { load } from '@2gis/mapgl'; | ||
* | ||
* const map = new mapgl.Map('map', { | ||
* key: MAPGL_JS_API_KEY, | ||
* ... | ||
* }); | ||
* | ||
* const control = new ShareControl(map, { | ||
* locale: navigator.language, | ||
* urlMaker: (center, zoom, rotation, pitch) => { | ||
* const viewport = `${center.toString()}/${zoom}/p/${pitch}/r/${rotation}`; | ||
* | ||
* return `${self.origin}${location.pathname}?m=${encodeURIComponent(viewport)}`; | ||
* }, | ||
* ... | ||
* }) | ||
* ``` | ||
*/ | ||
export declare class ShareControl { | ||
private map; | ||
private options; | ||
private popup?; | ||
private locale?; | ||
constructor(map: MapGL.Map, options?: ShareControlOptions); | ||
private hidePopup; | ||
private updateFields; | ||
private showPopup; | ||
private togglePreview; | ||
private updatePreview; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
|
||
import locales from '../locales/index'; | ||
|
||
|
||
const defaultLocale = 'en'; | ||
|
||
export function l (s: string, locale = defaultLocale) { | ||
return s.replace(/%(\S+)%/g, (_, v) => locales[v]?.[locale] ?? locales[v]?.[defaultLocale] ?? v); | ||
} |
Oops, something went wrong.