Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Typings for Node Platform #766

Merged
merged 8 commits into from
Feb 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,11 @@
"lib": "lib"
},
"files": [
"lib"
"lib",
"platform/node/index.d.ts"
],
"main": "platform/node/index.js",
"types": "platform/node/index.d.ts",
"repository": {
"type": "git",
"url": "git+https://github.com/maplibre/maplibre-gl-native.git"
Expand Down
129 changes: 129 additions & 0 deletions platform/node/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
declare module '@maplibre/maplibre-gl-native' {
const enum ResourceKind {
Unknown = 0,
Style = 1,
Source = 2,
Tile = 3,
Glyphs = 4,
SpriteImage = 5,
SpriteJSON = 6,
}

/**
* Response expected by a request call during render
*/
type RequestResponse = {
data: Uint8Array;
modified?: Date;
expires?: Date;
etag?: string;
};

const enum MapMode {
/**
* Render all tiles in map view
*/
Static = 'static',

/**
* Render and request only a single tile
*/
Tile = 'tile',
}

type MapOptions = {
/**
* Will be used during a `Map.render` call to request all necessary map resources (tiles, fonts...)
*/
request: (
request: { url: string; kind: ResourceKind },
callback: (error?: Error, response?: RequestResponse) => void,
) => void;

/**
* Pixel ratio at which to render images
*
* @default 1
*/
ratio?: number;
KiwiKilian marked this conversation as resolved.
Show resolved Hide resolved

/**
* Mode in which map view will be rendered
*
* @default MapMode.Static
*/
mode?: MapMode;
};

/**
* Defines the map view to render and the resulting image
*/
type RenderOptions = {
/**
* @default 0
*/
zoom?: number;

/**
* Width of image in pixel
*
* @default 512
*/
width?: number;

/**
* Height of image in pixel
*
* @default 512
*/
height?: number;

/**
* Coordinates [longitude, latitude]
*
* @default [0, 0]
*/
center?: [number, number];

/**
* Bearing of map view in degrees, counter-clockwise from north
*
* @default 0
*/
bearing?: number;

/**
* Pitch of map view in degrees, arcing towards the horizon
*
* @default 0
*/
pitch?: number;

/**
* @default []
*/
classes?: string[];
};

/**
* A `Map` instance is used to render images from map views
*/
class Map {
constructor(mapOptions: MapOptions);

load: (style: any) => void;

/**
* Render a specific map view to an image with previously loaded map styles
*/
render: (
renderOptions: RenderOptions,
callback: (...args: [error: Error, buffer: undefined] | [error: undefined, buffer: Uint8Array]) => void,
KiwiKilian marked this conversation as resolved.
Show resolved Hide resolved
) => void;

/**
* Call to permanently dispose the internal map resources, instance can't be used for further render calls
*/
release: () => void;
}
}