Skip to content

Releases: watergis/maplibre-gl-export

@watergis/maplibre-gl-export@5.0.0

Choose a tag to compare

@github-actions github-actions released this 24 Jul 11:31
940c490

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 ScaleControl and an AttributionControl are 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 glyphs property 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 own AttributionControl element, so it keeps the library's native styling and there is nothing to configure. attributionOptions now accepts compact and customAttribution of maplibre's AttributionControlOptions, plus visibility, position (any of the four corners) and margin.

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.

    MapGenerator is now exported from both packages and exposes toCanvas() and toBlob(), 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 download option and an onExport callback, so the image produced by the generate button of the panel can be picked up by the application. download defaults to true, 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 AllowedSizes option.

    AllowedSizes used 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] }]
    });

    size is [width, height] in mm in landscape order, exactly like the presets, so the Page Orientation dropdown swaps it when portrait is 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-align declaration from the export list button style. text-align: right was overridden by text-align: center on 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/Y and content were dropped, so high resolution icons were exported at their full bitmap size and icon-color was 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 nested Map instead of a plain object.

@watergis/mapbox-gl-export@4.0.0

Choose a tag to compare

@github-actions github-actions released this 24 Jul 11:31
940c490

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 ScaleControl and an AttributionControl are 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 glyphs property 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 own AttributionControl element, so it keeps the library's native styling and there is nothing to configure. attributionOptions now accepts compact and customAttribution of mapbox's AttributionControlOptions, plus visibility, position (any of the four corners) and margin.

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.

    MapGenerator is now exported from both packages and exposes toCanvas() and toBlob(), 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 download option and an onExport callback, so the image produced by the generate button of the panel can be picked up by the application. download defaults to true, 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 AllowedSizes option.

    AllowedSizes used 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] }]
    });

    size is [width, height] in mm in landscape order, exactly like the presets, so the Page Orientation dropdown swaps it when portrait is 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-align declaration from the export list button style. text-align: right was overridden by text-align: center on 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/Y and content were dropped, so high resolution icons were exported at their full bitmap size and icon-color was 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 nested Map instead of a plain object.

@watergis/maplibre-gl-export@4.2.0

Choose a tag to compare

@github-actions github-actions released this 23 Jul 11:58
8c27206

Minor Changes

  • ae0a9f0: Support MapLibre GL JS v5 and v6, with v6 as the stable default.

Patch Changes

  • 8e94e1f: chore: update dependencies

@watergis/mapbox-gl-export@3.6.2

Choose a tag to compare

@github-actions github-actions released this 23 Jul 11:58
8c27206

Patch Changes

  • 8e94e1f: chore: update dependencies

@watergis/maplibre-gl-export@4.1.2

Choose a tag to compare

@github-actions github-actions released this 28 Mar 12:18
ac4f97b

Patch Changes

  • 68e4abc: chore: updated dependencies

@watergis/mapbox-gl-export@3.6.1

Choose a tag to compare

@github-actions github-actions released this 28 Mar 12:18
ac4f97b

Patch Changes

  • 68e4abc: chore: updated dependencies

@watergis/maplibre-gl-export@4.1.1

Choose a tag to compare

@github-actions github-actions released this 18 Jan 13:45
1948bf2

Patch Changes

  • 3cc9a19: chore: update jspdf to 4.0.0

@watergis/maplibre-gl-export@4.1.0

Choose a tag to compare

@github-actions github-actions released this 29 Aug 04:58
389cefb

Minor Changes

  • a84469e: feat: add Russian translation

Patch Changes

  • 2689f24: chore: updated dependencies in package.json

@watergis/mapbox-gl-export@3.6.0

Choose a tag to compare

@github-actions github-actions released this 29 Aug 04:58
389cefb

Minor Changes

  • a84469e: feat: add Russian translation

Patch Changes

  • 2689f24: chore: updated dependencies in package.json

@watergis/maplibre-gl-export@4.0.1

Choose a tag to compare

@github-actions github-actions released this 10 Mar 07:08
cd9ffe8

Patch Changes

  • 513f0e5: chore: updated dependencies