@maptrip/map-tiles 1.2.0 → 1.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +5 -0
- package/dist/api-extensions/google/MapTripGoogleMapType.d.ts +1 -1
- package/dist/api-extensions/leaflet/MapTripLeafletGridLayer.d.ts +33 -1
- package/dist/api-extensions/openlayers/MapTripOpenLayersSource.d.ts +7 -0
- package/dist/core/VectorTileFactory.d.ts +1 -1
- package/dist/core/VectorTileRenderer.d.ts +1 -1
- package/dist/core/rendering_config_grayscale.d.ts +34 -0
- package/dist/map-tiles.d.ts +3 -2
- package/dist/map-tiles.js +1065 -865
- package/dist/map-tiles.js.map +1 -1
- package/dist/types/interfaces.d.ts +9 -9
- package/dist/util/MapReleaseFetcher.d.ts +12 -0
- package/lib/api-extensions/google/MapTripGoogleMapType.ts +4 -1
- package/lib/api-extensions/leaflet/MapTripLeafletGridLayer.ts +119 -23
- package/lib/api-extensions/openlayers/MapTripOpenLayersSource.ts +37 -0
- package/lib/core/VectorTileFactory.ts +17 -13
- package/lib/core/VectorTileRenderer.ts +13 -5
- package/lib/core/rendering_config_grayscale.ts +1126 -1104
- package/lib/main.ts +3 -2
- package/lib/types/interfaces.ts +11 -10
- package/lib/util/MapReleaseFetcher.ts +82 -0
- package/package.json +7 -6
|
@@ -12,6 +12,7 @@ export interface MapTilesProperties {
|
|
|
12
12
|
maxZoom?: number;
|
|
13
13
|
name?: string;
|
|
14
14
|
NAME?: string;
|
|
15
|
+
releaseDate?: boolean | false;
|
|
15
16
|
}
|
|
16
17
|
export interface Renderer {
|
|
17
18
|
from: number;
|
|
@@ -35,13 +36,6 @@ export interface Renderer {
|
|
|
35
36
|
dy: number;
|
|
36
37
|
};
|
|
37
38
|
filters?: Filter[];
|
|
38
|
-
[key: string]: any;
|
|
39
|
-
}
|
|
40
|
-
export interface Filter {
|
|
41
|
-
interface: string;
|
|
42
|
-
key: string;
|
|
43
|
-
value?: any;
|
|
44
|
-
type: string;
|
|
45
39
|
}
|
|
46
40
|
export interface RENDERING_CONFIG {
|
|
47
41
|
background: {
|
|
@@ -56,6 +50,12 @@ export interface RENDERING_CONFIG {
|
|
|
56
50
|
[key: string]: Renderer[];
|
|
57
51
|
};
|
|
58
52
|
}
|
|
53
|
+
export interface Filter {
|
|
54
|
+
interface: string;
|
|
55
|
+
key: string;
|
|
56
|
+
value?: any;
|
|
57
|
+
type: string;
|
|
58
|
+
}
|
|
59
59
|
export interface PolylineTextStyle {
|
|
60
60
|
size: number;
|
|
61
61
|
color: string;
|
|
@@ -79,8 +79,8 @@ export interface PolygonStyle {
|
|
|
79
79
|
opacity?: number | undefined;
|
|
80
80
|
outlineColor?: string | undefined;
|
|
81
81
|
outlineWidth?: number | undefined;
|
|
82
|
-
url
|
|
83
|
-
font
|
|
82
|
+
url?: string | undefined;
|
|
83
|
+
font?: string | undefined;
|
|
84
84
|
fontStyle?: string | undefined;
|
|
85
85
|
fontWeight?: string | undefined;
|
|
86
86
|
size?: number | undefined;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export declare class MapReleaseFetcher {
|
|
2
|
+
private _baseUrl;
|
|
3
|
+
private _token;
|
|
4
|
+
private _tomtom;
|
|
5
|
+
private _osm;
|
|
6
|
+
private _here;
|
|
7
|
+
constructor(token: string);
|
|
8
|
+
updateUrl(provider: string): void;
|
|
9
|
+
getRelease(provider: string): Promise<string | null>;
|
|
10
|
+
fetchAndExtractRelease(provider: string): Promise<string | null>;
|
|
11
|
+
private extractTargetString;
|
|
12
|
+
}
|
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
import { VectorTileFactory } from "../../core/VectorTileFactory.js";
|
|
2
2
|
import { MIN_ZOOM, MAX_ZOOM } from "../../core/constants.js";
|
|
3
|
-
import {
|
|
3
|
+
import {
|
|
4
|
+
RENDERING_CONFIG
|
|
5
|
+
} from "../../types/interfaces.js";
|
|
6
|
+
import { PointXY } from "../../types/interfaces.js";
|
|
4
7
|
|
|
5
8
|
class MapTripGoogleMapType {
|
|
6
9
|
tileSize = new google.maps.Size(256, 256);
|
|
@@ -1,14 +1,22 @@
|
|
|
1
1
|
import L from "leaflet";
|
|
2
|
-
|
|
3
2
|
import { VectorTileFactory } from "../../core/VectorTileFactory.js";
|
|
4
3
|
import { MIN_ZOOM, MAX_ZOOM, ATTRIBUTION } from "../../core/constants.js";
|
|
5
|
-
import
|
|
4
|
+
import { MapReleaseFetcher } from "../../util/MapReleaseFetcher.js";
|
|
5
|
+
import type { PointXY } from "../../types/interfaces.js";
|
|
6
|
+
import { RENDERING_CONFIG } from "../../types/interfaces.js";
|
|
6
7
|
|
|
7
|
-
|
|
8
|
-
MIN_ZOOM
|
|
9
|
-
MAX_ZOOM
|
|
8
|
+
class MapTripLeafletGridLayer extends L.GridLayer {
|
|
9
|
+
MIN_ZOOM = MIN_ZOOM;
|
|
10
|
+
MAX_ZOOM = MAX_ZOOM;
|
|
11
|
+
token: string;
|
|
12
|
+
factory: VectorTileFactory;
|
|
13
|
+
releaseFetcher: MapReleaseFetcher;
|
|
14
|
+
provider: string;
|
|
15
|
+
attribution: string;
|
|
16
|
+
release: string;
|
|
17
|
+
releaseDate: boolean;
|
|
10
18
|
|
|
11
|
-
|
|
19
|
+
constructor(options: {
|
|
12
20
|
provider?: string;
|
|
13
21
|
baseMap?: boolean;
|
|
14
22
|
traffic?: boolean;
|
|
@@ -20,25 +28,113 @@ const MapTripLeafletGridLayer = L.GridLayer.extend({
|
|
|
20
28
|
attribution?: string;
|
|
21
29
|
minZoom?: number;
|
|
22
30
|
maxZoom?: number;
|
|
31
|
+
releaseDate?: boolean;
|
|
23
32
|
}) {
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
33
|
+
super(options as L.GridLayerOptions);
|
|
34
|
+
this.token = options.token!;
|
|
35
|
+
this.provider = options.provider
|
|
36
|
+
? options.provider?.toLowerCase()
|
|
37
|
+
: "openstreetmap";
|
|
38
|
+
|
|
39
|
+
this.options.attribution = options.attribution
|
|
40
|
+
? options.attribution
|
|
41
|
+
: ATTRIBUTION;
|
|
42
|
+
this.releaseFetcher = new MapReleaseFetcher(this.token);
|
|
43
|
+
this.release = "";
|
|
44
|
+
this.attribution = "";
|
|
45
|
+
|
|
46
|
+
this.releaseDate = options.releaseDate ? options.releaseDate : false;
|
|
47
|
+
if (this.releaseDate) {
|
|
48
|
+
this.initializeAttribution();
|
|
49
|
+
this.on("add", () => {
|
|
50
|
+
if (this._map) {
|
|
51
|
+
this._map.on("baselayerchange", (event) =>
|
|
52
|
+
this.onBaseLayerChange(event)
|
|
53
|
+
);
|
|
54
|
+
}
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
//@ts-expect-error picking up LayerOptions rather than GridLayerOptions
|
|
59
|
+
this.options.minZoom = options.minZoom
|
|
60
|
+
? Math.max(this.MIN_ZOOM, options.minZoom)
|
|
61
|
+
: this.MIN_ZOOM;
|
|
62
|
+
//@ts-expect-error
|
|
63
|
+
this.options.maxZoom = options.maxZoom
|
|
64
|
+
? Math.min(this.MAX_ZOOM, options.maxZoom)
|
|
65
|
+
: this.MAX_ZOOM;
|
|
66
|
+
|
|
67
|
+
this.factory = VectorTileFactory.createFactory(options);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
createTile(coords: PointXY) {
|
|
71
|
+
return this.factory.getJsonTile(coords.z!, coords.x, coords.y, this.token);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
private async initializeAttribution() {
|
|
75
|
+
await this.setRelease();
|
|
76
|
+
await this.setAttribution();
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
// Set an original release
|
|
80
|
+
private async setRelease() {
|
|
81
|
+
const release = await this.releaseFetcher.getRelease(this.provider);
|
|
82
|
+
if (release) {
|
|
83
|
+
this.release = release;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
private async setAttribution() {
|
|
88
|
+
if (!this._map) return;
|
|
89
|
+
try {
|
|
90
|
+
// check if base layer changes to a new provider
|
|
91
|
+
const newRelease = await this.releaseFetcher.getRelease(this.provider);
|
|
92
|
+
if (newRelease && newRelease !== this.release) {
|
|
93
|
+
this.release = newRelease;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
// remove the original attribution in order to append the release date
|
|
97
|
+
this._map.attributionControl.removeAttribution(this.options.attribution!);
|
|
98
|
+
this.attribution = `${this.options.attribution} ${this.release}`;
|
|
99
|
+
this._map.attributionControl.addAttribution(this.attribution!);
|
|
100
|
+
|
|
101
|
+
// remove the attribution with release date from map for instances where different layers have different preferences for setting release date
|
|
102
|
+
const map = this._map;
|
|
103
|
+
this._map.addEventListener("baselayerchange", () => {
|
|
104
|
+
map.attributionControl.removeAttribution(this.attribution)
|
|
105
|
+
})
|
|
106
|
+
|
|
107
|
+
} catch (error) {
|
|
108
|
+
console.error("Error fetching release version: ", error);
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
private async onBaseLayerChange(event: L.LayersControlEvent) {
|
|
113
|
+
if (!this._map) {
|
|
114
|
+
return;
|
|
36
115
|
}
|
|
37
|
-
},
|
|
38
116
|
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
117
|
+
this._map.attributionControl.removeAttribution(this.attribution);
|
|
118
|
+
|
|
119
|
+
//@ts-expect-error doesn't recognize provider in options object
|
|
120
|
+
const eventProvider = event.layer.options.provider;
|
|
121
|
+
let newProvider: string;
|
|
122
|
+
if (eventProvider) {
|
|
123
|
+
if (eventProvider.toLowerCase() === "opensreetmap") {
|
|
124
|
+
newProvider = "openstreetmap";
|
|
125
|
+
} else if (eventProvider.toLowerCase() === "tomtom") {
|
|
126
|
+
newProvider = "tomtom";
|
|
127
|
+
} else if (eventProvider.toLowerCase() === "here") {
|
|
128
|
+
newProvider = "here";
|
|
129
|
+
} else {
|
|
130
|
+
newProvider = "openstreetmap";
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
this.provider = newProvider;
|
|
134
|
+
|
|
135
|
+
await this.setAttribution();
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
}
|
|
43
139
|
|
|
44
140
|
export { MapTripLeafletGridLayer };
|
|
@@ -4,10 +4,15 @@ import { XYZOptions, createXYZ, extentFromProjection } from "ol/tilegrid.js";
|
|
|
4
4
|
import { VectorTileFactory } from "../../core/VectorTileFactory.js";
|
|
5
5
|
import { MIN_ZOOM, MAX_ZOOM, ATTRIBUTION } from "../../core/constants.js";
|
|
6
6
|
import { RENDERING_CONFIG } from "../../types/interfaces.js";
|
|
7
|
+
import { MapReleaseFetcher } from "../../main.js";
|
|
7
8
|
|
|
8
9
|
class MapTripOpenLayersSource extends XYZ {
|
|
9
10
|
token: string;
|
|
10
11
|
factory: VectorTileFactory;
|
|
12
|
+
release: string = "";
|
|
13
|
+
releaseFetcher: MapReleaseFetcher;
|
|
14
|
+
releaseDate: boolean;
|
|
15
|
+
|
|
11
16
|
constructor(properties: {
|
|
12
17
|
provider?: string;
|
|
13
18
|
baseMap?: boolean;
|
|
@@ -17,6 +22,7 @@ class MapTripOpenLayersSource extends XYZ {
|
|
|
17
22
|
detourProfile?: string;
|
|
18
23
|
renderingConfig?: RENDERING_CONFIG;
|
|
19
24
|
token?: string;
|
|
25
|
+
releaseDate?: boolean;
|
|
20
26
|
}) {
|
|
21
27
|
const options: XYZOptions = {};
|
|
22
28
|
const projection = "EPSG:3857";
|
|
@@ -55,6 +61,37 @@ class MapTripOpenLayersSource extends XYZ {
|
|
|
55
61
|
|
|
56
62
|
this.token = properties.token!;
|
|
57
63
|
this.factory = VectorTileFactory.createFactory(properties)!;
|
|
64
|
+
this.releaseFetcher = new MapReleaseFetcher(this.token);
|
|
65
|
+
this.releaseDate = properties.releaseDate ? properties.releaseDate : false;
|
|
66
|
+
|
|
67
|
+
if (this.releaseDate) {
|
|
68
|
+
this.fetchAndSetAttribution(properties.provider!, properties.token!);
|
|
69
|
+
this.on("change", () => this.updateAttribution(properties.provider!));
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
private async fetchAndSetAttribution(provider: string, token: string) {
|
|
74
|
+
try {
|
|
75
|
+
const release = await this.releaseFetcher.getRelease(provider);
|
|
76
|
+
if (release) {
|
|
77
|
+
this.release = release;
|
|
78
|
+
this.setAttributions(`${ATTRIBUTION} ${this.release}`);
|
|
79
|
+
}
|
|
80
|
+
} catch (error) {
|
|
81
|
+
console.error("Error fetching release version: ", error);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
private async updateAttribution(provider: string) {
|
|
86
|
+
try {
|
|
87
|
+
const release = await this.releaseFetcher.getRelease(provider);
|
|
88
|
+
if (release && release !== this.release) {
|
|
89
|
+
this.release = release;
|
|
90
|
+
this.setAttributions(`${ATTRIBUTION} ${this.release}`);
|
|
91
|
+
}
|
|
92
|
+
} catch (error) {
|
|
93
|
+
console.error("Error updating attribution: ", error);
|
|
94
|
+
}
|
|
58
95
|
}
|
|
59
96
|
}
|
|
60
97
|
|
|
@@ -8,18 +8,18 @@ import {
|
|
|
8
8
|
PROVIDER_TRAFFIC,
|
|
9
9
|
} from "./constants.js";
|
|
10
10
|
|
|
11
|
+
import WebFont from "webfontloader";
|
|
11
12
|
import { RENDERING_CONFIG_DEFAULT } from "./rendering_config_default.js";
|
|
12
13
|
import { RENDERING_CONFIG_TRAFFIC } from "./rendering_config_traffic.js";
|
|
13
14
|
|
|
14
|
-
import WebFont from "webfontloader";
|
|
15
15
|
import {
|
|
16
16
|
Boundaries,
|
|
17
17
|
Coordinates,
|
|
18
|
-
RENDERING_CONFIG,
|
|
19
18
|
SuccessCallback,
|
|
20
19
|
MapTilesProperties,
|
|
21
20
|
} from "../types/interfaces.js";
|
|
22
21
|
|
|
22
|
+
import { RENDERING_CONFIG } from "../types/interfaces.js"
|
|
23
23
|
/**
|
|
24
24
|
* Creates a factory to create tiles from the provided URL templates.
|
|
25
25
|
*
|
|
@@ -95,7 +95,7 @@ class VectorTileFactory {
|
|
|
95
95
|
this._properties.traffic &&
|
|
96
96
|
!PROVIDER_TRAFFIC[this._properties.provider]
|
|
97
97
|
) {
|
|
98
|
-
throw new Error("There is
|
|
98
|
+
throw new Error("There is no traffic information for this provider");
|
|
99
99
|
}
|
|
100
100
|
|
|
101
101
|
// assert there is either a base map or traffic (or both)
|
|
@@ -145,17 +145,21 @@ class VectorTileFactory {
|
|
|
145
145
|
}
|
|
146
146
|
}
|
|
147
147
|
|
|
148
|
-
private static getRenderingConfig(properties:
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
148
|
+
private static getRenderingConfig(properties: {
|
|
149
|
+
provider?: string;
|
|
150
|
+
baseMap?: boolean;
|
|
151
|
+
traffic?: boolean;
|
|
152
|
+
timeout?: number;
|
|
153
|
+
parallelDownloads?: number;
|
|
154
|
+
detourProfile?: string;
|
|
155
|
+
renderingConfig?: RENDERING_CONFIG;
|
|
156
|
+
}) {
|
|
157
|
+
if (properties.renderingConfig) {
|
|
158
|
+
return properties.renderingConfig;
|
|
159
|
+
} else if (properties.baseMap) {
|
|
158
160
|
return RENDERING_CONFIG_DEFAULT;
|
|
161
|
+
} else {
|
|
162
|
+
return RENDERING_CONFIG_TRAFFIC;
|
|
159
163
|
}
|
|
160
164
|
}
|
|
161
165
|
|
|
@@ -15,11 +15,12 @@ import {
|
|
|
15
15
|
PolylineStyle,
|
|
16
16
|
PolylineTextStyle,
|
|
17
17
|
PositionXY,
|
|
18
|
-
RENDERING_CONFIG,
|
|
19
18
|
Renderer,
|
|
20
19
|
Vertex,
|
|
21
20
|
} from "../types/interfaces.js";
|
|
22
21
|
|
|
22
|
+
import { RENDERING_CONFIG} from "../types/interfaces.js"
|
|
23
|
+
|
|
23
24
|
class VectorTileRenderer {
|
|
24
25
|
private _styles: RENDERING_CONFIG;
|
|
25
26
|
private _images: { [key: string]: HTMLImageElement };
|
|
@@ -159,9 +160,11 @@ class VectorTileRenderer {
|
|
|
159
160
|
const geometry = layer[i].geometry;
|
|
160
161
|
|
|
161
162
|
// Look up the renderer for this kind of data
|
|
162
|
-
|
|
163
|
+
//@ts-ignore
|
|
164
|
+
const rendererName = this._styles.layers[kind];
|
|
163
165
|
const renderer = rendererName
|
|
164
|
-
?
|
|
166
|
+
? //@ts-ignore
|
|
167
|
+
this._styles?.renderers[rendererName]
|
|
165
168
|
: undefined;
|
|
166
169
|
|
|
167
170
|
if (renderer) {
|
|
@@ -426,7 +429,7 @@ class VectorTileRenderer {
|
|
|
426
429
|
texts?: { [key: string]: any }
|
|
427
430
|
): void {
|
|
428
431
|
if (style) {
|
|
429
|
-
|
|
432
|
+
let merged = { ...VectorTileRenderer.DEFAULT_STYLE.POLYGON, ...style };
|
|
430
433
|
|
|
431
434
|
for (var j = 0; j < coordinates.length; j++) {
|
|
432
435
|
var part = coordinates[j];
|
|
@@ -491,7 +494,7 @@ class VectorTileRenderer {
|
|
|
491
494
|
return;
|
|
492
495
|
}
|
|
493
496
|
|
|
494
|
-
merged = { ...VectorTileRenderer.DEFAULT_STYLE.TEXT, ...style };
|
|
497
|
+
let merged = { ...VectorTileRenderer.DEFAULT_STYLE.TEXT, ...style };
|
|
495
498
|
|
|
496
499
|
context.globalAlpha = merged.opacity;
|
|
497
500
|
context.font =
|
|
@@ -1123,8 +1126,11 @@ class VectorTileRenderer {
|
|
|
1123
1126
|
|
|
1124
1127
|
preloadImages(): void {
|
|
1125
1128
|
for (const name in this._styles?.renderers) {
|
|
1129
|
+
//@ts-ignore not allowing for bracket notation
|
|
1126
1130
|
for (let i = 0; i < this._styles.renderers[name].length; i++) {
|
|
1131
|
+
//@ts-ignore not allowing for bracket notation
|
|
1127
1132
|
for (const renderer in this._styles.renderers[name][i]) {
|
|
1133
|
+
//@ts-ignore not allowing for bracket notation
|
|
1128
1134
|
const config = this._styles.renderers[name][i][renderer];
|
|
1129
1135
|
|
|
1130
1136
|
if (config.url) {
|
|
@@ -1146,7 +1152,9 @@ class VectorTileRenderer {
|
|
|
1146
1152
|
let result = [];
|
|
1147
1153
|
|
|
1148
1154
|
for (let renderer in this._styles?.renderers) {
|
|
1155
|
+
//@ts-ignore not allowing for bracket notation
|
|
1149
1156
|
for (let i = 0; i < this._styles.renderers[renderer].length; i++) {
|
|
1157
|
+
//@ts-ignore not allowing for bracket notation
|
|
1150
1158
|
let text = this._styles.renderers[renderer][i].text;
|
|
1151
1159
|
if (text) {
|
|
1152
1160
|
let merged = { ...VectorTileRenderer.DEFAULT_STYLE.TEXT, ...text };
|