@versatiles/svg-renderer 0.5.1 → 0.5.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +18 -26
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +0 -1
- package/dist/index.js +18 -26
- package/dist/index.js.map +1 -1
- package/dist/maplibre.cjs +20 -32
- package/dist/maplibre.cjs.map +1 -1
- package/dist/maplibre.d.ts +0 -2
- package/dist/maplibre.js +20 -32
- package/dist/maplibre.js.map +1 -1
- package/dist/maplibre.umd.js +20 -32
- package/dist/maplibre.umd.js.map +1 -1
- package/package.json +1 -1
package/dist/maplibre.d.ts
CHANGED
|
@@ -4,7 +4,6 @@ import { StyleSpecification } from '@maplibre/maplibre-gl-style-spec';
|
|
|
4
4
|
interface SVGExportControlOptions {
|
|
5
5
|
defaultWidth?: number;
|
|
6
6
|
defaultHeight?: number;
|
|
7
|
-
defaultScale?: number;
|
|
8
7
|
}
|
|
9
8
|
declare class SVGExportControl implements IControl {
|
|
10
9
|
private map;
|
|
@@ -30,7 +29,6 @@ declare class SVGExportControl implements IControl {
|
|
|
30
29
|
declare function renderToSVG(options: {
|
|
31
30
|
width?: number;
|
|
32
31
|
height?: number;
|
|
33
|
-
scale?: number;
|
|
34
32
|
style: StyleSpecification;
|
|
35
33
|
lon?: number;
|
|
36
34
|
lat?: number;
|
package/dist/maplibre.js
CHANGED
|
@@ -64,7 +64,7 @@ const PANEL_CSS = `
|
|
|
64
64
|
|
|
65
65
|
.svg-export-panel .panel-inputs {
|
|
66
66
|
display: grid;
|
|
67
|
-
grid-template-columns: 1fr 1fr
|
|
67
|
+
grid-template-columns: 1fr 1fr;
|
|
68
68
|
gap: 8px;
|
|
69
69
|
margin-bottom: 12px;
|
|
70
70
|
}
|
|
@@ -9359,13 +9359,11 @@ class SVGRenderer {
|
|
|
9359
9359
|
width;
|
|
9360
9360
|
height;
|
|
9361
9361
|
#svg;
|
|
9362
|
-
#scale;
|
|
9363
9362
|
#backgroundColor;
|
|
9364
9363
|
constructor(opt) {
|
|
9365
9364
|
this.width = opt.width;
|
|
9366
9365
|
this.height = opt.height;
|
|
9367
9366
|
this.#svg = [];
|
|
9368
|
-
this.#scale = opt.scale;
|
|
9369
9367
|
this.#backgroundColor = Color.transparent;
|
|
9370
9368
|
}
|
|
9371
9369
|
drawBackgroundFill(style) {
|
|
@@ -9385,7 +9383,7 @@ class SVGRenderer {
|
|
|
9385
9383
|
return;
|
|
9386
9384
|
const translate = style.translate[0] === 0 && style.translate[1] === 0
|
|
9387
9385
|
? ''
|
|
9388
|
-
: ` transform="translate(${formatPoint(style.translate
|
|
9386
|
+
: ` transform="translate(${formatPoint(style.translate)})"`;
|
|
9389
9387
|
const opacityAttr = style.opacity < 1 ? ` opacity="${style.opacity.toFixed(3)}"` : '';
|
|
9390
9388
|
const key = color.hex + translate + opacityAttr;
|
|
9391
9389
|
let group = groups.get(key);
|
|
@@ -9394,7 +9392,7 @@ class SVGRenderer {
|
|
|
9394
9392
|
groups.set(key, group);
|
|
9395
9393
|
}
|
|
9396
9394
|
feature.geometry.forEach((ring) => {
|
|
9397
|
-
group.segments.push(ring.map((p) => roundXY(p.x, p.y
|
|
9395
|
+
group.segments.push(ring.map((p) => roundXY(p.x, p.y)));
|
|
9398
9396
|
});
|
|
9399
9397
|
});
|
|
9400
9398
|
for (const { segments, attrs } of groups.values()) {
|
|
@@ -9414,10 +9412,10 @@ class SVGRenderer {
|
|
|
9414
9412
|
return;
|
|
9415
9413
|
const translate = style.translate[0] === 0 && style.translate[1] === 0
|
|
9416
9414
|
? ''
|
|
9417
|
-
: ` transform="translate(${formatPoint(style.translate
|
|
9418
|
-
const roundedWidth = formatScaled(style.width
|
|
9415
|
+
: ` transform="translate(${formatPoint(style.translate)})"`;
|
|
9416
|
+
const roundedWidth = formatScaled(style.width);
|
|
9419
9417
|
const dasharrayStr = style.dasharray
|
|
9420
|
-
? style.dasharray.map((v) => formatScaled(v * style.width
|
|
9418
|
+
? style.dasharray.map((v) => formatScaled(v * style.width)).join(',')
|
|
9421
9419
|
: '';
|
|
9422
9420
|
const opacityAttr = style.opacity < 1 ? ` opacity="${style.opacity.toFixed(3)}"` : '';
|
|
9423
9421
|
const key = [
|
|
@@ -9448,7 +9446,7 @@ class SVGRenderer {
|
|
|
9448
9446
|
groups.set(key, group);
|
|
9449
9447
|
}
|
|
9450
9448
|
feature.geometry.forEach((line) => {
|
|
9451
|
-
group.segments.push(line.map((p) => roundXY(p.x, p.y
|
|
9449
|
+
group.segments.push(line.map((p) => roundXY(p.x, p.y)));
|
|
9452
9450
|
});
|
|
9453
9451
|
});
|
|
9454
9452
|
for (const { segments, attrs } of groups.values()) {
|
|
@@ -9469,12 +9467,10 @@ class SVGRenderer {
|
|
|
9469
9467
|
return;
|
|
9470
9468
|
const translate = style.translate[0] === 0 && style.translate[1] === 0
|
|
9471
9469
|
? ''
|
|
9472
|
-
: ` transform="translate(${formatPoint(style.translate
|
|
9473
|
-
const roundedRadius = formatScaled(style.radius
|
|
9470
|
+
: ` transform="translate(${formatPoint(style.translate)})"`;
|
|
9471
|
+
const roundedRadius = formatScaled(style.radius);
|
|
9474
9472
|
const strokeColor = new Color(style.strokeColor);
|
|
9475
|
-
const strokeAttrs = style.strokeWidth > 0
|
|
9476
|
-
? ` ${strokeAttr(strokeColor, formatScaled(style.strokeWidth, this.#scale))}`
|
|
9477
|
-
: '';
|
|
9473
|
+
const strokeAttrs = style.strokeWidth > 0 ? ` ${strokeAttr(strokeColor, formatScaled(style.strokeWidth))}` : '';
|
|
9478
9474
|
const opacityAttr = style.opacity < 1 ? ` opacity="${style.opacity.toFixed(3)}"` : '';
|
|
9479
9475
|
const key = [color.hex, roundedRadius, strokeAttrs, opacityAttr, translate].join('\0');
|
|
9480
9476
|
let group = groups.get(key);
|
|
@@ -9488,7 +9484,7 @@ class SVGRenderer {
|
|
|
9488
9484
|
feature.geometry.forEach((ring) => {
|
|
9489
9485
|
const p = ring[0];
|
|
9490
9486
|
if (p)
|
|
9491
|
-
group.points.push(roundXY(p.x, p.y
|
|
9487
|
+
group.points.push(roundXY(p.x, p.y));
|
|
9492
9488
|
});
|
|
9493
9489
|
});
|
|
9494
9490
|
for (const { points, attrs } of groups.values()) {
|
|
@@ -9520,8 +9516,7 @@ class SVGRenderer {
|
|
|
9520
9516
|
const pixelated = style.resampling === 'nearest';
|
|
9521
9517
|
for (const tile of tiles) {
|
|
9522
9518
|
const overlap = Math.min(tile.width, tile.height) / 10000; // slight overlap to prevent sub-pixel gaps between tiles
|
|
9523
|
-
|
|
9524
|
-
let attrs = `x="${formatScaled(tile.x - overlap, s)}" y="${formatScaled(tile.y - overlap, s)}" width="${formatScaled(tile.width + overlap * 2, s)}" height="${formatScaled(tile.height + overlap * 2, s)}" href="${tile.dataUri}"`;
|
|
9519
|
+
let attrs = `x="${formatScaled(tile.x - overlap)}" y="${formatScaled(tile.y - overlap)}" width="${formatScaled(tile.width + overlap * 2)}" height="${formatScaled(tile.height + overlap * 2)}" href="${tile.dataUri}"`;
|
|
9525
9520
|
if (pixelated)
|
|
9526
9521
|
attrs += ' style="image-rendering:pixelated"';
|
|
9527
9522
|
this.#svg.push(`<image ${attrs} />`);
|
|
@@ -9555,14 +9550,14 @@ function strokeAttr(color, width) {
|
|
|
9555
9550
|
attr += ` stroke-opacity="${color.opacity.toFixed(3)}"`;
|
|
9556
9551
|
return attr;
|
|
9557
9552
|
}
|
|
9558
|
-
function formatScaled(v
|
|
9559
|
-
return formatNum(Math.round(v *
|
|
9553
|
+
function formatScaled(v) {
|
|
9554
|
+
return formatNum(Math.round(v * 10));
|
|
9560
9555
|
}
|
|
9561
|
-
function roundXY(x, y
|
|
9562
|
-
return [Math.round(x *
|
|
9556
|
+
function roundXY(x, y) {
|
|
9557
|
+
return [Math.round(x * 10), Math.round(y * 10)];
|
|
9563
9558
|
}
|
|
9564
|
-
function formatPoint(p
|
|
9565
|
-
const [x, y] = roundXY(p[0], p[1]
|
|
9559
|
+
function formatPoint(p) {
|
|
9560
|
+
const [x, y] = roundXY(p[0], p[1]);
|
|
9566
9561
|
return formatNum(x) + ',' + formatNum(y);
|
|
9567
9562
|
}
|
|
9568
9563
|
|
|
@@ -16413,15 +16408,12 @@ async function render(job) {
|
|
|
16413
16408
|
async function renderToSVG(options) {
|
|
16414
16409
|
const width = options.width ?? 1024;
|
|
16415
16410
|
const height = options.height ?? 1024;
|
|
16416
|
-
const scale = options.scale ?? 1;
|
|
16417
16411
|
if (width <= 0)
|
|
16418
16412
|
throw new Error('width must be positive');
|
|
16419
16413
|
if (height <= 0)
|
|
16420
16414
|
throw new Error('height must be positive');
|
|
16421
|
-
if (scale <= 0)
|
|
16422
|
-
throw new Error('scale must be positive');
|
|
16423
16415
|
return await renderMap({
|
|
16424
|
-
renderer: new SVGRenderer({ width, height
|
|
16416
|
+
renderer: new SVGRenderer({ width, height }),
|
|
16425
16417
|
style: options.style,
|
|
16426
16418
|
view: {
|
|
16427
16419
|
center: [options.lon ?? 0, options.lat ?? 0],
|
|
@@ -16482,7 +16474,6 @@ class SVGExportControl {
|
|
|
16482
16474
|
this.options = {
|
|
16483
16475
|
defaultWidth: options?.defaultWidth ?? 1024,
|
|
16484
16476
|
defaultHeight: options?.defaultHeight ?? 1024,
|
|
16485
|
-
defaultScale: options?.defaultScale ?? 1,
|
|
16486
16477
|
};
|
|
16487
16478
|
}
|
|
16488
16479
|
onAdd(map) {
|
|
@@ -16528,7 +16519,6 @@ class SVGExportControl {
|
|
|
16528
16519
|
<div class="panel-inputs">
|
|
16529
16520
|
<label>Width<input type="number" class="input-width" value="${String(this.options.defaultWidth)}" min="1" max="8192"></label>
|
|
16530
16521
|
<label>Height<input type="number" class="input-height" value="${String(this.options.defaultHeight)}" min="1" max="8192"></label>
|
|
16531
|
-
<label>Scale<input type="number" class="input-scale" value="${String(this.options.defaultScale)}" min="0.1" max="10" step="0.1"></label>
|
|
16532
16522
|
</div>
|
|
16533
16523
|
<div class="preview-container">
|
|
16534
16524
|
<span class="preview-loading">Rendering preview\u2026</span>
|
|
@@ -16626,8 +16616,7 @@ class SVGExportControl {
|
|
|
16626
16616
|
openBtn.disabled = true;
|
|
16627
16617
|
const width = Number(querySelector(panel, '.input-width').value);
|
|
16628
16618
|
const height = Number(querySelector(panel, '.input-height').value);
|
|
16629
|
-
|
|
16630
|
-
if (!width || !height || !scale || width < 1 || height < 1 || scale < 0.1) {
|
|
16619
|
+
if (!width || !height || width < 1 || height < 1) {
|
|
16631
16620
|
previewContainer.innerHTML = '<span class="preview-loading">Invalid input values</span>';
|
|
16632
16621
|
return;
|
|
16633
16622
|
}
|
|
@@ -16638,7 +16627,6 @@ class SVGExportControl {
|
|
|
16638
16627
|
const svg = await renderToSVG({
|
|
16639
16628
|
width,
|
|
16640
16629
|
height,
|
|
16641
|
-
scale,
|
|
16642
16630
|
style,
|
|
16643
16631
|
lon: center.lng,
|
|
16644
16632
|
lat: center.lat,
|