Skip to content

Commit

Permalink
Merge mapbox-gl-export to this repository (#52)
Browse files Browse the repository at this point in the history
  • Loading branch information
JinIgarashi authored Mar 9, 2024
1 parent ad4aa86 commit a03a84b
Show file tree
Hide file tree
Showing 55 changed files with 3,240 additions and 1,950 deletions.
16 changes: 16 additions & 0 deletions .changeset/spotty-roses-marry.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
---
"@watergis/mapbox-gl-export": major
---

This release has breaking changes.

- merged [mapbox-gl-export](https://github.com/watergis/mapbox-gl-export) repository to `maplibre-gl-export`.
- added Spanish language and Japanese language from `maplibre-gl-export`
- added `Filename` option from `maplibre-gl-export` to allow to change default file name from `map`.
- added `AllowedSizes` option from `maplibre-gl-export` to allow to set available file sizes.
- the URL of CDN script and css were changed. Use the below URLs for CDN.

```html
<link href="https://www.unpkg.com/@watergis/mapbox-gl-export@latest/dist/mapbox-gl-export.css" rel="stylesheet" />
<script src="https://www.unpkg.com/@watergis/mapbox-gl-export@latest/dist/maplibre-gl-export.umd.js"></script>
```
5 changes: 5 additions & 0 deletions .changeset/tall-moose-rest.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@watergis/maplibre-gl-export": minor
---

feat: upgrade maplibre dependencies to v4
5 changes: 5 additions & 0 deletions .changeset/wise-mangos-fly.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@watergis/maplibre-gl-export": patch
---

feat: added `LETTER` page size (migrated it from `mapbox-gl-export`)
9 changes: 5 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,19 @@

[![Netlify Status](https://api.netlify.com/api/v1/badges/2ca781c3-2680-4c17-9219-4992c1f2a44e/deploy-status)](https://app.netlify.com/sites/maplibre-gl-export/deploys)

This monorepo manages the source code and demo page for `@watergis/maplibre-gl-export`.
This monorepo manages the source code and demo page for `@watergis/maplibre-gl-export` and `@watergis/mapbox-gl-export`.

## Repositories

| repository | description | changelog |
|---|---|---|
|[@watergis/maplibre-gl-export](./packages/maplibre-gl-export/)|The main repository to manage plugin source code|[CHANGELOG](./packages/maplibre-gl-export/CHANGELOG.md)
|[maplibre-gl-export.water-gis.com](./sites/maplibre-gl-export.water-gis.com/)|The repository manages demo website|-|
|[@watergis/maplibre-gl-export](./packages/maplibre-gl-export/)| To manage maplibre export plugin source code|[CHANGELOG](./packages/maplibre-gl-export/CHANGELOG.md)|
|[@watergis/mapbox-gl-export](./packages/mapbox-gl-export/)| To manage maplibre export plugin source code|[CHANGELOG](./packages/mapbox-gl-export/CHANGELOG.md)|
|[maplibre-gl-export.water-gis.com](./sites/maplibre-gl-export.water-gis.com/)| Demo website code for maplibre/mapbox export plugins |-|

## Usage of the plugin

See [README](./packages/maplibre-gl-export)
See README.md for [maplibre-gl-export](./packages/maplibre-gl-export) or [mapbox-gl-export](./packages/mapbox-gl-export)

## How to release

Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
},
"homepage": "https://github.com/watergis/maplibre-gl-export#readme",
"devDependencies": {
"@changesets/cli": "^2.26.0",
"lefthook": "^1.2.9"
"@changesets/cli": "^2.27.1",
"lefthook": "^1.6.5"
},
"packageManager": "pnpm@8.2.0",
"engines": {
Expand Down
1 change: 1 addition & 0 deletions packages/mapbox-gl-export/.env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
VITE_MAPBOX_ACCESSTOKEN=
14 changes: 14 additions & 0 deletions packages/mapbox-gl-export/.eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
.DS_Store
node_modules
/build
/.svelte-kit
/package
/dist
.env
.env.*
!.env.example

# Ignore files for PNPM, NPM and YARN
pnpm-lock.yaml
package-lock.json
yarn.lock
16 changes: 16 additions & 0 deletions packages/mapbox-gl-export/.eslintrc.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
module.exports = {
root: true,
parser: '@typescript-eslint/parser',
extends: ['eslint:recommended', 'plugin:@typescript-eslint/recommended', 'prettier'],
plugins: ['@typescript-eslint'],
ignorePatterns: ['*.cjs'],
parserOptions: {
sourceType: 'module',
ecmaVersion: 2020
},
env: {
browser: true,
es2017: true,
node: true
}
};
24 changes: 24 additions & 0 deletions packages/mapbox-gl-export/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
pnpm-debug.log*
lerna-debug.log*

node_modules
dist
dist-ssr
*.local

# Editor directories and files
.vscode/*
!.vscode/extensions.json
.idea
.DS_Store
*.suo
*.ntvs*
*.njsproj
*.sln
*.sw?
16 changes: 16 additions & 0 deletions packages/mapbox-gl-export/.prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
.DS_Store
node_modules
/build
/.svelte-kit
/package
/dist
.env
.env.*
!.env.example

# Ignore files for PNPM, NPM and YARN
pnpm-lock.yaml
package-lock.json
yarn.lock
*.md
.github/*
7 changes: 7 additions & 0 deletions packages/mapbox-gl-export/.prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"useTabs": true,
"singleQuote": true,
"trailingComma": "none",
"printWidth": 100,
"plugins": []
}
21 changes: 21 additions & 0 deletions packages/mapbox-gl-export/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2020 Jin IGARASHI

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.
173 changes: 173 additions & 0 deletions packages/mapbox-gl-export/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,173 @@
# mapbox-gl-export

![build](https://github.com/watergis/maplibre-gl-export/workflows/build/badge.svg)
![GitHub](https://img.shields.io/github/license/watergis/maplibre-gl-export)

This module adds control which can export PDF and images.

This module is using source code of [mpetroff/print-maps](https://github.com/mpetroff/print-maps). I just adopted this library to normal Mapbox GL Plugin. Thanks so much to develop this library!

## for Maplibre GL users

Please consider to use [maplibre-gl-export](https://github.com/watergis/maplibre-gl-export) plugin for Maplibre GL.

## Installation

```bash
npm i @watergis/mapbox-gl-export --save
```

## Use CDN

```html
<link href="https://www.unpkg.com/@watergis/mapbox-gl-export@latest/dist/mapbox-gl-export.css" rel="stylesheet" />
<script src='https://api.mapbox.com/mapbox-gl-js/v1.13.1/mapbox-gl.js'></script>
<script src="https://www.unpkg.com/@watergis/mapbox-gl-export@latest/dist/maplibre-gl-export.umd.js"></script>
<script>
map.addControl(new MapboxExportControl({
PageSize: Size.A3,
PageOrientation: PageOrientation.Portrait,
Format: Format.PNG,
DPI: DPI[96],
Crosshair: true,
PrintableArea: true,
}), 'top-right');
</script>
```

Furthermore, you may download specific version's scripts and css locally from [release](https://github.com/watergis/maplibre-gl-export/releases) page.

## Demo

Try [codesandbox](https://codesandbox.io/s/mapbox-gl-export-8x4lw?file=/src/index.ts).

See [demo](https://watergis.github.io/mapbox-gl-export/#12/-1.08551/35.87063).

![demo.gif](./demo.gif)

## Usage

```ts
import { MapboxExportControl, Size, PageOrientation, Format, DPI} from "@watergis/mapbox-gl-export";
import '@watergis/mapbox-gl-export/dist/mapbox-gl-export.css';
import mapboxgl from 'mapbox-gl';

const map = new mapboxgl.Map();
// create control with default options
map.addControl(new MapboxExportControl(), 'top-right');
// create control with specified options
map.addControl(new MapboxExportControl({
PageSize: Size.A3,
PageOrientation: PageOrientation.Portrait,
Format: Format.PNG,
DPI: DPI[96],
Crosshair: true,
PrintableArea: true
}), 'top-right');
```

### if you want to use a basemap from Mapbox

- for mapbox v1 user

```ts
mapboxgl.accessToken='your mapbox access token'
```

- for mapbox v2 user
There is an option of `accessToken` in `MapboxExportControl`. Please put your accessToken when you create a instance of plugin.

```ts
mapboxgl.accessToken='your mapbox access token'
const map = new mapboxgl.Map({
container: 'map',
style: 'mapbox://styles/mapbox/streets-v11',
});
map.addControl(new MapboxExportControl({
accessToken: 'your mapbox access token'
}), 'top-right');
```

### Options

You can specify default option as follows.

- PageSize
- You can select from `A2` to `A6` or `B2` to `B6`
- default page size is `A4`
- PageOrientation
- You can select `landscape` or `portrait`
- default is `landscape`
- Format
- You can select it from `jpg`, `png`, `svg` and `pdf`
- default is `PDF`
- DPI
- You can select it from `72`, `96`, `200`, `300` and `400`.
- default is `300`
- Crosshair
- Display crosshair on the map. it helps to adjust the map center before printing.
- accepts `true` and `false` value
- default is `false`
- PritableArea
- Display printable area on the map it helps to adjust pritable area before printing.
- accepts `true` and `false` value
- default is `false`
- Local
- default `en` for english
- `de` german
- `fr` french
- `fi` finnish
- `sv` swedish
- `es` spanish
- `vi` Vietnam
- `uk` Ukranian
- `zhHans` Chinese Simplified
- `zhHant` Chinese Traditional
- `ja` Japanese
- AllowedSizes
- list of allowed page sizes for export
- available values `'LETTER'`, `'A2'`, `'A3'`, `'A4'`, `'A5'`, `'A6'`, `'B2'`, `'B3'`, `'B4'`, `'B5'`, `'B6'`
- default: all sizes `['LETTER','A2','A3','A4','A5','A6','B2','B3','B4','B5','B6']`
- Filename
- file name template, file part
- default `map` for i.e `map.pdf`

## Attribution

When you use exported map, please includes attribution as follows.

If you can include HTML, use this code snippet that includes links to Mapbox & OpenStreetMap:

```html
© NARWASSCO, Ltd. © <a href='https://www.mapbox.com/about/maps/'>Mapbox</a> © <a href='https://www.openstreetmap.org/copyright'>OpenStreetMap</a> <strong><a href='https://www.mapbox.com/map-feedback/' target='_blank'>Improve this map</a></strong>Powered by the United Nations Vector Tile Toolkit
```

For print output or if you can’t include links, use this text-only attribution:

```
© NARWASSCO, Ltd. ©Mapbox ©OpenStreetMap contributors, Powered by the United Nations Vector Tile Toolkit
```

`© NARWASSCO, Ltd.` is default example of map data by `Narok Water and Sewerage Services Co., Ltd.`, Kenya. If you don't use current map, you don't need to use this attribution.

Also, default example is using base map by United Nation Vector Tile Toolkit. That is why `Powered by the United Nations Vector Tile Toolkit` is included in above.

## Development

```bash
pnpm lint
pnpm format
pnpm dev
```

open [http://localhost:5173](http://localhost:5173).

If there are any changes on source code, it will be reflected automatically.

## Build package

```
pnpm build
```

The modules will be generated under `dist` folder.
Binary file added packages/mapbox-gl-export/demo.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
38 changes: 38 additions & 0 deletions packages/mapbox-gl-export/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<!doctype html>
<html>
<head>
<meta charset="utf-8" />
<title>Example</title>
<meta name="viewport" content="initial-scale=1,maximum-scale=1,user-scalable=no" />
<link
rel="stylesheet"
href="https://cdnjs.cloudflare.com/ajax/libs/github-fork-ribbon-css/0.2.3/gh-fork-ribbon.min.css"
/>
<link href="https://api.mapbox.com/mapbox-gl-js/v3.2.0/mapbox-gl.css" rel="stylesheet" />
<style>
body {
margin: 0;
padding: 0;
}
#map {
position: absolute;
top: 0;
bottom: 0;
width: 100%;
z-index: 10;
}
</style>
</head>
<body>
<a
class="github-fork-ribbon left-top"
href="https://github.com/watergis/maplibre-gl-export"
data-ribbon="Fork me on GitHub"
title="Fork me on GitHub"
>Fork me on GitHub</a
>
<div id="map"></div>
<script src="https://api.mapbox.com/mapbox-gl-js/v3.2.0/mapbox-gl.js"></script>
<script type="module" src="./index.ts"></script>
</body>
</html>
Loading

0 comments on commit a03a84b

Please sign in to comment.