Releases: watergis/maplibre-gl-export
Release list
@watergis/maplibre-gl-export@5.0.0
Major Changes
-
be90fa4: feat: draw the attribution, north icon and a new scale bar onto the exported image with a composed 2D canvas instead of adding them as symbol layers.
The exported map canvas is now composed onto a 2D canvas before being saved, and the overlays are drawn on top of it. A
ScaleControland anAttributionControlare added to the hidden map used for rendering, and their elements are rasterized and drawn onto the exported image, keeping maplibre's native styling. This removes the limitations of the previous symbol layer approach:- the attribution no longer requires the
glyphsproperty in the style - the attribution and the north icon are no longer hidden at zoom levels below 2
- the attribution can now be placed in any of the four corners
- a scale bar is exported for the first time, and can be toggled from the export panel together with the north icon
Usage
The scale bar and north icon can be toggled from the export panel, and both overlays can be configured through
MaplibreExportControl:import { MaplibreExportControl, Size, PageOrientation, Format, DPI } from '@watergis/maplibre-gl-export'; const exportControl = new MaplibreExportControl({ PageSize: Size.A3, PageOrientation: PageOrientation.Landscape, Format: Format.PNG, DPI: DPI[300], // attribution: rasterized from maplibre's own AttributionControl (keeps native styling) attributionOptions: { visibility: 'visible', position: 'bottom-right', // any of the four corners margin: 10, // distance from the map edge at 96 DPI compact: false, customAttribution: '© My Company' }, // scale bar: exported for the first time scalebarOptions: { visibility: 'visible', position: 'bottom-left', margin: 10, maxWidth: 100, unit: 'metric' // 'metric' | 'imperial' | 'nautical' }, // north icon northIconOptions: { visibility: 'visible', position: 'top-right', margin: 10 } }); map.addControl(exportControl, 'top-right');
Breaking changes
attributionOptions.style(textSize,textColor,textHaloColor,textHaloWidth,fallbackTextFont) has been removed. The attribution is now rasterized from maplibre's ownAttributionControlelement, so it keeps the library's native styling and there is nothing to configure.attributionOptionsnow acceptscompactandcustomAttributionof maplibre'sAttributionControlOptions, plusvisibility,position(any of the four corners) andmargin. - the attribution no longer requires the
Minor Changes
-
b7b4173: feat: add custom to PageSize menu to allow users to change height and width freely,
-
1d9d37d: feat: make the generated image available to the application instead of only downloading it.
MapGeneratoris now exported from both packages and exposestoCanvas()andtoBlob(), so the image can be generated without the export panel and without saving a file:import { MapGenerator, Format, Size } from '@watergis/maplibre-gl-export'; // composed canvas of the map, at the requested page size and DPI const canvas = await new MapGenerator(map, { size: Size.A4, dpi: 300 }).toCanvas(); // or the image in the configured format. png, jpg, pdf and svg are supported const blob = await new MapGenerator(map, { size: Size.A4, format: Format.PDF }).toBlob(); setPdfUrl(URL.createObjectURL(blob));
The generator and the export control also accept a
downloadoption and anonExportcallback, so the image produced by the generate button of the panel can be picked up by the application.downloaddefaults totrue, so the file keeps being saved unless it is turned off:map.addControl( new MaplibreExportControl({ PageSize: Size.A4, Format: Format.PNG, // do not save the image as a file, only hand it over to `onExport` download: false, onExport: ({ canvas, blob, fileName, format }) => { console.log(`generated ${fileName} (${format}), ${blob.size} bytes`); setImageUrl(URL.createObjectURL(blob)); } }), 'top-right' );
-
c31e758: feat: allow developer-defined page sizes in the
AllowedSizesoption.AllowedSizesused to accept only the names of the built-in paper presets, so aspect ratios that are not paper formats (16:9, 3:2, 1:1, ...) could not be offered in the page size dropdown. An entry can now also be a{ name, size }pair, and preset names and custom sizes can be mixed in the same list.const exportControl = new MaplibreExportControl({ AllowedSizes: ['A4', { name: '16:9', size: [320, 180] }, { name: 'Square', size: [200, 200] }] });
sizeis[width, height]in mm in landscape order, exactly like the presets, so the Page Orientation dropdown swaps it whenportraitis selected. Invalid entries are ignored instead of breaking the panel. Passing an array of preset names keeps working unchanged.
Patch Changes
- b7b4173: fix: fixed form layout collapse, make it look better.
- 01a8ecf: fix: remove the duplicated
text-aligndeclaration from the export list button style.text-align: rightwas overridden bytext-align: centeron the next line, so only the dead declaration is dropped and the rendering is unchanged. - 2e65aca: fix: keep the metadata of the style images when they are copied to the map used for exporting.
pixelRatio,sdf,stretchX/Yandcontentwere dropped, so high resolution icons were exported at their full bitmap size andicon-colorwas no longer applied to SDF icons. The mapbox plugin additionally failed to copy any image at all, because mapbox-gl v3 keeps them in a nestedMapinstead of a plain object.
@watergis/mapbox-gl-export@4.0.0
Major Changes
-
be90fa4: feat: draw the attribution, north icon and a new scale bar onto the exported image with a composed 2D canvas instead of adding them as symbol layers.
The exported map canvas is now composed onto a 2D canvas before being saved, and the overlays are drawn on top of it. A
ScaleControland anAttributionControlare added to the hidden map used for rendering, and their elements are rasterized and drawn onto the exported image, keeping mapbox's native styling. This removes the limitations of the previous symbol layer approach:- the attribution no longer requires the
glyphsproperty in the style - the attribution and the north icon are no longer hidden at zoom levels below 2
- the attribution can now be placed in any of the four corners
- a scale bar is exported for the first time, and can be toggled from the export panel together with the north icon
Usage
The scale bar and north icon can be toggled from the export panel, and both overlays can be configured through
MapboxExportControl:import { MapboxExportControl } from '@watergis/mapbox-gl-export'; import { Size, PageOrientation, Format, DPI } from '@watergis/maplibre-gl-export'; const exportControl = new MapboxExportControl({ PageSize: Size.A3, PageOrientation: PageOrientation.Landscape, Format: Format.PNG, DPI: DPI[300], // attribution: rasterized from mapbox's own AttributionControl (keeps native styling) attributionOptions: { visibility: 'visible', position: 'bottom-right', // any of the four corners margin: 10, // distance from the map edge at 96 DPI compact: false, customAttribution: '© My Company' }, // scale bar: exported for the first time scalebarOptions: { visibility: 'visible', position: 'bottom-left', margin: 10, maxWidth: 100, unit: 'metric' // 'metric' | 'imperial' | 'nautical' }, // north icon northIconOptions: { visibility: 'visible', position: 'top-right', margin: 10 } }); map.addControl(exportControl, 'top-right');
Breaking changes
attributionOptions.style(textSize,textColor,textHaloColor,textHaloWidth,fallbackTextFont) has been removed. The attribution is now rasterized from mapbox's ownAttributionControlelement, so it keeps the library's native styling and there is nothing to configure.attributionOptionsnow acceptscompactandcustomAttributionof mapbox'sAttributionControlOptions, plusvisibility,position(any of the four corners) andmargin. - the attribution no longer requires the
Minor Changes
-
b7b4173: feat: add custom to PageSize menu to allow users to change height and width freely,
-
1d9d37d: feat: make the generated image available to the application instead of only downloading it.
MapGeneratoris now exported from both packages and exposestoCanvas()andtoBlob(), so the image can be generated without the export panel and without saving a file:import { MapGenerator, Format, Size } from '@watergis/maplibre-gl-export'; // composed canvas of the map, at the requested page size and DPI const canvas = await new MapGenerator(map, { size: Size.A4, dpi: 300 }).toCanvas(); // or the image in the configured format. png, jpg, pdf and svg are supported const blob = await new MapGenerator(map, { size: Size.A4, format: Format.PDF }).toBlob(); setPdfUrl(URL.createObjectURL(blob));
The generator and the export control also accept a
downloadoption and anonExportcallback, so the image produced by the generate button of the panel can be picked up by the application.downloaddefaults totrue, so the file keeps being saved unless it is turned off:map.addControl( new MaplibreExportControl({ PageSize: Size.A4, Format: Format.PNG, // do not save the image as a file, only hand it over to `onExport` download: false, onExport: ({ canvas, blob, fileName, format }) => { console.log(`generated ${fileName} (${format}), ${blob.size} bytes`); setImageUrl(URL.createObjectURL(blob)); } }), 'top-right' );
-
c31e758: feat: allow developer-defined page sizes in the
AllowedSizesoption.AllowedSizesused to accept only the names of the built-in paper presets, so aspect ratios that are not paper formats (16:9, 3:2, 1:1, ...) could not be offered in the page size dropdown. An entry can now also be a{ name, size }pair, and preset names and custom sizes can be mixed in the same list.const exportControl = new MaplibreExportControl({ AllowedSizes: ['A4', { name: '16:9', size: [320, 180] }, { name: 'Square', size: [200, 200] }] });
sizeis[width, height]in mm in landscape order, exactly like the presets, so the Page Orientation dropdown swaps it whenportraitis selected. Invalid entries are ignored instead of breaking the panel. Passing an array of preset names keeps working unchanged.
Patch Changes
- b7b4173: fix: fixed form layout collapse, make it look better.
- 01a8ecf: fix: remove the duplicated
text-aligndeclaration from the export list button style.text-align: rightwas overridden bytext-align: centeron the next line, so only the dead declaration is dropped and the rendering is unchanged. - 2e65aca: fix: keep the metadata of the style images when they are copied to the map used for exporting.
pixelRatio,sdf,stretchX/Yandcontentwere dropped, so high resolution icons were exported at their full bitmap size andicon-colorwas no longer applied to SDF icons. The mapbox plugin additionally failed to copy any image at all, because mapbox-gl v3 keeps them in a nestedMapinstead of a plain object.
@watergis/maplibre-gl-export@4.2.0
@watergis/mapbox-gl-export@3.6.2
Patch Changes
- 8e94e1f: chore: update dependencies
@watergis/maplibre-gl-export@4.1.2
Patch Changes
- 68e4abc: chore: updated dependencies
@watergis/mapbox-gl-export@3.6.1
Patch Changes
- 68e4abc: chore: updated dependencies
@watergis/maplibre-gl-export@4.1.1
Patch Changes
- 3cc9a19: chore: update jspdf to 4.0.0
@watergis/maplibre-gl-export@4.1.0
@watergis/mapbox-gl-export@3.6.0
@watergis/maplibre-gl-export@4.0.1
Patch Changes
- 513f0e5: chore: updated dependencies