@maptrip/map-tiles 1.2.1 → 1.3.1
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/leaflet/MapTripLeafletGridLayer.d.ts +11 -0
- package/dist/api-extensions/openlayers/MapTripOpenLayersSource.d.ts +7 -0
- package/dist/map-tiles.d.ts +2 -1
- package/dist/map-tiles.js +166 -5
- package/dist/map-tiles.js.map +1 -1
- package/dist/types/interfaces.d.ts +1 -0
- package/dist/util/MapReleaseFetcher.d.ts +10 -0
- package/lib/api-extensions/leaflet/MapTripLeafletGridLayer.ts +94 -3
- package/lib/api-extensions/openlayers/MapTripOpenLayersSource.ts +37 -1
- package/lib/core/VectorTileFactory.ts +1 -1
- package/lib/core/constants.ts +3 -2
- package/lib/main.ts +3 -0
- package/lib/types/interfaces.ts +1 -0
- package/lib/util/MapReleaseFetcher.ts +66 -0
- package/package.json +3 -2
package/README.md
CHANGED
|
@@ -68,6 +68,7 @@ L.map("map", {
|
|
|
68
68
|
|
|
69
69
|
- `token`: A valid and non-expired token for your account, see section _Authorization_ (**required**)
|
|
70
70
|
- `attribution`: The copyright notes to show in the map
|
|
71
|
+
- `releaseDate`: Boolean value stating whether to append the map release data to the attribution; default is false.
|
|
71
72
|
- `minZoom`: The minimum zoom level for the map (must not be smaller than 2)
|
|
72
73
|
- `maxZoom`: The maximum zoom level for the map (must not be larger than 18)
|
|
73
74
|
|
|
@@ -108,6 +109,8 @@ new Map({
|
|
|
108
109
|
`MapTripOpenLayersSource` can be configured with all properties listed in the section _Properties_, and also with these:
|
|
109
110
|
|
|
110
111
|
- `token`: A valid and non-expired token for your account, see section _Authorization_ (**required**)
|
|
112
|
+
- `attribution`: The copyright notes to show in the map
|
|
113
|
+
- `releaseDate`: Boolean value stating whether to append the map release data to the attribution; default is false.
|
|
111
114
|
|
|
112
115
|
### Google Maps
|
|
113
116
|
|
|
@@ -274,6 +277,8 @@ To use them, you mapping API has to be able to use both base layers and overlays
|
|
|
274
277
|
|
|
275
278
|
## History
|
|
276
279
|
|
|
280
|
+
- 1.3.1: Updated all all providers to use the latest build of the project
|
|
281
|
+
- 1.3.0: Added map release data for Leaflet and OpenLayers map attributions
|
|
277
282
|
- 1.2.1: Fixed a bug in MapTripLeafletGridLayer type implementation
|
|
278
283
|
- 1.2.0: Added TypeScript declaration file
|
|
279
284
|
- 1.1.1: Added rendering config for foot_path layer
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { PointXY, RENDERING_CONFIG } from '../../types/interfaces.js';
|
|
2
|
+
import { MapReleaseFetcher } from '../../util/MapReleaseFetcher.js';
|
|
2
3
|
import { VectorTileFactory } from '../../core/VectorTileFactory.js';
|
|
3
4
|
import { default as L } from 'leaflet';
|
|
4
5
|
|
|
@@ -7,6 +8,11 @@ declare class MapTripLeafletGridLayer extends L.GridLayer {
|
|
|
7
8
|
MAX_ZOOM: number;
|
|
8
9
|
token: string;
|
|
9
10
|
factory: VectorTileFactory;
|
|
11
|
+
releaseFetcher: MapReleaseFetcher;
|
|
12
|
+
provider: string;
|
|
13
|
+
attribution: string;
|
|
14
|
+
release: string;
|
|
15
|
+
releaseDate: boolean;
|
|
10
16
|
constructor(options: {
|
|
11
17
|
provider?: string;
|
|
12
18
|
baseMap?: boolean;
|
|
@@ -19,7 +25,12 @@ declare class MapTripLeafletGridLayer extends L.GridLayer {
|
|
|
19
25
|
attribution?: string;
|
|
20
26
|
minZoom?: number;
|
|
21
27
|
maxZoom?: number;
|
|
28
|
+
releaseDate?: boolean;
|
|
22
29
|
});
|
|
23
30
|
createTile(coords: PointXY): HTMLCanvasElement;
|
|
31
|
+
private initializeAttribution;
|
|
32
|
+
private setRelease;
|
|
33
|
+
private setAttribution;
|
|
34
|
+
private onBaseLayerChange;
|
|
24
35
|
}
|
|
25
36
|
export { MapTripLeafletGridLayer };
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { MapReleaseFetcher } from '../../main.js';
|
|
1
2
|
import { RENDERING_CONFIG } from '../../types/interfaces.js';
|
|
2
3
|
import { VectorTileFactory } from '../../core/VectorTileFactory.js';
|
|
3
4
|
import { default as XYZ } from 'ol/source/XYZ.js';
|
|
@@ -5,6 +6,9 @@ import { default as XYZ } from 'ol/source/XYZ.js';
|
|
|
5
6
|
declare class MapTripOpenLayersSource extends XYZ {
|
|
6
7
|
token: string;
|
|
7
8
|
factory: VectorTileFactory;
|
|
9
|
+
release: string;
|
|
10
|
+
releaseFetcher: MapReleaseFetcher;
|
|
11
|
+
releaseDate: boolean;
|
|
8
12
|
constructor(properties: {
|
|
9
13
|
provider?: string;
|
|
10
14
|
baseMap?: boolean;
|
|
@@ -14,6 +18,9 @@ declare class MapTripOpenLayersSource extends XYZ {
|
|
|
14
18
|
detourProfile?: string;
|
|
15
19
|
renderingConfig?: RENDERING_CONFIG;
|
|
16
20
|
token?: string;
|
|
21
|
+
releaseDate?: boolean;
|
|
17
22
|
});
|
|
23
|
+
private fetchAndSetAttribution;
|
|
24
|
+
private updateAttribution;
|
|
18
25
|
}
|
|
19
26
|
export { MapTripOpenLayersSource };
|
package/dist/map-tiles.d.ts
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { MapTripOpenLayersSource } from './api-extensions/openlayers/MapTripOpenLayersSource.js';
|
|
2
2
|
import { MapTripLeafletGridLayer } from './api-extensions/leaflet/MapTripLeafletGridLayer.js';
|
|
3
3
|
import { MapTripGoogleMapType } from './api-extensions/google/MapTripGoogleMapType.js';
|
|
4
|
+
import { MapReleaseFetcher } from './util/MapReleaseFetcher.js';
|
|
4
5
|
import { RENDERING_CONFIG_TRAFFIC } from './core/rendering_config_traffic.js';
|
|
5
6
|
import { RENDERING_CONFIG_GRAYSCALE } from './core/rendering_config_grayscale.js';
|
|
6
7
|
import { RENDERING_CONFIG_DEFAULT } from './core/rendering_config_default.js';
|
|
7
8
|
import { VectorTileFactory } from './core/VectorTileFactory.js';
|
|
8
9
|
|
|
9
|
-
export { VectorTileFactory, RENDERING_CONFIG_DEFAULT, RENDERING_CONFIG_GRAYSCALE, RENDERING_CONFIG_TRAFFIC, MapTripLeafletGridLayer, MapTripGoogleMapType, MapTripOpenLayersSource, };
|
|
10
|
+
export { VectorTileFactory, RENDERING_CONFIG_DEFAULT, RENDERING_CONFIG_GRAYSCALE, RENDERING_CONFIG_TRAFFIC, MapReleaseFetcher, MapTripLeafletGridLayer, MapTripGoogleMapType, MapTripOpenLayersSource, };
|
package/dist/map-tiles.js
CHANGED
|
@@ -1919,8 +1919,8 @@ class VectorTileRenderer {
|
|
|
1919
1919
|
const URL_TEMPLATE = "https://v${index}.maptrip.de/?tilex=${x}&tiley=${y}&acao=true&context=tomtom${z}&project=${project}&projection=wgs84";
|
|
1920
1920
|
const PROVIDER_PROJECTS = {
|
|
1921
1921
|
tomtom: "TomTom_latest",
|
|
1922
|
-
here: "
|
|
1923
|
-
openstreetmap: "
|
|
1922
|
+
here: "HERE_latest",
|
|
1923
|
+
openstreetmap: "OSM_latest"
|
|
1924
1924
|
};
|
|
1925
1925
|
const PROVIDER_TRAFFIC = {
|
|
1926
1926
|
tomtom: "https://v0.maptrip.de/tiles?project=TrafficMobileTomTom_EUROPE&tilex=${x}&tiley=${y}&acao=true&context=traffic${z}&projection=wgs84",
|
|
@@ -3248,7 +3248,7 @@ class VectorTileFactory {
|
|
|
3248
3248
|
throw new Error("Unknown provider");
|
|
3249
3249
|
}
|
|
3250
3250
|
if (this._properties.traffic && !PROVIDER_TRAFFIC[this._properties.provider]) {
|
|
3251
|
-
throw new Error("There is
|
|
3251
|
+
throw new Error("There is no traffic information for this provider");
|
|
3252
3252
|
}
|
|
3253
3253
|
if (!this._properties.baseMap && !this._properties.traffic) {
|
|
3254
3254
|
throw new Error(
|
|
@@ -4548,6 +4548,65 @@ const RENDERING_CONFIG_GRAYSCALE = {
|
|
|
4548
4548
|
}
|
|
4549
4549
|
};
|
|
4550
4550
|
|
|
4551
|
+
class MapReleaseFetcher {
|
|
4552
|
+
_token;
|
|
4553
|
+
_tomtom = null;
|
|
4554
|
+
_osm = null;
|
|
4555
|
+
_here = null;
|
|
4556
|
+
constructor(token) {
|
|
4557
|
+
this._token = token;
|
|
4558
|
+
}
|
|
4559
|
+
async getRelease(provider) {
|
|
4560
|
+
if (provider === "tomtom") {
|
|
4561
|
+
if (!this._tomtom) {
|
|
4562
|
+
const url = "https://v1.maptrip.de/?CMD=GETFILE&PROJECT=TomTom_latest&RELATIVEPATH=/data/mapset/data/routing_geocoder/admin.bin&acao=true";
|
|
4563
|
+
this._tomtom = this.fetchAndExtractRelease(url);
|
|
4564
|
+
}
|
|
4565
|
+
return this._tomtom;
|
|
4566
|
+
} else if (provider === "here") {
|
|
4567
|
+
if (!this._here) {
|
|
4568
|
+
const url = "https://v1.maptrip.de/?CMD=GETFILE&PROJECT=HERE_latest&RELATIVEPATH=/data/mapset/data/routing_geocoder/admin.bin&acao=true";
|
|
4569
|
+
this._here = this.fetchAndExtractRelease(url);
|
|
4570
|
+
}
|
|
4571
|
+
return this._here;
|
|
4572
|
+
} else if (provider === "openstreetmap") {
|
|
4573
|
+
if (!this._osm) {
|
|
4574
|
+
const url = "https://v1.maptrip.de/?CMD=GETFILE&PROJECT=OSM_latest&RELATIVEPATH=/data/mapset/data/routing_geocoder/admin.bin&acao=true";
|
|
4575
|
+
this._osm = this.fetchAndExtractRelease(url);
|
|
4576
|
+
}
|
|
4577
|
+
return this._osm;
|
|
4578
|
+
}
|
|
4579
|
+
}
|
|
4580
|
+
async fetchAndExtractRelease(url) {
|
|
4581
|
+
return new Promise((resolve, reject) => {
|
|
4582
|
+
var xhr = new XMLHttpRequest();
|
|
4583
|
+
xhr.onreadystatechange = () => {
|
|
4584
|
+
if (xhr.readyState !== XMLHttpRequest.DONE)
|
|
4585
|
+
return;
|
|
4586
|
+
if (xhr.status === 200) {
|
|
4587
|
+
const text = new TextDecoder("latin1").decode(xhr.response);
|
|
4588
|
+
const textString = this.extractTargetString(text);
|
|
4589
|
+
const formattedString = textString.split("Q").join(" Q");
|
|
4590
|
+
const release = ` ${formattedString}`;
|
|
4591
|
+
resolve(release);
|
|
4592
|
+
} else {
|
|
4593
|
+
reject(`Error fetching: ${xhr.status}`);
|
|
4594
|
+
}
|
|
4595
|
+
};
|
|
4596
|
+
xhr.open("GET", url, true);
|
|
4597
|
+
xhr.setRequestHeader("Authorization", `Bearer ${this._token}`);
|
|
4598
|
+
xhr.setRequestHeader("Accept", "*/*");
|
|
4599
|
+
xhr.setRequestHeader("Content-Type", "application/octet-stream");
|
|
4600
|
+
xhr.responseType = "arraybuffer";
|
|
4601
|
+
xhr.send(null);
|
|
4602
|
+
});
|
|
4603
|
+
}
|
|
4604
|
+
extractTargetString(text) {
|
|
4605
|
+
const match = text.match(/2\d{3}Q[1-4]/);
|
|
4606
|
+
return match ? match[0] : null;
|
|
4607
|
+
}
|
|
4608
|
+
}
|
|
4609
|
+
|
|
4551
4610
|
class MapTripGoogleMapType {
|
|
4552
4611
|
tileSize = new google.maps.Size(256, 256);
|
|
4553
4612
|
alt = null;
|
|
@@ -19092,10 +19151,31 @@ class MapTripLeafletGridLayer extends L$1.GridLayer {
|
|
|
19092
19151
|
MAX_ZOOM = MAX_ZOOM;
|
|
19093
19152
|
token;
|
|
19094
19153
|
factory;
|
|
19154
|
+
releaseFetcher;
|
|
19155
|
+
provider;
|
|
19156
|
+
attribution;
|
|
19157
|
+
release;
|
|
19158
|
+
releaseDate;
|
|
19095
19159
|
constructor(options) {
|
|
19096
19160
|
super(options);
|
|
19097
19161
|
this.token = options.token;
|
|
19162
|
+
this.provider = options.provider ? options.provider?.toLowerCase() : "openstreetmap";
|
|
19098
19163
|
this.options.attribution = options.attribution ? options.attribution : ATTRIBUTION;
|
|
19164
|
+
this.releaseFetcher = new MapReleaseFetcher(this.token);
|
|
19165
|
+
this.release = "";
|
|
19166
|
+
this.attribution = "";
|
|
19167
|
+
this.releaseDate = options.releaseDate ? options.releaseDate : false;
|
|
19168
|
+
if (this.releaseDate) {
|
|
19169
|
+
this.initializeAttribution();
|
|
19170
|
+
this.on("add", () => {
|
|
19171
|
+
if (this._map) {
|
|
19172
|
+
this._map.on(
|
|
19173
|
+
"baselayerchange",
|
|
19174
|
+
(event) => this.onBaseLayerChange(event)
|
|
19175
|
+
);
|
|
19176
|
+
}
|
|
19177
|
+
});
|
|
19178
|
+
}
|
|
19099
19179
|
this.options.minZoom = options.minZoom ? Math.max(this.MIN_ZOOM, options.minZoom) : this.MIN_ZOOM;
|
|
19100
19180
|
this.options.maxZoom = options.maxZoom ? Math.min(this.MAX_ZOOM, options.maxZoom) : this.MAX_ZOOM;
|
|
19101
19181
|
this.factory = VectorTileFactory.createFactory(options);
|
|
@@ -19103,6 +19183,57 @@ class MapTripLeafletGridLayer extends L$1.GridLayer {
|
|
|
19103
19183
|
createTile(coords) {
|
|
19104
19184
|
return this.factory.getJsonTile(coords.z, coords.x, coords.y, this.token);
|
|
19105
19185
|
}
|
|
19186
|
+
async initializeAttribution() {
|
|
19187
|
+
await this.setRelease();
|
|
19188
|
+
await this.setAttribution();
|
|
19189
|
+
}
|
|
19190
|
+
// Set an original release
|
|
19191
|
+
async setRelease() {
|
|
19192
|
+
const release = await this.releaseFetcher.getRelease(this.provider);
|
|
19193
|
+
if (release) {
|
|
19194
|
+
this.release = release;
|
|
19195
|
+
}
|
|
19196
|
+
}
|
|
19197
|
+
async setAttribution() {
|
|
19198
|
+
if (!this._map)
|
|
19199
|
+
return;
|
|
19200
|
+
try {
|
|
19201
|
+
const newRelease = await this.releaseFetcher.getRelease(this.provider);
|
|
19202
|
+
if (newRelease && newRelease !== this.release) {
|
|
19203
|
+
this.release = newRelease;
|
|
19204
|
+
}
|
|
19205
|
+
this._map.attributionControl.removeAttribution(this.options.attribution);
|
|
19206
|
+
this.attribution = `${this.options.attribution} ${this.release}`;
|
|
19207
|
+
this._map.attributionControl.addAttribution(this.attribution);
|
|
19208
|
+
const map = this._map;
|
|
19209
|
+
this._map.addEventListener("baselayerchange", () => {
|
|
19210
|
+
map.attributionControl.removeAttribution(this.attribution);
|
|
19211
|
+
});
|
|
19212
|
+
} catch (error) {
|
|
19213
|
+
console.error("Error fetching release version: ", error);
|
|
19214
|
+
}
|
|
19215
|
+
}
|
|
19216
|
+
async onBaseLayerChange(event) {
|
|
19217
|
+
if (!this._map) {
|
|
19218
|
+
return;
|
|
19219
|
+
}
|
|
19220
|
+
this._map.attributionControl.removeAttribution(this.attribution);
|
|
19221
|
+
const eventProvider = event.layer.options.provider;
|
|
19222
|
+
let newProvider;
|
|
19223
|
+
if (eventProvider) {
|
|
19224
|
+
if (eventProvider.toLowerCase() === "opensreetmap") {
|
|
19225
|
+
newProvider = "openstreetmap";
|
|
19226
|
+
} else if (eventProvider.toLowerCase() === "tomtom") {
|
|
19227
|
+
newProvider = "tomtom";
|
|
19228
|
+
} else if (eventProvider.toLowerCase() === "here") {
|
|
19229
|
+
newProvider = "here";
|
|
19230
|
+
} else {
|
|
19231
|
+
newProvider = "openstreetmap";
|
|
19232
|
+
}
|
|
19233
|
+
this.provider = newProvider;
|
|
19234
|
+
await this.setAttribution();
|
|
19235
|
+
}
|
|
19236
|
+
}
|
|
19106
19237
|
}
|
|
19107
19238
|
|
|
19108
19239
|
/**
|
|
@@ -26999,8 +27130,10 @@ const XYZ$1 = XYZ;
|
|
|
26999
27130
|
class MapTripOpenLayersSource extends XYZ$1 {
|
|
27000
27131
|
token;
|
|
27001
27132
|
factory;
|
|
27133
|
+
release = "";
|
|
27134
|
+
releaseFetcher;
|
|
27135
|
+
releaseDate;
|
|
27002
27136
|
constructor(properties) {
|
|
27003
|
-
super();
|
|
27004
27137
|
const options = {};
|
|
27005
27138
|
const projection = "EPSG:3857";
|
|
27006
27139
|
const tileGrid = createXYZ({
|
|
@@ -27034,8 +27167,36 @@ class MapTripOpenLayersSource extends XYZ$1 {
|
|
|
27034
27167
|
});
|
|
27035
27168
|
this.token = properties.token;
|
|
27036
27169
|
this.factory = VectorTileFactory.createFactory(properties);
|
|
27170
|
+
this.releaseFetcher = new MapReleaseFetcher(this.token);
|
|
27171
|
+
this.releaseDate = properties.releaseDate ? properties.releaseDate : false;
|
|
27172
|
+
if (this.releaseDate) {
|
|
27173
|
+
this.fetchAndSetAttribution(properties.provider, properties.token);
|
|
27174
|
+
this.on("change", () => this.updateAttribution(properties.provider));
|
|
27175
|
+
}
|
|
27176
|
+
}
|
|
27177
|
+
async fetchAndSetAttribution(provider, token) {
|
|
27178
|
+
try {
|
|
27179
|
+
const release = await this.releaseFetcher.getRelease(provider);
|
|
27180
|
+
if (release) {
|
|
27181
|
+
this.release = release;
|
|
27182
|
+
this.setAttributions(`${ATTRIBUTION} ${this.release}`);
|
|
27183
|
+
}
|
|
27184
|
+
} catch (error) {
|
|
27185
|
+
console.error("Error fetching release version: ", error);
|
|
27186
|
+
}
|
|
27187
|
+
}
|
|
27188
|
+
async updateAttribution(provider) {
|
|
27189
|
+
try {
|
|
27190
|
+
const release = await this.releaseFetcher.getRelease(provider);
|
|
27191
|
+
if (release && release !== this.release) {
|
|
27192
|
+
this.release = release;
|
|
27193
|
+
this.setAttributions(`${ATTRIBUTION} ${this.release}`);
|
|
27194
|
+
}
|
|
27195
|
+
} catch (error) {
|
|
27196
|
+
console.error("Error updating attribution: ", error);
|
|
27197
|
+
}
|
|
27037
27198
|
}
|
|
27038
27199
|
}
|
|
27039
27200
|
|
|
27040
|
-
export { MapTripGoogleMapType, MapTripLeafletGridLayer, MapTripOpenLayersSource, RENDERING_CONFIG_DEFAULT, RENDERING_CONFIG_GRAYSCALE, RENDERING_CONFIG_TRAFFIC, VectorTileFactory };
|
|
27201
|
+
export { MapReleaseFetcher, MapTripGoogleMapType, MapTripLeafletGridLayer, MapTripOpenLayersSource, RENDERING_CONFIG_DEFAULT, RENDERING_CONFIG_GRAYSCALE, RENDERING_CONFIG_TRAFFIC, VectorTileFactory };
|
|
27041
27202
|
//# sourceMappingURL=map-tiles.js.map
|