@tinkatinka/static-map 2.0.0 → 3.0.0
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/README.md +16 -0
- package/dist/base64img.js +1 -2
- package/dist/compactmap.d.ts +1 -1
- package/dist/index.d.ts +10 -4
- package/dist/index.js +40 -2
- package/package.json +13 -13
package/README.md
CHANGED
|
@@ -112,6 +112,22 @@ interface StaticMapRectOptions {
|
|
|
112
112
|
}
|
|
113
113
|
```
|
|
114
114
|
|
|
115
|
+
#### Polygons
|
|
116
|
+
```ts
|
|
117
|
+
addPolygon(points: LatLng[], options?: Partial<StaticMapPolygonOptions>);
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
Options:
|
|
121
|
+
|
|
122
|
+
```ts
|
|
123
|
+
interface StaticMapPolygonOptions {
|
|
124
|
+
strokeStyle: string; // css stroke style [default: 'black']
|
|
125
|
+
lineWidth: number; // line width in pixels [default: 1.0]
|
|
126
|
+
lineCap: 'butt' | 'round' | 'square'; // [default: 'round']
|
|
127
|
+
lineJoin: 'bevel' | 'round' | 'miter'; // [default: 'round']
|
|
128
|
+
}
|
|
129
|
+
```
|
|
130
|
+
|
|
115
131
|
#### Text
|
|
116
132
|
```ts
|
|
117
133
|
.addText(text: string, anchor: LatLng, options?: Partial<StaticMapTextOptions>);
|
package/dist/base64img.js
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
const base64img = async (url, mimetype = 'image/png', userAgent = 'StaticMap/1.0') => {
|
|
1
|
+
const base64img = async (url, mimetype = 'image/png', userAgent = 'StaticMap/2') => {
|
|
3
2
|
const response = await fetch(url, {
|
|
4
3
|
headers: {
|
|
5
4
|
'User-Agent': userAgent
|
package/dist/compactmap.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export declare const compactMap: <T, R>(array: T
|
|
1
|
+
export declare const compactMap: <T, R>(array: Array<T>, func: (value: T, idx: number) => R | undefined) => Array<R>;
|
|
2
2
|
declare global {
|
|
3
3
|
interface Array<T> {
|
|
4
4
|
compactMap<R>(func: (value: T, idx: number) => R | undefined): Array<R>;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
/// <reference types="node" />
|
|
2
1
|
import Canvas from 'canvas';
|
|
3
2
|
import type { SetOptional, PartialDeep } from 'type-fest';
|
|
4
3
|
export interface LatLng {
|
|
@@ -21,8 +20,8 @@ export interface FillOptions {
|
|
|
21
20
|
export type StrokeFillOptions = SetOptional<StrokeOptions, 'strokeStyle'> & SetOptional<FillOptions, 'fillStyle'>;
|
|
22
21
|
export type StaticMapOverlay = {
|
|
23
22
|
type: StaticMapOverlayType;
|
|
24
|
-
} & StaticMapImage | StaticMapLine | StaticMapCircle | StaticMapRect | StaticMapText | StaticMapScale;
|
|
25
|
-
type StaticMapOverlayType = 'image' | 'line' | 'circle' | 'rect' | 'text' | 'scale';
|
|
23
|
+
} & StaticMapImage | StaticMapLine | StaticMapCircle | StaticMapRect | StaticMapPolygon | StaticMapText | StaticMapScale;
|
|
24
|
+
type StaticMapOverlayType = 'image' | 'line' | 'circle' | 'rect' | 'polygon' | 'text' | 'scale';
|
|
26
25
|
export interface StaticMapImage {
|
|
27
26
|
type: 'image';
|
|
28
27
|
src: string;
|
|
@@ -48,13 +47,19 @@ export interface StaticMapRect {
|
|
|
48
47
|
bounds: LatLngBounds;
|
|
49
48
|
options: StaticMapRectOptions;
|
|
50
49
|
}
|
|
50
|
+
export type StaticMapPolygonOptions = StrokeFillOptions;
|
|
51
|
+
export interface StaticMapPolygon {
|
|
52
|
+
type: 'polygon';
|
|
53
|
+
points: LatLng[];
|
|
54
|
+
options: StaticMapPolygonOptions;
|
|
55
|
+
}
|
|
51
56
|
export interface StaticMapText {
|
|
52
57
|
type: 'text';
|
|
53
58
|
text: string;
|
|
54
59
|
anchor: LatLng;
|
|
55
60
|
options: StaticMapTextOptions;
|
|
56
61
|
}
|
|
57
|
-
export interface StaticMapTextOptions extends CanvasTextDrawingStyles, StrokeFillOptions {
|
|
62
|
+
export interface StaticMapTextOptions extends SetOptional<CanvasTextDrawingStyles, 'letterSpacing' | 'wordSpacing'>, StrokeFillOptions {
|
|
58
63
|
px: number;
|
|
59
64
|
py: number;
|
|
60
65
|
maxWidth?: number;
|
|
@@ -122,6 +127,7 @@ export declare class StaticMap {
|
|
|
122
127
|
addLine(src: LatLng, dst: LatLng, options?: Partial<StaticMapLineOptions>): StaticMap;
|
|
123
128
|
addCircle(center: LatLng, options?: Partial<StaticMapCircleOptions>): StaticMap;
|
|
124
129
|
addRectangle(bounds: LatLngBounds, options?: Partial<StaticMapRectOptions>): StaticMap;
|
|
130
|
+
addPolygon(points: LatLng[], options?: Partial<StaticMapPolygonOptions>): StaticMap;
|
|
125
131
|
addText(text: string, anchor: LatLng, options?: Partial<StaticMapTextOptions>): StaticMap;
|
|
126
132
|
addScale(options?: PartialDeep<StaticMapScaleOptions>): StaticMap;
|
|
127
133
|
private boundsCenter;
|
package/dist/index.js
CHANGED
|
@@ -46,10 +46,13 @@ export class StaticMap {
|
|
|
46
46
|
direction: 'inherit',
|
|
47
47
|
font: '12px sans-serif',
|
|
48
48
|
fontKerning: 'auto',
|
|
49
|
+
fontStretch: 'normal',
|
|
50
|
+
fontVariantCaps: 'normal',
|
|
49
51
|
lineWidth: 1.0,
|
|
50
52
|
lineCap: 'round',
|
|
51
53
|
lineJoin: 'round',
|
|
52
|
-
fillStyle: 'black'
|
|
54
|
+
fillStyle: 'black',
|
|
55
|
+
textRendering: 'auto'
|
|
53
56
|
};
|
|
54
57
|
static defaultScaleOptions = {
|
|
55
58
|
units: 'metric',
|
|
@@ -141,6 +144,16 @@ export class StaticMap {
|
|
|
141
144
|
options: merge({}, StaticMap.defaultRectOptions, options)
|
|
142
145
|
});
|
|
143
146
|
}
|
|
147
|
+
addPolygon(points, options) {
|
|
148
|
+
if (points.length >= 2) {
|
|
149
|
+
return this.addOverlay({
|
|
150
|
+
type: 'polygon',
|
|
151
|
+
points,
|
|
152
|
+
options: merge({}, StaticMap.defaultLineOptions, options)
|
|
153
|
+
});
|
|
154
|
+
}
|
|
155
|
+
return this;
|
|
156
|
+
}
|
|
144
157
|
addText(text, anchor, options) {
|
|
145
158
|
return this.addOverlay({
|
|
146
159
|
type: 'text',
|
|
@@ -245,7 +258,8 @@ export class StaticMap {
|
|
|
245
258
|
}
|
|
246
259
|
case 'rect':
|
|
247
260
|
return overlay.bounds;
|
|
248
|
-
case 'line':
|
|
261
|
+
case 'line':
|
|
262
|
+
case 'polygon': {
|
|
249
263
|
const min = (arr) => arr.reduce((prev, curr) => ((curr < prev) ? curr : prev));
|
|
250
264
|
const max = (arr) => arr.reduce((prev, curr) => ((curr > prev) ? curr : prev));
|
|
251
265
|
const bounds = (points) => ({
|
|
@@ -425,6 +439,30 @@ export class StaticMap {
|
|
|
425
439
|
}
|
|
426
440
|
break;
|
|
427
441
|
}
|
|
442
|
+
case 'polygon': {
|
|
443
|
+
if (overlay.points.length > 1) {
|
|
444
|
+
const p0 = this.latlngToPxPy(overlay.points[0], zoom, centerXY, scale);
|
|
445
|
+
ctx.beginPath();
|
|
446
|
+
ctx.moveTo(p0.x, p0.y);
|
|
447
|
+
for (const p of overlay.points.slice(1)) {
|
|
448
|
+
const pxy = this.latlngToPxPy(p, zoom, centerXY, scale);
|
|
449
|
+
ctx.lineTo(pxy.x, pxy.y);
|
|
450
|
+
}
|
|
451
|
+
ctx.closePath();
|
|
452
|
+
if (overlay.options.fillStyle) {
|
|
453
|
+
ctx.fillStyle = overlay.options.fillStyle;
|
|
454
|
+
ctx.fill();
|
|
455
|
+
}
|
|
456
|
+
if (overlay.options.strokeStyle && overlay.options.lineWidth > 0) {
|
|
457
|
+
ctx.strokeStyle = overlay.options.strokeStyle;
|
|
458
|
+
ctx.lineWidth = overlay.options.lineWidth;
|
|
459
|
+
ctx.lineCap = overlay.options.lineCap;
|
|
460
|
+
ctx.lineJoin = overlay.options.lineJoin;
|
|
461
|
+
ctx.stroke();
|
|
462
|
+
}
|
|
463
|
+
}
|
|
464
|
+
break;
|
|
465
|
+
}
|
|
428
466
|
case 'circle': {
|
|
429
467
|
const ccenter = this.latlngToPxPy(overlay.center, zoom, centerXY, scale);
|
|
430
468
|
ctx.beginPath();
|
package/package.json
CHANGED
|
@@ -1,12 +1,15 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tinkatinka/static-map",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "3.0.0",
|
|
4
4
|
"description": "Render static map images",
|
|
5
5
|
"author": "Florian Gmeiner <florian@tinkatinka.com>",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"type": "module",
|
|
8
8
|
"main": "dist/index.js",
|
|
9
9
|
"types": "dist/index.d.ts",
|
|
10
|
+
"engines": {
|
|
11
|
+
"node": ">=18.0.0"
|
|
12
|
+
},
|
|
10
13
|
"files": [
|
|
11
14
|
"dist"
|
|
12
15
|
],
|
|
@@ -26,27 +29,24 @@
|
|
|
26
29
|
"scripts": {
|
|
27
30
|
"build": "tsc -p tsconfig.build.json",
|
|
28
31
|
"clean": "rm -rf dist/*",
|
|
29
|
-
"lint": "eslint
|
|
30
|
-
"test": "tsc -p tsconfig.test.json && node --experimental-vm-modules --no-warnings --test --test-reporter=spec
|
|
32
|
+
"lint": "eslint",
|
|
33
|
+
"test": "tsc -p tsconfig.test.json && node --experimental-vm-modules --no-warnings --test --test-reporter=spec"
|
|
31
34
|
},
|
|
32
35
|
"browser": {
|
|
33
36
|
"node-fetch": false
|
|
34
37
|
},
|
|
35
38
|
"dependencies": {
|
|
36
|
-
"canvas": "^
|
|
37
|
-
"cross-fetch": "^4.0.0",
|
|
39
|
+
"canvas": "^3.1.0",
|
|
38
40
|
"lodash-es": "^4.17.21"
|
|
39
41
|
},
|
|
40
42
|
"devDependencies": {
|
|
43
|
+
"@eslint/js": "^9.9.0",
|
|
44
|
+
"@types/eslint__js": "^8.42.3",
|
|
41
45
|
"@types/lodash-es": "^4.17.12",
|
|
42
|
-
"@types/node": "^
|
|
43
|
-
"
|
|
44
|
-
"eslint": "^8.0.1",
|
|
45
|
-
"eslint-plugin-import": "^2.23.4",
|
|
46
|
+
"@types/node": "^22.5.0",
|
|
47
|
+
"eslint": "^9.9.0",
|
|
46
48
|
"type-fest": "^4.6.0",
|
|
47
|
-
"typescript": "^5.
|
|
48
|
-
|
|
49
|
-
"peerDependencies": {
|
|
50
|
-
"canvas": "^2.8.0"
|
|
49
|
+
"typescript": "^5.5.4",
|
|
50
|
+
"typescript-eslint": "^8.2.0"
|
|
51
51
|
}
|
|
52
52
|
}
|