@tinkatinka/static-map 1.5.0 → 1.5.1

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.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 };
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.1",
4
4
  "description": "Render static map images",
5
5
  "author": "Florian Gmeiner <florian@tinkatinka.com>",
6
6
  "license": "MIT",
@@ -37,16 +37,16 @@
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": "^28.0.0",
41
+ "@types/jest-image-snapshot": "^5.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",
47
+ "jest": "^28.0.0",
48
+ "jest-image-snapshot": "^5.1.0",
49
+ "ts-jest": "^28.0.0",
50
50
  "type-fest": "^2.12.2",
51
51
  "typescript": "^4.3.4"
52
52
  },