-
Notifications
You must be signed in to change notification settings - Fork 18
/
d-map-tile-pyramids.ts
75 lines (67 loc) · 2.17 KB
/
d-map-tile-pyramids.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
/*
* Copyright (C) 2019 Toshiba Corporation
* SPDX-License-Identifier: Apache-2.0
*/
import { DDiagramCanvasBase } from "./d-diagram-canvas-base";
import { DMapCoordinate } from "./d-map-coordinate";
import { DMapCoordinates } from "./d-map-coordinates";
import { DMapTilePyramid, DMapTilePyramidPlaneOptions } from "./d-map-tile-pyramid";
import { DMapTilePyramidImpl } from "./d-map-tile-pyramid-impl";
import { DMapTileUrlBuilder } from "./d-map-tile-url-builder";
export const DMapTileUrlBuilderKokudo: DMapTileUrlBuilder = (
tz: number,
tx: number,
ty: number
): string => {
if (5 <= tz) {
return `https://cyberjapandata.gsi.go.jp/xyz/pale/${tz}/${tx}/${ty}.png`;
} else if (2 <= tz) {
return `https://cyberjapandata.gsi.go.jp/xyz/std/${tz}/${tx}/${ty}.png`;
} else {
return `https://cyberjapandata.gsi.go.jp/xyz/earthhillshade/${tz}/${tx}/${ty}.png`;
}
};
export const DMapTileUrlBuilderOsm: DMapTileUrlBuilder = (
tz: number,
tx: number,
ty: number
): string => {
return `https://${"abc"[(tx + ty) % 3]}.tile.openstreetmap.org/${tz}/${tx}/${ty}.png`;
};
export const DMapTileUrlBuilderOsmfj: DMapTileUrlBuilder = (
tz: number,
tx: number,
ty: number
): string => {
return `https://j.tile.openstreetmap.jp/${tz}/${tx}/${ty}.png`;
};
export interface DMapTilePyramidsFromOptions {
canvas: DDiagramCanvasBase<any, any>;
builder?: DMapTileUrlBuilder;
coordinate?: DMapCoordinate;
plane?: Partial<DMapTilePyramidPlaneOptions>;
}
export class DMapTilePyramids {
protected static MIN: number = 0;
protected static MAX: number = 18;
protected static THROTTLE: number = 333;
protected static toPlaneOptions(
options: DMapTilePyramidsFromOptions
): DMapTilePyramidPlaneOptions {
const plane = options.plane;
return {
min: plane?.min ?? this.MIN,
max: plane?.max ?? this.MAX,
throttle: plane?.throttle ?? this.THROTTLE
};
}
static from(options: DMapTilePyramidsFromOptions): DMapTilePyramid {
return new DMapTilePyramidImpl({
canvas: options.canvas,
builder: options.builder || DMapTileUrlBuilderOsmfj,
mapping: options.canvas.tile.mapping,
coordinate: options.coordinate || DMapCoordinates.DEFAULT,
plane: this.toPlaneOptions(options)
});
}
}