• This repository has been archived on 10/Mar/2024
  • Stars
    star
    142
  • Rank 257,009 (Top 6 %)
  • Language
    TypeScript
  • License
    MIT License
  • Created about 4 years ago
  • Updated 7 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

This module adds print control to mapbox-gl.

mapbox-gl-export

badge badge badge badge 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

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

Use CDN

<link href='https://watergis.github.io/mapbox-gl-export/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://watergis.github.io/mapbox-gl-export/mapbox-gl-export.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 page.

Demo

Try codesandbox.

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,
    PrintableArea: true
}), 'top-right');

if you want to use a basemap from Mapbox

  • for mapbox v1 user
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.
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

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

npm version patch # it increase patch version 0.0.X
npm version minor # it increase minor version 0.x.0
npm version major # it increase major version x.0.0
git push origin master --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.

More Repositories

1

mapbox-gl-legend

This module adds legend control which is able to create legend panel from mapbox style to mapbox-gl
TypeScript
109
star
2

maplibre-gl-export

This module adds control which can export PDF and images. It was forked from mapbox-gl-export.
TypeScript
87
star
3

dem2terrainrgb

This module is to convert DEM to terrain RGB raster tiles.
Python
68
star
4

svelte-maplibre-components

This repository to manage packages of svelte maplibre components for water application.
Svelte
42
star
5

maplibre-gl-legend

This module adds legend control which is able to create legend panel from mapbox style to maplibre-gl-legend
TypeScript
31
star
6

sveltekit-maplibre-boilerplate

This is a template to develop maplibre application by sveltekit
TypeScript
30
star
7

mapbox-gl-elevation

This module adds elevation control to mapbox-gl.
TypeScript
22
star
8

sveltekit-watergis-template

This repository is a sveltekit template to develop GIS for water application quickly
Svelte
18
star
9

terrain-rgb

This module is to get elevation from terrain RGB tilesets by longitude and latitude.
TypeScript
14
star
10

docs

A documentation website for open source software of this organization.
HTML
13
star
11

postgis2mbtiles

A module extracting the data from PostGIS to mbtiles by using tippecanoe.
JavaScript
12
star
12

mapbox-gl-valhalla

This module adds a control which can integrate with valhalla api.
TypeScript
9
star
13

mvt-generator

This module creates MVT tiles directly from PostGIS
JavaScript
5
star
14

mapboxgljs-boilerplate

This is the template of Mapbox GL JS implementation for Water Services Providers.
JavaScript
5
star
15

viewer

Svelte
4
star
16

mapbox.photon

This module adds mapbox plugin for Photon geocoder
TypeScript
3
star
17

geojson2inp

This module converts GeoJSON to EPANET INP file
TypeScript
3
star
18

mapbox-gl-area-switcher

This module adds area switcher control which is able to change locations of area quickly to mapbox-gl
TypeScript
3
star
19

mapbox-gl-popup

This module adds popup control which can show attributes of targeted layers to mapbox-gl
CSS
3
star
20

postgis2vectortiles

This is a simple tool to create Mapbox Vectortiles under particular directory from PostGIS database
JavaScript
2
star
21

postgis2geojson

This module is to extract GeoJSON files by SQL from PostGIS database.
JavaScript
2
star
22

mbtiles2pbf

This module will extract pbf files from mbtile by using mbutil.
TypeScript
2
star
23

awesome-vector-tiles

This is awesome implementations of the Mapbox Vector Tile for Water Services Providers
2
star
24

elastic2mvt

This module generate Mapbox vector tiles from Elasticsearch
JavaScript
2
star
25

19d

Open Buildings data introduced by Google for 19d tile grid data which can cover the whole Rwanda.
HTML
1
star
26

svelte-maplibre-legend

This is a svelte component to make layer legend for maplibre-gl
CSS
1
star
27

svelte-maplibre-attribute-popup

This is a svelte component to add attribute popup plugin to maplibre.
Svelte
1
star
28

maplibre-gl-elevation

This module adds elevation control to maplibre-gl.
TypeScript
1
star
29

mbgl-tileindex-viewer

This is a simple Mapbox GL JS viewer for showing tile boundaries and index number
HTML
1
star
30

es_tileserv

This is a simple vector tile server which is served from Elasticsearch.
JavaScript
1
star
31

ne2geojson

This is a simple module to download shapefile from Natural Earth and convert them to GeoJSON in order to use for UNVT.
JavaScript
1
star
32

postgis2mbtiles-docker

This is postgis2mbtiles for Docker
JavaScript
1
star
33

sprite-creator

This module is to generate sprite files from icon images.
JavaScript
1
star
34

excel2geojson

It is a module converting from Excel to Geojson
JavaScript
1
star