From cdcaa4a2d714fa6e2d741f10fae72cb7bd5f5bb5 Mon Sep 17 00:00:00 2001 From: Olivier Kamers Date: Mon, 5 Aug 2019 22:02:06 +0200 Subject: [PATCH] [@types/staticmaps] Initial commit (#37338) --- types/staticmaps/index.d.ts | 70 ++++++++++++++++++++ types/staticmaps/staticmaps-tests.ts | 97 ++++++++++++++++++++++++++++ types/staticmaps/tsconfig.json | 23 +++++++ types/staticmaps/tslint.json | 1 + 4 files changed, 191 insertions(+) create mode 100644 types/staticmaps/index.d.ts create mode 100644 types/staticmaps/staticmaps-tests.ts create mode 100644 types/staticmaps/tsconfig.json create mode 100644 types/staticmaps/tslint.json diff --git a/types/staticmaps/index.d.ts b/types/staticmaps/index.d.ts new file mode 100644 index 0000000000..ac7ddacb8c --- /dev/null +++ b/types/staticmaps/index.d.ts @@ -0,0 +1,70 @@ +// Type definitions for staticmaps 1.1 +// Project: https://github.com/StephanGeorg/staticmaps#readme +// Definitions by: Olivier Kamers +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +// TypeScript Version: 2.2 + +import { JpegOptions, OutputOptions, PngOptions, WebpOptions } from 'sharp'; + +declare class StaticMaps { + constructor(options: StaticMapsOptions); + + addLine: (options: AddLineOptions) => void; + addPolygon: (options: AddPolygonOptions) => void; + addMarker: (options: AddMarkerOptions) => void; + addText: (options: AddTextOptions) => void; + render: (center?: ReadonlyArray, zoom?: number) => Promise; + image: StaticMapsImage; +} + +declare class StaticMapsImage { + constructor(); + + image: Buffer; + save: (fileName?: string, outputOptions?: OutputOptions | PngOptions | JpegOptions | WebpOptions) => Promise; + buffer: (mime?: string, outputOptions?: OutputOptions | PngOptions | JpegOptions | WebpOptions) => Promise; +} + +export interface StaticMapsOptions { + width: number; + height: number; + paddingX?: number; + paddingY?: number; + tileUrl?: string; + tileSize?: number; + tileRequestTimeout?: number; + tileRequestHeader?: object; + maxZoom?: number; + reverseY?: boolean; +} + +export interface AddMarkerOptions { + coord: [number, number]; + img: string; + height: number; + width: number; + offsetX?: number; + offsetY?: number; +} + +export interface AddLineOptions { + coords: ReadonlyArray<[number, number]>; + color?: string; + width?: number; +} + +export interface AddPolygonOptions extends AddLineOptions { + fill?: string; +} + +export interface AddTextOptions { + coord: [number, number]; + text: string; + font?: string; + size?: number; + color?: string; + width?: number; + fill?: string; +} + +export default StaticMaps; diff --git a/types/staticmaps/staticmaps-tests.ts b/types/staticmaps/staticmaps-tests.ts new file mode 100644 index 0000000000..b37ede7f94 --- /dev/null +++ b/types/staticmaps/staticmaps-tests.ts @@ -0,0 +1,97 @@ +import StaticMaps from 'staticmaps'; + +// Initialization +const map = new StaticMaps({ + width: 100, + height: 100, +}); +new StaticMaps({ + width: 100, + height: 100, + paddingX: 1, + paddingY: 1, + tileUrl: 'https://tile.server/{x}/{y}/{z}', + tileSize: 50, + tileRequestTimeout: 2000, + tileRequestHeader: { + Authorization: 'Bearer token', + }, + maxZoom: 17, + reverseY: true, +}); + +// addMarker +map.addMarker({ + coord: [13.437524, 52.4945528], + img: './marker.png', // can also be a URL + height: 48, + width: 48, +}); +map.addMarker({ + coord: [13.437524, 52.4945528], + img: './marker.png', // can also be a URL + height: 48, + width: 48, + offsetX: 24, + offsetY: 48, +}); + +// addLine +map.addLine({ + coords: [[13.399259, 52.482659], [13.387849, 52.477144], [13.40538, 52.510632]], +}); +map.addLine({ + coords: [[13.399259, 52.482659], [13.387849, 52.477144], [13.40538, 52.510632]], + color: '#0000FFBB', + width: 3, +}); + +// addPolygon +map.addPolygon({ + coords: [[13.399259, 52.482659], [13.387849, 52.477144], [13.40538, 52.510632], [13.399259, 52.482659]], + color: '#0000FFBB', + width: 3, + fill: '#0000FFBB', +}); +map.addPolygon({ + coords: [[13.399259, 52.482659], [13.387849, 52.477144], [13.40538, 52.510632], [13.399259, 52.482659]], +}); + +// addText +map.addText({ + coord: [13.437524, 52.4945528], + text: 'My Text', +}); +map.addText({ + coord: [13.437524, 52.4945528], + text: 'My Text', + size: 50, + width: 1, + fill: '#000000', + color: '#ffffff', + font: 'Calibri', +}); + +// render +map.render(); +map.render([13.437524, 52.4945528], 15); + +// Save image +map.image + .save() + .then() + .catch(); +map.image + .save('my-staticmap-image.png', { compressionLevel: 9 }) + .then() + .catch(); + +// Buffer image +map.image + .buffer() + .then(buffer => buffer.toString()) + .catch(); +map.image + .buffer('image/jpeg', { quality: 75 }) + .then(buffer => buffer.toString()) + .catch(); diff --git a/types/staticmaps/tsconfig.json b/types/staticmaps/tsconfig.json new file mode 100644 index 0000000000..3900f379ff --- /dev/null +++ b/types/staticmaps/tsconfig.json @@ -0,0 +1,23 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictFunctionTypes": true, + "strictNullChecks": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "staticmaps-tests.ts" + ] +} diff --git a/types/staticmaps/tslint.json b/types/staticmaps/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/staticmaps/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" }