@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/index.cjs
CHANGED
|
@@ -9187,13 +9187,11 @@ class SVGRenderer {
|
|
|
9187
9187
|
width;
|
|
9188
9188
|
height;
|
|
9189
9189
|
#svg;
|
|
9190
|
-
#scale;
|
|
9191
9190
|
#backgroundColor;
|
|
9192
9191
|
constructor(opt) {
|
|
9193
9192
|
this.width = opt.width;
|
|
9194
9193
|
this.height = opt.height;
|
|
9195
9194
|
this.#svg = [];
|
|
9196
|
-
this.#scale = opt.scale;
|
|
9197
9195
|
this.#backgroundColor = Color.transparent;
|
|
9198
9196
|
}
|
|
9199
9197
|
drawBackgroundFill(style) {
|
|
@@ -9213,7 +9211,7 @@ class SVGRenderer {
|
|
|
9213
9211
|
return;
|
|
9214
9212
|
const translate = style.translate[0] === 0 && style.translate[1] === 0
|
|
9215
9213
|
? ''
|
|
9216
|
-
: ` transform="translate(${formatPoint(style.translate
|
|
9214
|
+
: ` transform="translate(${formatPoint(style.translate)})"`;
|
|
9217
9215
|
const opacityAttr = style.opacity < 1 ? ` opacity="${style.opacity.toFixed(3)}"` : '';
|
|
9218
9216
|
const key = color.hex + translate + opacityAttr;
|
|
9219
9217
|
let group = groups.get(key);
|
|
@@ -9222,7 +9220,7 @@ class SVGRenderer {
|
|
|
9222
9220
|
groups.set(key, group);
|
|
9223
9221
|
}
|
|
9224
9222
|
feature.geometry.forEach((ring) => {
|
|
9225
|
-
group.segments.push(ring.map((p) => roundXY(p.x, p.y
|
|
9223
|
+
group.segments.push(ring.map((p) => roundXY(p.x, p.y)));
|
|
9226
9224
|
});
|
|
9227
9225
|
});
|
|
9228
9226
|
for (const { segments, attrs } of groups.values()) {
|
|
@@ -9242,10 +9240,10 @@ class SVGRenderer {
|
|
|
9242
9240
|
return;
|
|
9243
9241
|
const translate = style.translate[0] === 0 && style.translate[1] === 0
|
|
9244
9242
|
? ''
|
|
9245
|
-
: ` transform="translate(${formatPoint(style.translate
|
|
9246
|
-
const roundedWidth = formatScaled(style.width
|
|
9243
|
+
: ` transform="translate(${formatPoint(style.translate)})"`;
|
|
9244
|
+
const roundedWidth = formatScaled(style.width);
|
|
9247
9245
|
const dasharrayStr = style.dasharray
|
|
9248
|
-
? style.dasharray.map((v) => formatScaled(v * style.width
|
|
9246
|
+
? style.dasharray.map((v) => formatScaled(v * style.width)).join(',')
|
|
9249
9247
|
: '';
|
|
9250
9248
|
const opacityAttr = style.opacity < 1 ? ` opacity="${style.opacity.toFixed(3)}"` : '';
|
|
9251
9249
|
const key = [
|
|
@@ -9276,7 +9274,7 @@ class SVGRenderer {
|
|
|
9276
9274
|
groups.set(key, group);
|
|
9277
9275
|
}
|
|
9278
9276
|
feature.geometry.forEach((line) => {
|
|
9279
|
-
group.segments.push(line.map((p) => roundXY(p.x, p.y
|
|
9277
|
+
group.segments.push(line.map((p) => roundXY(p.x, p.y)));
|
|
9280
9278
|
});
|
|
9281
9279
|
});
|
|
9282
9280
|
for (const { segments, attrs } of groups.values()) {
|
|
@@ -9297,12 +9295,10 @@ class SVGRenderer {
|
|
|
9297
9295
|
return;
|
|
9298
9296
|
const translate = style.translate[0] === 0 && style.translate[1] === 0
|
|
9299
9297
|
? ''
|
|
9300
|
-
: ` transform="translate(${formatPoint(style.translate
|
|
9301
|
-
const roundedRadius = formatScaled(style.radius
|
|
9298
|
+
: ` transform="translate(${formatPoint(style.translate)})"`;
|
|
9299
|
+
const roundedRadius = formatScaled(style.radius);
|
|
9302
9300
|
const strokeColor = new Color(style.strokeColor);
|
|
9303
|
-
const strokeAttrs = style.strokeWidth > 0
|
|
9304
|
-
? ` ${strokeAttr(strokeColor, formatScaled(style.strokeWidth, this.#scale))}`
|
|
9305
|
-
: '';
|
|
9301
|
+
const strokeAttrs = style.strokeWidth > 0 ? ` ${strokeAttr(strokeColor, formatScaled(style.strokeWidth))}` : '';
|
|
9306
9302
|
const opacityAttr = style.opacity < 1 ? ` opacity="${style.opacity.toFixed(3)}"` : '';
|
|
9307
9303
|
const key = [color.hex, roundedRadius, strokeAttrs, opacityAttr, translate].join('\0');
|
|
9308
9304
|
let group = groups.get(key);
|
|
@@ -9316,7 +9312,7 @@ class SVGRenderer {
|
|
|
9316
9312
|
feature.geometry.forEach((ring) => {
|
|
9317
9313
|
const p = ring[0];
|
|
9318
9314
|
if (p)
|
|
9319
|
-
group.points.push(roundXY(p.x, p.y
|
|
9315
|
+
group.points.push(roundXY(p.x, p.y));
|
|
9320
9316
|
});
|
|
9321
9317
|
});
|
|
9322
9318
|
for (const { points, attrs } of groups.values()) {
|
|
@@ -9348,8 +9344,7 @@ class SVGRenderer {
|
|
|
9348
9344
|
const pixelated = style.resampling === 'nearest';
|
|
9349
9345
|
for (const tile of tiles) {
|
|
9350
9346
|
const overlap = Math.min(tile.width, tile.height) / 10000; // slight overlap to prevent sub-pixel gaps between tiles
|
|
9351
|
-
|
|
9352
|
-
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}"`;
|
|
9347
|
+
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}"`;
|
|
9353
9348
|
if (pixelated)
|
|
9354
9349
|
attrs += ' style="image-rendering:pixelated"';
|
|
9355
9350
|
this.#svg.push(`<image ${attrs} />`);
|
|
@@ -9383,14 +9378,14 @@ function strokeAttr(color, width) {
|
|
|
9383
9378
|
attr += ` stroke-opacity="${color.opacity.toFixed(3)}"`;
|
|
9384
9379
|
return attr;
|
|
9385
9380
|
}
|
|
9386
|
-
function formatScaled(v
|
|
9387
|
-
return formatNum(Math.round(v *
|
|
9381
|
+
function formatScaled(v) {
|
|
9382
|
+
return formatNum(Math.round(v * 10));
|
|
9388
9383
|
}
|
|
9389
|
-
function roundXY(x, y
|
|
9390
|
-
return [Math.round(x *
|
|
9384
|
+
function roundXY(x, y) {
|
|
9385
|
+
return [Math.round(x * 10), Math.round(y * 10)];
|
|
9391
9386
|
}
|
|
9392
|
-
function formatPoint(p
|
|
9393
|
-
const [x, y] = roundXY(p[0], p[1]
|
|
9387
|
+
function formatPoint(p) {
|
|
9388
|
+
const [x, y] = roundXY(p[0], p[1]);
|
|
9394
9389
|
return formatNum(x) + ',' + formatNum(y);
|
|
9395
9390
|
}
|
|
9396
9391
|
|
|
@@ -16241,15 +16236,12 @@ async function render(job) {
|
|
|
16241
16236
|
async function renderToSVG(options) {
|
|
16242
16237
|
const width = options.width ?? 1024;
|
|
16243
16238
|
const height = options.height ?? 1024;
|
|
16244
|
-
const scale = options.scale ?? 1;
|
|
16245
16239
|
if (width <= 0)
|
|
16246
16240
|
throw new Error('width must be positive');
|
|
16247
16241
|
if (height <= 0)
|
|
16248
16242
|
throw new Error('height must be positive');
|
|
16249
|
-
if (scale <= 0)
|
|
16250
|
-
throw new Error('scale must be positive');
|
|
16251
16243
|
return await renderMap({
|
|
16252
|
-
renderer: new SVGRenderer({ width, height
|
|
16244
|
+
renderer: new SVGRenderer({ width, height }),
|
|
16253
16245
|
style: options.style,
|
|
16254
16246
|
view: {
|
|
16255
16247
|
center: [options.lon ?? 0, options.lat ?? 0],
|