-
Notifications
You must be signed in to change notification settings - Fork 8
/
index.d.ts
179 lines (149 loc) · 3.83 KB
/
index.d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
import {Database} from 'sqlite3-offline'
type Tile = MBTiles.Tile
type Metadata = MBTiles.Metadata
type UpdateMetadata = MBTiles.UpdateMetadata
type Bounds = MBTiles.Bounds
type BBox = MBTiles.BBox
type Center = MBTiles.Center
type Formats = 'jpg' | 'png' | 'pbf' | 'webp'
type Types = 'overlay' | 'baselayer'
type Schema = 'xyz' | 'tms' | 'quadkey'
interface SchemaType {
xyz: Tile
tms: Tile
quadkey: string
}
declare class MBTilesClass<T extends Tile | string> {
// Metadata properties
type: string
version: string
name?: string
minzoom?: number
maxzoom?: number
format?: string
bounds?: BBox
center?: Center
description?: string
attribution?: string
url?: string
// Extra properties
db?: Database
uri?: string
errors?: any[]
ok?: boolean
schema?: string
constructor(uri: string, schema?: Schema)
/**
* Save buffer data to individual Tile
*/
save(tile: T, image: Buffer): Promise<boolean>
/**
* Retrieves Metadata from MBTiles
*/
metadata(): Promise<Metadata>
/**
* Sync: Retrieves Metadata from MBTiles
*/
metadataSync(callback: (error: Error, metadata: Metadata) => void): void
/**
* Delete individual Tile
*/
delete(tile: T): Promise<boolean>
/**
* Count the amount of Tiles
*/
count(tiles?: T[]): Promise<number>
/**
* Update Metadata
*/
update(metadata: UpdateMetadata): Promise<Metadata>
/**
* Finds all Tile unique hashes
*/
findAll(tiles?: T[]): Promise<T[]>
/**
* Finds one Tile and returns Buffer
*/
findOne(tile: T): Promise<Buffer>
/**
* Sync: Finds one Tile and returns Buffer
*/
findOneSync(tile: T, callback: (error: Error, tile: Buffer) => void): void
/**
* Build SQL tables
*/
tables(): Promise<boolean>
/**
* Build SQL index
*/
index(): Promise<boolean>
/**
* Creates hash from a single Tile
*/
hash(tile: T): number
/**
* Creates a hash table for all tiles
*/
hashes(tiles?: T[]): Promise<MBTiles.Hashes>
/**
* Retrieves Minimum Zoom level
*/
getMinZoom(): Promise<number>
/**
* Retrieves Maximum Zoom level
*/
getMaxZoom(): Promise<number>
/**
* Retrieves Image Format
*/
getFormat(): Promise<MBTiles.Formats>
/**
* Retrieves Bounds
*/
getBounds(zoom?: number): Promise<MBTiles.BBox>
/**
* Validate MBTiles according to the specifications
*/
validate(): Promise<boolean>
}
declare namespace MBTiles {
export type Center = [number, number]
export type Tile = [number, number, number]
export type BBox = [number, number, number, number]
export type Formats = 'png' | 'jpeg' | 'jpeg' | 'pbf'
export type Types = 'baselayer' | 'overlay'
export type Versions = '1.0.0' | '1.1.0' | '1.2.0'
export type Polygon = GeoJSON.Feature<GeoJSON.Polygon>
export type Polygons = GeoJSON.FeatureCollection<GeoJSON.Polygon>
export type MultiPolygon = GeoJSON.Feature<GeoJSON.MultiPolygon>
export type MultiPolygons = GeoJSON.FeatureCollection<GeoJSON.MultiPolygon>
export type Bounds = BBox | BBox[] | Polygon | Polygons | MultiPolygon | MultiPolygons
export type Hashes = Set<number>
export type MBTilesStatic = MBTilesClass<Tile | string>
export type MBTilesTile = MBTilesClass<Tile>
export type MBTilesQuadkey = MBTilesClass<string>
export interface Metadata extends BaseMetadata {
bounds?: BBox
}
export interface UpdateMetadata extends BaseMetadata {
bounds?: Bounds
}
export interface BaseMetadata {
name: string
description: string
minzoom?: number
maxzoom?: number
format?: string
type?: string
version?: string
center?: Center
attribution?: string
url?: string
}
}
interface MBTiles {
new (uri: string, schema: 'quadkey'): MBTilesClass<string>;
new (uri: string, schema?: 'xyz' | 'tms'): MBTilesClass<Tile>;
}
declare const MBTiles: MBTiles;
export = MBTiles