shgis-mapbox-gl-export

mapbox export

Usage no npm install needed!

<script type="module">
  import shgisMapboxGlExport from 'https://cdn.skypack.dev/shgis-mapbox-gl-export';
</script>

README

mapbox-gl-export

GitHub

This module adds control which can export PDF and images.

This module is using source code of 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 plugin for Maplibre GL.

Installation:

  • for mapbox-gl-js v1 open source users
npm i @watergis/mapbox-gl-export --save
  • for mapbox-gl-js v2 users
npm i git+https://github.com/watergis/mapbox-gl-export.git#mbgljs-v2

Note. mbgljs-v2 branch is not being maintained actively although it has been upgraded to v2 library. This repository does not support anything for mapbox-gl-js v2.

Demo:

See demo.

demo.gif

Usage:

import { MapboxExportControl, Size, PageOrientation, Format, DPI} from "@watergis/mapbox-gl-export";
import '@watergis/mapbox-gl-export/css/styles.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
}), '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

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:

© 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:

npm run lint # check styling of source code
npm run lint:fix # fix styling by eslint
npm run dev

open http://localhost:8080.

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

Build package:

npm run build

The modules will be generated under dist folder.

Deploy to Github pages

npm run deploy

It will deploy files under example folder to gh-pages.

How to release

vi package.json
# update version in package.json
git add package.json
git commit -m "v1.X.X"
git push origin master
git tag v1.X.X master
git push --tag
# release CI will create draft release in Github pages, then publish it if it is ready.
# publish CI will deploy npmjs and Github Packages.

Contribution

This Mapbox GL Export Control is still under development. so most welcome any feedbacks and pull request to this repository.