@tinkatinka/static-map 1.5.0 → 1.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.
@@ -0,0 +1,6 @@
1
+ export declare const compactMap: <T, R>(array: T[], func: (value: T, idx: number) => R | undefined) => R[];
2
+ declare global {
3
+ interface Array<T> {
4
+ compactMap<R>(func: (value: T, idx: number) => R | undefined): Array<R>;
5
+ }
6
+ }
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.compactMap = void 0;
4
+ const isDefined = (value) => (value !== undefined);
5
+ const compactMap = (array, func) => array.map(func).filter(isDefined);
6
+ exports.compactMap = compactMap;
7
+ if (!Array.prototype.compactMap) {
8
+ Array.prototype.compactMap = function (func) {
9
+ return (0, exports.compactMap)(this, func);
10
+ };
11
+ }
package/dist/index.d.ts CHANGED
@@ -18,8 +18,8 @@ export interface StrokeOptions {
18
18
  export interface FillOptions {
19
19
  fillStyle: string | CanvasGradient | CanvasPattern;
20
20
  }
21
- export declare type StrokeFillOptions = SetOptional<StrokeOptions, 'strokeStyle'> & SetOptional<FillOptions, 'fillStyle'>;
22
- export declare type StaticMapOverlay = StaticMapImage | StaticMapLine | StaticMapCircle | StaticMapText | StaticMapScale;
21
+ export type StrokeFillOptions = SetOptional<StrokeOptions, 'strokeStyle'> & SetOptional<FillOptions, 'fillStyle'>;
22
+ export type StaticMapOverlay = StaticMapImage | StaticMapLine | StaticMapCircle | StaticMapText | StaticMapScale;
23
23
  export interface StaticMapImage {
24
24
  src: string;
25
25
  bounds: LatLngBounds;
@@ -28,7 +28,7 @@ export interface StaticMapLine {
28
28
  points: LatLng[];
29
29
  options: StaticMapLineOptions;
30
30
  }
31
- export declare type StaticMapLineOptions = StrokeOptions;
31
+ export type StaticMapLineOptions = StrokeOptions;
32
32
  export interface StaticMapCircle {
33
33
  center: LatLng;
34
34
  options: StaticMapCircleOptions;
@@ -46,8 +46,8 @@ export interface StaticMapTextOptions extends CanvasTextDrawingStyles, StrokeFil
46
46
  py: number;
47
47
  maxWidth?: number;
48
48
  }
49
- export declare type LengthUnits = 'metric' | 'imperial';
50
- export declare type LayoutPosition = 'topleft' | 'topright' | 'bottomleft' | 'bottomright';
49
+ export type LengthUnits = 'metric' | 'imperial';
50
+ export type LayoutPosition = 'topleft' | 'topright' | 'bottomleft' | 'bottomright';
51
51
  export interface StaticMapScale {
52
52
  options: StaticMapScaleOptions;
53
53
  }
package/dist/index.js CHANGED
@@ -8,6 +8,7 @@ const canvas_1 = __importDefault(require("canvas"));
8
8
  const lodash_merge_1 = __importDefault(require("lodash.merge"));
9
9
  const tilecache_1 = require("./tilecache");
10
10
  const base64img_1 = __importDefault(require("./base64img"));
11
+ const compactmap_1 = require("./compactmap");
11
12
  const EARTH_RADIUS_MEAN = 6371008.8;
12
13
  const FEET_PER_METER = 3.2808399;
13
14
  const FEET_PER_MILE = 5280;
@@ -204,6 +205,9 @@ class StaticMap {
204
205
  const a = overlay.anchor;
205
206
  return { min: a, max: a };
206
207
  }
208
+ case 'scale': {
209
+ return undefined;
210
+ }
207
211
  default:
208
212
  throw new Error(`Unknown overlay type "${type}"`);
209
213
  }
@@ -227,7 +231,7 @@ class StaticMap {
227
231
  lng: max(arr.map(b => b.max.lng))
228
232
  }
229
233
  });
230
- return union(this.overlays.map(this.overlayExtent.bind(this)));
234
+ return union((0, compactmap_1.compactMap)(this.overlays, this.overlayExtent.bind(this)));
231
235
  }
232
236
  calculateZoom(extent) {
233
237
  let z = this.options.tileMaxZoom + 1;
@@ -425,7 +429,10 @@ class StaticMap {
425
429
  ratio = scaleLen / maxFeet;
426
430
  }
427
431
  }
428
- const dx = width * ratio * scaledata.options.maxWidth / 100;
432
+ const midLeftP = this.latlngToPxPy(midLeft, zoom, centerXY, scale);
433
+ const midRightP = this.latlngToPxPy(midRight, zoom, centerXY, scale);
434
+ const widthP = Math.abs(midRightP.x - midLeftP.x);
435
+ const dx = widthP * ratio * scaledata.options.maxWidth / 100;
429
436
  let p0 = { x: 0, y: 0 };
430
437
  const mpx = Math.max(scaledata.options.mx * width / 100, scaledata.options.my * height / 100);
431
438
  const margin = { x: mpx, y: mpx };
@@ -521,6 +528,7 @@ StaticMap.defaultTextOptions = {
521
528
  textBaseline: 'middle',
522
529
  direction: 'inherit',
523
530
  font: '12px sans-serif',
531
+ fontKerning: 'auto',
524
532
  lineWidth: 1.0,
525
533
  lineCap: 'round',
526
534
  lineJoin: 'round',
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tinkatinka/static-map",
3
- "version": "1.5.0",
3
+ "version": "1.5.2",
4
4
  "description": "Render static map images",
5
5
  "author": "Florian Gmeiner <florian@tinkatinka.com>",
6
6
  "license": "MIT",
@@ -37,17 +37,17 @@
37
37
  "lodash.merge": "^4.6.2"
38
38
  },
39
39
  "devDependencies": {
40
- "@types/jest": "^27.0.1",
41
- "@types/jest-image-snapshot": "^4.3.0",
40
+ "@types/jest": "^29.4.0",
41
+ "@types/jest-image-snapshot": "^6.1.0",
42
42
  "@types/lodash.merge": "^4.6.6",
43
- "@types/node": "^17.0.13",
43
+ "@types/node": "^18.0.0",
44
44
  "@typescript-eslint/eslint-plugin": "^5.1.0",
45
45
  "eslint": "^8.0.1",
46
46
  "eslint-plugin-import": "^2.23.4",
47
- "jest": "^27.0.6",
48
- "jest-image-snapshot": "^4.5.1",
49
- "ts-jest": "^27.0.3",
50
- "type-fest": "^2.12.2",
47
+ "jest": "^29.5.0",
48
+ "jest-image-snapshot": "^6.1.0",
49
+ "ts-jest": "^29.0.5",
50
+ "type-fest": "^3.6.1",
51
51
  "typescript": "^4.3.4"
52
52
  },
53
53
  "peerDependencies": {