@maptrip/map-tiles 1.1.1 → 1.2.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.
Files changed (39) hide show
  1. package/README.md +2 -0
  2. package/dist/api-extensions/google/MapTripGoogleMapType.d.ts +28 -0
  3. package/dist/api-extensions/leaflet/MapTripLeafletGridLayer.d.ts +25 -0
  4. package/dist/api-extensions/openlayers/MapTripOpenLayersSource.d.ts +19 -0
  5. package/dist/core/CollisionDetector.d.ts +14 -0
  6. package/dist/core/VectorTileFactory.d.ts +64 -0
  7. package/dist/core/VectorTileLoader.d.ts +40 -0
  8. package/dist/core/VectorTileRenderer.d.ts +123 -0
  9. package/dist/core/constants.d.ts +10 -0
  10. package/dist/core/rendering_config_default.d.ts +658 -0
  11. package/dist/core/rendering_config_grayscale.d.ts +672 -0
  12. package/dist/core/rendering_config_traffic.d.ts +39 -0
  13. package/dist/map-tiles.d.ts +9 -0
  14. package/dist/map-tiles.js +22856 -9398
  15. package/dist/map-tiles.js.map +1 -0
  16. package/dist/types/interfaces.d.ts +134 -0
  17. package/lib/api-extensions/google/MapTripGoogleMapType.ts +43 -0
  18. package/lib/api-extensions/leaflet/MapTripLeafletGridLayer.ts +48 -0
  19. package/lib/api-extensions/openlayers/MapTripOpenLayersSource.ts +62 -0
  20. package/lib/core/CollisionDetector.ts +95 -0
  21. package/lib/core/VectorTileFactory.ts +331 -0
  22. package/lib/core/VectorTileLoader.ts +165 -0
  23. package/lib/core/VectorTileRenderer.ts +1220 -0
  24. package/lib/core/constants.ts +21 -0
  25. package/lib/core/rendering_config_grayscale.ts +1129 -0
  26. package/lib/types/interfaces.ts +147 -0
  27. package/package.json +22 -17
  28. package/lib/api-extensions/google/MapTripGoogleMapType.js +0 -25
  29. package/lib/api-extensions/leaflet/MapTripLeafletGridLayer.js +0 -24
  30. package/lib/api-extensions/openlayers/MapTripOpenLayersSource.js +0 -43
  31. package/lib/core/CollisionDetector.js +0 -65
  32. package/lib/core/VectorTileFactory.js +0 -245
  33. package/lib/core/VectorTileLoader.js +0 -132
  34. package/lib/core/VectorTileRenderer.js +0 -826
  35. package/lib/core/constants.js +0 -18
  36. package/lib/core/rendering_config_grayscale.js +0 -1107
  37. /package/lib/core/{rendering_config_default.js → rendering_config_default.ts} +0 -0
  38. /package/lib/core/{rendering_config_traffic.js → rendering_config_traffic.ts} +0 -0
  39. /package/lib/{main.js → main.ts} +0 -0
@@ -1,132 +0,0 @@
1
- class VectorTileLoader {
2
-
3
- constructor(properties) {
4
- this._properties = properties ? { ...VectorTileLoader.DEFAULT_PROPERTIES, ...properties } : VectorTileLoader.DEFAULT_PROPERTIES;
5
-
6
- this._tiles = [];
7
- this._numLoading = 0;
8
- }
9
-
10
- queue(tile, successCallback, errorCallback) {
11
- this._tiles.push({ tile: tile, successCallback: successCallback, errorCallback: errorCallback });
12
- }
13
-
14
- loadNext() {
15
- if (this._numLoading >= this._properties.parallelDownloads) {
16
- return;
17
- }
18
-
19
- if (this._tiles.length > 0) {
20
- // filter all files with wrong zoom levels
21
- let latestZoom = this._tiles[this._tiles.length - 1].tile.z;
22
- this._tiles = this._tiles.filter(function(tile) {
23
- return latestZoom === tile.tile.z;
24
- }.bind(this));
25
-
26
- // load the first tile
27
- var next = this._tiles.shift();
28
- if (!next) {
29
- return;
30
- }
31
-
32
- // load all URLs for that tile
33
- this.loadAllUrls(next, next.tile.urls);
34
- }
35
- }
36
-
37
- /**
38
- * Checks if a HTTP Request is successful
39
- *
40
- * @param {XMLHttpRequest} httpRequest
41
- *
42
- * @return {boolean}
43
- */
44
- isHttpRequestSuccessful(httpRequest) {
45
- return httpRequest.readyState === XMLHttpRequest.DONE && httpRequest.status === 200 && httpRequest.responseText.length > 0;
46
- }
47
-
48
- /**
49
- * Checks if a HTTP Request has failed (there was a timeout or the status code is an error)
50
- *
51
- * @param {XMLHttpRequest} httpRequest
52
- *
53
- * @return {boolean}
54
- */
55
- isHttpRequestFailed(httpRequest) {
56
- return this.isHttpRequestTimeout(httpRequest) || httpRequest.readyState === XMLHttpRequest.DONE && httpRequest.status >= 400;
57
- }
58
-
59
- /**
60
- * Checks if a HTTP Request has timed out
61
- *
62
- * @param {XMLHttpRequest} httpRequest
63
- *
64
- * @return {boolean}
65
- */
66
- isHttpRequestTimeout(httpRequest) {
67
- return httpRequest.readyState === XMLHttpRequest.DONE && httpRequest.status === 0;
68
- }
69
-
70
- loadAllUrls(tile, urls) {
71
- var url = urls.pop();
72
-
73
- var xhr = new XMLHttpRequest();
74
- xhr.onreadystatechange = function() {
75
- if (xhr.readyState !== XMLHttpRequest.DONE) {
76
- return;
77
- }
78
-
79
- if (this.isHttpRequestSuccessful(xhr)) {
80
- var json = JSON.parse(xhr.responseText); // XXX bei Fehlern des Data Servers kommt hier kein JSON sondern XML!
81
-
82
- if (!tile.json) {
83
- tile.json = json;
84
- }
85
- else {
86
- tile.json.features = tile.json.features.concat(json.features);
87
- }
88
-
89
- if (urls.length === 0) {
90
- // no more URLs left, so call the callback
91
- tile.successCallback(tile.json);
92
- }
93
- else {
94
- // load the remaining URLs
95
- this.loadAllUrls(tile, urls);
96
- }
97
- }
98
-
99
- if (this.isHttpRequestFailed(xhr) || this.isHttpRequestTimeout(xhr)) {
100
- tile.errorCallback(xhr.responseText);
101
- }
102
-
103
- this._numLoading--;
104
- this.loadNext();
105
- }.bind(this);
106
-
107
- xhr.ontimeout = function() {
108
- tile.errorCallback(xhr.responseText);
109
- this._numLoading--;
110
- this.loadNext();
111
- }.bind(this);
112
-
113
- if (this._properties.detourProfile) {
114
- url += '&SP_USE=' + encodeURIComponent(this._properties.detourProfile);
115
- }
116
-
117
- xhr.open('GET', url, true);
118
- xhr.setRequestHeader('Authorization', `Bearer ${tile.tile.token}`);
119
- xhr.timeout = this._properties.timeout;
120
- xhr.send(null);
121
-
122
- this._numLoading++;
123
- }
124
-
125
- static DEFAULT_PROPERTIES = {
126
- detourProfile: null,
127
- timeout: 5000,
128
- parallelDownloads: 12
129
- };
130
- }
131
-
132
- export { VectorTileLoader };