[@types/staticmaps] Initial commit (#37338)

This commit is contained in:
Olivier Kamers 2019-08-05 22:02:06 +02:00 committed by Nathan Shively-Sanders
parent 043bb9aa9a
commit cdcaa4a2d7
4 changed files with 191 additions and 0 deletions

70
types/staticmaps/index.d.ts vendored Normal file
View File

@ -0,0 +1,70 @@
// Type definitions for staticmaps 1.1
// Project: https://github.com/StephanGeorg/staticmaps#readme
// Definitions by: Olivier Kamers <https://github.com/olivierkamers>
// 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<number>, zoom?: number) => Promise<void>;
image: StaticMapsImage;
}
declare class StaticMapsImage {
constructor();
image: Buffer;
save: (fileName?: string, outputOptions?: OutputOptions | PngOptions | JpegOptions | WebpOptions) => Promise<void>;
buffer: (mime?: string, outputOptions?: OutputOptions | PngOptions | JpegOptions | WebpOptions) => Promise<Buffer>;
}
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;

View File

@ -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();

View File

@ -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"
]
}

View File

@ -0,0 +1 @@
{ "extends": "dtslint/dt.json" }