mirror of
https://github.com/zhigang1992/DefinitelyTyped.git
synced 2026-06-02 06:29:40 +08:00
feat: add mapnik d.ts
This commit is contained in:
49
types/mapnik/index.d.ts
vendored
Normal file
49
types/mapnik/index.d.ts
vendored
Normal file
@@ -0,0 +1,49 @@
|
||||
// Type definitions for mapnik 3.x
|
||||
// Project: http://mapnik.org
|
||||
// Definitions by: Loli <https://github.com/ipv4sec>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
|
||||
/// <reference types="node" />
|
||||
export const settings: any;
|
||||
export function register_default_fonts(): void;
|
||||
export function register_default_input_plugins(): void;
|
||||
export function register_datasource(path: string): void;
|
||||
export class VectorTile {
|
||||
constructor(z: number, x: number, y: number)
|
||||
addDataSync(vectorTile: any): void;
|
||||
}
|
||||
export class Datasource {
|
||||
constructor(datasource: any)
|
||||
featureset(): Featureset;
|
||||
}
|
||||
|
||||
export class Featureset {
|
||||
constructor()
|
||||
next(): FeaturesetNext;
|
||||
}
|
||||
export class FeaturesetNext {
|
||||
constructor()
|
||||
toJSON(): string;
|
||||
}
|
||||
|
||||
export class Image {
|
||||
constructor(x: number, y: number)
|
||||
encode(type: string, callback?: (err: Error, buffer: Buffer) => void): void;
|
||||
getData(): Buffer;
|
||||
}
|
||||
|
||||
export interface Image {
|
||||
// constructor(x: number, y: number)
|
||||
new(x: number, y: number): () => void;
|
||||
encode(type: string, callback?: (err: Error, buffer: Buffer) => void): void;
|
||||
getData(): Buffer;
|
||||
save(fp: string): () => void;
|
||||
open(fp: string): () => void;
|
||||
}
|
||||
|
||||
export class Map {
|
||||
constructor(x: number, y: number)
|
||||
load(xml: string, callback?: (err: Error, map: Map) => void): void;
|
||||
zoomAll(): void;
|
||||
render(images: Image | VectorTile , callback?: (err: Error, map: Image) => void): void;
|
||||
}
|
||||
40
types/mapnik/mapnik-tests.ts
Normal file
40
types/mapnik/mapnik-tests.ts
Normal file
@@ -0,0 +1,40 @@
|
||||
import * as mapnik from "mapnik";
|
||||
import * as fs from "fs";
|
||||
import * as path from "path";
|
||||
|
||||
mapnik.register_default_fonts();
|
||||
mapnik.register_default_input_plugins();
|
||||
|
||||
const map: mapnik.Map = new mapnik.Map(256, 256);
|
||||
map.load('./test/stylesheet.xml', function xx(err: Error, map: mapnik.Map) {
|
||||
if (err) throw err;
|
||||
map.zoomAll();
|
||||
const im: mapnik.Image = new mapnik.Image(256, 256);
|
||||
map.render(im, function xxx(err: Error, im: mapnik.Image) {
|
||||
if (err) throw err;
|
||||
im.encode('png', function xxxx(err: Error, buffer: Buffer) {
|
||||
if (err) throw err;
|
||||
fs.writeFile('map.png', buffer, function xxxxx(err: Error) {
|
||||
if (err) throw err;
|
||||
console.log('saved map image to map.png');
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
// new mapnik.Image.open("xxx").save("xx");
|
||||
|
||||
mapnik.register_datasource(path.join(mapnik.settings.paths.input_plugins, 'shape.input'));
|
||||
const ds: mapnik.Datasource = new mapnik.Datasource({type: 'shape', file: 'test/data/world_merc.shp'});
|
||||
const featureset: mapnik.Featureset = ds.featureset();
|
||||
const geojson: any = {
|
||||
type: "FeatureCollection",
|
||||
features: [
|
||||
]
|
||||
};
|
||||
let feat: mapnik.FeaturesetNext = featureset.next();
|
||||
while (feat) {
|
||||
geojson.features.push(JSON.parse(feat.toJSON()));
|
||||
feat = featureset.next();
|
||||
}
|
||||
fs.writeFileSync("output.geojson", JSON.stringify(geojson, null, 2));
|
||||
23
types/mapnik/tsconfig.json
Normal file
23
types/mapnik/tsconfig.json
Normal file
@@ -0,0 +1,23 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"module": "commonjs",
|
||||
"lib": [
|
||||
"es6"
|
||||
],
|
||||
"noImplicitAny": true,
|
||||
"noImplicitThis": true,
|
||||
"strictNullChecks": true,
|
||||
"strictFunctionTypes": true,
|
||||
"baseUrl": "../",
|
||||
"typeRoots": [
|
||||
"../"
|
||||
],
|
||||
"types": [],
|
||||
"noEmit": true,
|
||||
"forceConsistentCasingInFileNames": true
|
||||
},
|
||||
"files": [
|
||||
"index.d.ts",
|
||||
"mapnik-tests.ts"
|
||||
]
|
||||
}
|
||||
1
types/mapnik/tslint.json
Normal file
1
types/mapnik/tslint.json
Normal file
@@ -0,0 +1 @@
|
||||
{ "extends": "dtslint/dt.json" }
|
||||
Reference in New Issue
Block a user