@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.cjs
CHANGED
|
@@ -66,7 +66,7 @@ const PANEL_CSS = `
|
|
|
66
66
|
|
|
67
67
|
.svg-export-panel .panel-inputs {
|
|
68
68
|
display: grid;
|
|
69
|
-
grid-template-columns: 1fr 1fr
|
|
69
|
+
grid-template-columns: 1fr 1fr;
|
|
70
70
|
gap: 8px;
|
|
71
71
|
margin-bottom: 12px;
|
|
72
72
|
}
|
|
@@ -9361,13 +9361,11 @@ class SVGRenderer {
|
|
|
9361
9361
|
width;
|
|
9362
9362
|
height;
|
|
9363
9363
|
#svg;
|
|
9364
|
-
#scale;
|
|
9365
9364
|
#backgroundColor;
|
|
9366
9365
|
constructor(opt) {
|
|
9367
9366
|
this.width = opt.width;
|
|
9368
9367
|
this.height = opt.height;
|
|
9369
9368
|
this.#svg = [];
|
|
9370
|
-
this.#scale = opt.scale;
|
|
9371
9369
|
this.#backgroundColor = Color.transparent;
|
|
9372
9370
|
}
|
|
9373
9371
|
drawBackgroundFill(style) {
|
|
@@ -9387,7 +9385,7 @@ class SVGRenderer {
|
|
|
9387
9385
|
return;
|
|
9388
9386
|
const translate = style.translate[0] === 0 && style.translate[1] === 0
|
|
9389
9387
|
? ''
|
|
9390
|
-
: ` transform="translate(${formatPoint(style.translate
|
|
9388
|
+
: ` transform="translate(${formatPoint(style.translate)})"`;
|
|
9391
9389
|
const opacityAttr = style.opacity < 1 ? ` opacity="${style.opacity.toFixed(3)}"` : '';
|
|
9392
9390
|
const key = color.hex + translate + opacityAttr;
|
|
9393
9391
|
let group = groups.get(key);
|
|
@@ -9396,7 +9394,7 @@ class SVGRenderer {
|
|
|
9396
9394
|
groups.set(key, group);
|
|
9397
9395
|
}
|
|
9398
9396
|
feature.geometry.forEach((ring) => {
|
|
9399
|
-
group.segments.push(ring.map((p) => roundXY(p.x, p.y
|
|
9397
|
+
group.segments.push(ring.map((p) => roundXY(p.x, p.y)));
|
|
9400
9398
|
});
|
|
9401
9399
|
});
|
|
9402
9400
|
for (const { segments, attrs } of groups.values()) {
|
|
@@ -9416,10 +9414,10 @@ class SVGRenderer {
|
|
|
9416
9414
|
return;
|
|
9417
9415
|
const translate = style.translate[0] === 0 && style.translate[1] === 0
|
|
9418
9416
|
? ''
|
|
9419
|
-
: ` transform="translate(${formatPoint(style.translate
|
|
9420
|
-
const roundedWidth = formatScaled(style.width
|
|
9417
|
+
: ` transform="translate(${formatPoint(style.translate)})"`;
|
|
9418
|
+
const roundedWidth = formatScaled(style.width);
|
|
9421
9419
|
const dasharrayStr = style.dasharray
|
|
9422
|
-
? style.dasharray.map((v) => formatScaled(v * style.width
|
|
9420
|
+
? style.dasharray.map((v) => formatScaled(v * style.width)).join(',')
|
|
9423
9421
|
: '';
|
|
9424
9422
|
const opacityAttr = style.opacity < 1 ? ` opacity="${style.opacity.toFixed(3)}"` : '';
|
|
9425
9423
|
const key = [
|
|
@@ -9450,7 +9448,7 @@ class SVGRenderer {
|
|
|
9450
9448
|
groups.set(key, group);
|
|
9451
9449
|
}
|
|
9452
9450
|
feature.geometry.forEach((line) => {
|
|
9453
|
-
group.segments.push(line.map((p) => roundXY(p.x, p.y
|
|
9451
|
+
group.segments.push(line.map((p) => roundXY(p.x, p.y)));
|
|
9454
9452
|
});
|
|
9455
9453
|
});
|
|
9456
9454
|
for (const { segments, attrs } of groups.values()) {
|
|
@@ -9471,12 +9469,10 @@ class SVGRenderer {
|
|
|
9471
9469
|
return;
|
|
9472
9470
|
const translate = style.translate[0] === 0 && style.translate[1] === 0
|
|
9473
9471
|
? ''
|
|
9474
|
-
: ` transform="translate(${formatPoint(style.translate
|
|
9475
|
-
const roundedRadius = formatScaled(style.radius
|
|
9472
|
+
: ` transform="translate(${formatPoint(style.translate)})"`;
|
|
9473
|
+
const roundedRadius = formatScaled(style.radius);
|
|
9476
9474
|
const strokeColor = new Color(style.strokeColor);
|
|
9477
|
-
const strokeAttrs = style.strokeWidth > 0
|
|
9478
|
-
? ` ${strokeAttr(strokeColor, formatScaled(style.strokeWidth, this.#scale))}`
|
|
9479
|
-
: '';
|
|
9475
|
+
const strokeAttrs = style.strokeWidth > 0 ? ` ${strokeAttr(strokeColor, formatScaled(style.strokeWidth))}` : '';
|
|
9480
9476
|
const opacityAttr = style.opacity < 1 ? ` opacity="${style.opacity.toFixed(3)}"` : '';
|
|
9481
9477
|
const key = [color.hex, roundedRadius, strokeAttrs, opacityAttr, translate].join('\0');
|
|
9482
9478
|
let group = groups.get(key);
|
|
@@ -9490,7 +9486,7 @@ class SVGRenderer {
|
|
|
9490
9486
|
feature.geometry.forEach((ring) => {
|
|
9491
9487
|
const p = ring[0];
|
|
9492
9488
|
if (p)
|
|
9493
|
-
group.points.push(roundXY(p.x, p.y
|
|
9489
|
+
group.points.push(roundXY(p.x, p.y));
|
|
9494
9490
|
});
|
|
9495
9491
|
});
|
|
9496
9492
|
for (const { points, attrs } of groups.values()) {
|
|
@@ -9522,8 +9518,7 @@ class SVGRenderer {
|
|
|
9522
9518
|
const pixelated = style.resampling === 'nearest';
|
|
9523
9519
|
for (const tile of tiles) {
|
|
9524
9520
|
const overlap = Math.min(tile.width, tile.height) / 10000; // slight overlap to prevent sub-pixel gaps between tiles
|
|
9525
|
-
|
|
9526
|
-
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}"`;
|
|
9521
|
+
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}"`;
|
|
9527
9522
|
if (pixelated)
|
|
9528
9523
|
attrs += ' style="image-rendering:pixelated"';
|
|
9529
9524
|
this.#svg.push(`<image ${attrs} />`);
|
|
@@ -9557,14 +9552,14 @@ function strokeAttr(color, width) {
|
|
|
9557
9552
|
attr += ` stroke-opacity="${color.opacity.toFixed(3)}"`;
|
|
9558
9553
|
return attr;
|
|
9559
9554
|
}
|
|
9560
|
-
function formatScaled(v
|
|
9561
|
-
return formatNum(Math.round(v *
|
|
9555
|
+
function formatScaled(v) {
|
|
9556
|
+
return formatNum(Math.round(v * 10));
|
|
9562
9557
|
}
|
|
9563
|
-
function roundXY(x, y
|
|
9564
|
-
return [Math.round(x *
|
|
9558
|
+
function roundXY(x, y) {
|
|
9559
|
+
return [Math.round(x * 10), Math.round(y * 10)];
|
|
9565
9560
|
}
|
|
9566
|
-
function formatPoint(p
|
|
9567
|
-
const [x, y] = roundXY(p[0], p[1]
|
|
9561
|
+
function formatPoint(p) {
|
|
9562
|
+
const [x, y] = roundXY(p[0], p[1]);
|
|
9568
9563
|
return formatNum(x) + ',' + formatNum(y);
|
|
9569
9564
|
}
|
|
9570
9565
|
|
|
@@ -16415,15 +16410,12 @@ async function render(job) {
|
|
|
16415
16410
|
async function renderToSVG(options) {
|
|
16416
16411
|
const width = options.width ?? 1024;
|
|
16417
16412
|
const height = options.height ?? 1024;
|
|
16418
|
-
const scale = options.scale ?? 1;
|
|
16419
16413
|
if (width <= 0)
|
|
16420
16414
|
throw new Error('width must be positive');
|
|
16421
16415
|
if (height <= 0)
|
|
16422
16416
|
throw new Error('height must be positive');
|
|
16423
|
-
if (scale <= 0)
|
|
16424
|
-
throw new Error('scale must be positive');
|
|
16425
16417
|
return await renderMap({
|
|
16426
|
-
renderer: new SVGRenderer({ width, height
|
|
16418
|
+
renderer: new SVGRenderer({ width, height }),
|
|
16427
16419
|
style: options.style,
|
|
16428
16420
|
view: {
|
|
16429
16421
|
center: [options.lon ?? 0, options.lat ?? 0],
|
|
@@ -16484,7 +16476,6 @@ class SVGExportControl {
|
|
|
16484
16476
|
this.options = {
|
|
16485
16477
|
defaultWidth: options?.defaultWidth ?? 1024,
|
|
16486
16478
|
defaultHeight: options?.defaultHeight ?? 1024,
|
|
16487
|
-
defaultScale: options?.defaultScale ?? 1,
|
|
16488
16479
|
};
|
|
16489
16480
|
}
|
|
16490
16481
|
onAdd(map) {
|
|
@@ -16530,7 +16521,6 @@ class SVGExportControl {
|
|
|
16530
16521
|
<div class="panel-inputs">
|
|
16531
16522
|
<label>Width<input type="number" class="input-width" value="${String(this.options.defaultWidth)}" min="1" max="8192"></label>
|
|
16532
16523
|
<label>Height<input type="number" class="input-height" value="${String(this.options.defaultHeight)}" min="1" max="8192"></label>
|
|
16533
|
-
<label>Scale<input type="number" class="input-scale" value="${String(this.options.defaultScale)}" min="0.1" max="10" step="0.1"></label>
|
|
16534
16524
|
</div>
|
|
16535
16525
|
<div class="preview-container">
|
|
16536
16526
|
<span class="preview-loading">Rendering preview\u2026</span>
|
|
@@ -16628,8 +16618,7 @@ class SVGExportControl {
|
|
|
16628
16618
|
openBtn.disabled = true;
|
|
16629
16619
|
const width = Number(querySelector(panel, '.input-width').value);
|
|
16630
16620
|
const height = Number(querySelector(panel, '.input-height').value);
|
|
16631
|
-
|
|
16632
|
-
if (!width || !height || !scale || width < 1 || height < 1 || scale < 0.1) {
|
|
16621
|
+
if (!width || !height || width < 1 || height < 1) {
|
|
16633
16622
|
previewContainer.innerHTML = '<span class="preview-loading">Invalid input values</span>';
|
|
16634
16623
|
return;
|
|
16635
16624
|
}
|
|
@@ -16640,7 +16629,6 @@ class SVGExportControl {
|
|
|
16640
16629
|
const svg = await renderToSVG({
|
|
16641
16630
|
width,
|
|
16642
16631
|
height,
|
|
16643
|
-
scale,
|
|
16644
16632
|
style,
|
|
16645
16633
|
lon: center.lng,
|
|
16646
16634
|
lat: center.lat,
|