@maptrip/map-tiles 1.1.0 → 1.2.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.
Files changed (39) hide show
  1. package/README.md +5 -3
  2. package/dist/api-extensions/google/MapTripGoogleMapType.d.ts +28 -0
  3. package/dist/api-extensions/leaflet/MapTripLeafletGridLayer.d.ts +4 -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 +638 -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 +23647 -10188
  15. package/dist/map-tiles.js.map +1 -0
  16. package/dist/types/interfaces.d.ts +135 -0
  17. package/lib/api-extensions/google/MapTripGoogleMapType.ts +40 -0
  18. package/lib/api-extensions/leaflet/MapTripLeafletGridLayer.ts +44 -0
  19. package/lib/api-extensions/openlayers/MapTripOpenLayersSource.ts +61 -0
  20. package/lib/core/CollisionDetector.ts +95 -0
  21. package/lib/core/VectorTileFactory.ts +327 -0
  22. package/lib/core/VectorTileLoader.ts +165 -0
  23. package/lib/core/VectorTileRenderer.ts +1212 -0
  24. package/lib/core/constants.ts +21 -0
  25. package/lib/core/rendering_config_default.ts +1131 -0
  26. package/lib/{main.js → main.ts} +2 -0
  27. package/lib/types/interfaces.ts +147 -0
  28. package/package.json +19 -14
  29. package/lib/api-extensions/google/MapTripGoogleMapType.js +0 -25
  30. package/lib/api-extensions/leaflet/MapTripLeafletGridLayer.js +0 -24
  31. package/lib/api-extensions/openlayers/MapTripOpenLayersSource.js +0 -43
  32. package/lib/core/CollisionDetector.js +0 -65
  33. package/lib/core/VectorTileFactory.js +0 -245
  34. package/lib/core/VectorTileLoader.js +0 -132
  35. package/lib/core/VectorTileRenderer.js +0 -826
  36. package/lib/core/constants.js +0 -18
  37. package/lib/core/rendering_config_default.js +0 -1107
  38. /package/lib/core/{rendering_config_grayscale.js → rendering_config_grayscale.ts} +0 -0
  39. /package/lib/core/{rendering_config_traffic.js → rendering_config_traffic.ts} +0 -0
package/README.md CHANGED
@@ -49,8 +49,8 @@ you create an instance of `MapTripLeafletGridLayer` and add it to the layers of
49
49
  ```js
50
50
  import { MapTripLeafletGridLayer } from "@maptrip/map-tiles";
51
51
 
52
- import L from 'leaflet';
53
- import 'leaflet/dist/leaflet.css';
52
+ import L from "leaflet";
53
+ import "leaflet/dist/leaflet.css";
54
54
 
55
55
  const layer = new MapTripLeafletGridLayer({
56
56
  provider: "TomTom",
@@ -237,7 +237,7 @@ You can specify a third parameter with properties when creating the factory. The
237
237
  | traffic | Add traffic flows to the map tiles (only available for TomTom and HERE maps) | false |
238
238
  | timeout | Load timeout for tiles in milliseconds. Increase this if you have a very slow internet connection | 5000 |
239
239
  | parallelDownloads | The number of tiles that are loaded in parallel | 12 |
240
- | detourProfile | The name of a MapTrip Detour Profile, see *MapTrip Detour* | |
240
+ | detourProfile | The name of a MapTrip Detour Profile, see _MapTrip Detour_ | |
241
241
  | renderingConfig | Set a custom rendering configuration to customize layers, colors, line widths etc. | RENDERING_CONFIG_DEFAULT |
242
242
 
243
243
  This factory initializes a factory with TomTom data and traffic flows:
@@ -274,5 +274,7 @@ To use them, you mapping API has to be able to use both base layers and overlays
274
274
 
275
275
  ## History
276
276
 
277
+ - 1.2.0: Added TypeScript declaration file
278
+ - 1.1.1: Added rendering config for foot_path layer
277
279
  - 1.1.0: Added MapTrip detour profiles
278
280
  - 1.0.8: First public version
@@ -0,0 +1,28 @@
1
+ import { PointXY, RENDERING_CONFIG } from '../../types/interfaces.js';
2
+ import { VectorTileFactory } from '../../core/VectorTileFactory.js';
3
+
4
+ declare class MapTripGoogleMapType {
5
+ tileSize: google.maps.Size;
6
+ alt: null;
7
+ maxZoom: number;
8
+ minZoom: number;
9
+ projection: null;
10
+ radius: number;
11
+ name: string;
12
+ token: string;
13
+ factory: VectorTileFactory;
14
+ constructor(properties: {
15
+ provider?: string;
16
+ baseMap?: boolean;
17
+ traffic?: boolean;
18
+ timeout?: number;
19
+ parallelDownloads?: number;
20
+ detourProfile?: string;
21
+ renderingConfig?: RENDERING_CONFIG;
22
+ token?: string;
23
+ name?: string;
24
+ });
25
+ getTile(coord: PointXY, zoom: number): HTMLCanvasElement;
26
+ releaseTile(): void;
27
+ }
28
+ export { MapTripGoogleMapType };
@@ -0,0 +1,4 @@
1
+ import { default as L } from 'leaflet';
2
+
3
+ declare const MapTripLeafletGridLayer: (new (...args: any[]) => any) & typeof L.Class;
4
+ export { MapTripLeafletGridLayer };
@@ -0,0 +1,19 @@
1
+ import { RENDERING_CONFIG } from '../../types/interfaces.js';
2
+ import { VectorTileFactory } from '../../core/VectorTileFactory.js';
3
+ import { default as XYZ } from 'ol/source/XYZ.js';
4
+
5
+ declare class MapTripOpenLayersSource extends XYZ {
6
+ token: string;
7
+ factory: VectorTileFactory;
8
+ constructor(properties: {
9
+ provider?: string;
10
+ baseMap?: boolean;
11
+ traffic?: boolean;
12
+ timeout?: number;
13
+ parallelDownloads?: number;
14
+ detourProfile?: string;
15
+ renderingConfig?: RENDERING_CONFIG;
16
+ token?: string;
17
+ });
18
+ }
19
+ export { MapTripOpenLayersSource };
@@ -0,0 +1,14 @@
1
+ import { PositionXY } from '../types/interfaces.js';
2
+
3
+ declare class CollisionDetector {
4
+ private _tree;
5
+ constructor();
6
+ insert(x: number, y: number, w: number, h: number): void;
7
+ insertPolylineText(context: CanvasRenderingContext2D, text: string, position: PositionXY): void;
8
+ isCollision(x: number, y: number, w: number, h: number): boolean;
9
+ isPolylineTextCollision(context: CanvasRenderingContext2D, text: string, position: PositionXY): boolean;
10
+ getCollisionParams(context: CanvasRenderingContext2D, text: string, position: PositionXY, widthUsed: number): {
11
+ [key: string]: number;
12
+ };
13
+ }
14
+ export { CollisionDetector };
@@ -0,0 +1,64 @@
1
+ import { RENDERING_CONFIG, SuccessCallback, MapTilesProperties } from '../types/interfaces.js';
2
+
3
+ /**
4
+ * Creates a factory to create tiles from the provided URL templates.
5
+ *
6
+ * The templates must have variables ${x}, ${y} and ${z} for the tile index.
7
+ * When multiple URLs are specified, they are used round robin.
8
+ */
9
+ declare class VectorTileFactory {
10
+ private _layers;
11
+ private _tileLoader;
12
+ private _renderer;
13
+ private _urls;
14
+ private _additionalUrls;
15
+ static _fonts: string | undefined;
16
+ static _properties: typeof VectorTileFactory.DEFAULT_PROPERTIES;
17
+ constructor(urls: string[], additionalUrls: string[], renderingConfig: RENDERING_CONFIG, properties: MapTilesProperties);
18
+ static createFactory(properties: {
19
+ provider?: string;
20
+ baseMap?: boolean;
21
+ traffic?: boolean;
22
+ timeout?: number;
23
+ parallelDownloads?: number;
24
+ detourProfile?: string;
25
+ renderingConfig?: RENDERING_CONFIG;
26
+ }): VectorTileFactory;
27
+ private static getUrlTemplatesForBaseLayer;
28
+ private static getUrlTemplatesForTrafficLayer;
29
+ private static getRenderingConfig;
30
+ getJsonTile(z: number, x: number, y: number, token: string, callback?: SuccessCallback): HTMLCanvasElement;
31
+ /**
32
+ * @private
33
+ */
34
+ private resolveTileUrl;
35
+ /**
36
+ * @private
37
+ */
38
+ private tileIndexToLatLong;
39
+ /**
40
+ * @private
41
+ */
42
+ private getTileBoundaries;
43
+ /**
44
+ * @private
45
+ */
46
+ private drawTile;
47
+ /**
48
+ * Draws an error message on the tile.
49
+ * @private
50
+ *
51
+ * @param canvas
52
+ */
53
+ private drawErroredTile;
54
+ /**
55
+ * @private
56
+ */
57
+ private getFeatures;
58
+ static DEFAULT_PROPERTIES: {
59
+ provider: string;
60
+ baseMap: boolean;
61
+ traffic: boolean;
62
+ };
63
+ }
64
+ export { VectorTileFactory };
@@ -0,0 +1,40 @@
1
+ import { SuccessCallback, TileQueueItem, Tile, MapTilesProperties } from '../types/interfaces.js';
2
+
3
+ declare class VectorTileLoader {
4
+ private _properties;
5
+ private _tiles;
6
+ private _numLoading;
7
+ constructor(properties: MapTilesProperties);
8
+ queue(tile: Tile, successCallback: SuccessCallback, errorCallback: ErrorCallback): void;
9
+ loadNext(): void;
10
+ /**
11
+ * Checks if a HTTP Request is successful
12
+ *
13
+ * @param {XMLHttpRequest} httpRequest
14
+ *
15
+ * @return {boolean}
16
+ */
17
+ isHttpRequestSuccessful(httpRequest: XMLHttpRequest): boolean;
18
+ /**
19
+ * Checks if a HTTP Request has failed (there was a timeout or the status code is an error)
20
+ *
21
+ * @param {XMLHttpRequest} httpRequest
22
+ *
23
+ * @return {boolean}
24
+ */
25
+ isHttpRequestFailed(httpRequest: XMLHttpRequest): boolean;
26
+ /**
27
+ * Checks if a HTTP Request has timed out
28
+ *
29
+ * @param {XMLHttpRequest} httpRequest
30
+ *
31
+ * @return {boolean}
32
+ */
33
+ isHttpRequestTimeout(httpRequest: XMLHttpRequest): boolean;
34
+ loadAllUrls(tile: TileQueueItem, urls: string[]): void;
35
+ static DEFAULT_PROPERTIES: {
36
+ timeout: number;
37
+ parallelDownloads: number;
38
+ };
39
+ }
40
+ export { VectorTileLoader };
@@ -0,0 +1,123 @@
1
+ import { Boundaries, PointXY, PolygonStyle, PolylineStyle, PolylineTextStyle, PositionXY, RENDERING_CONFIG, Renderer, Vertex } from '../types/interfaces.js';
2
+ import { CollisionDetector } from './CollisionDetector.js';
3
+ import { GeoJsonProperties } from 'geojson';
4
+
5
+ declare class VectorTileRenderer {
6
+ private _styles;
7
+ private _images;
8
+ constructor(styles: RENDERING_CONFIG);
9
+ drawTile(layer: GeoJSON.Feature<GeoJSON.Geometry, GeoJSON.GeoJsonProperties>[], z: number, boundaries: Boundaries, context: CanvasRenderingContext2D): void;
10
+ drawPolylineLayers(lines: GeoJSON.Feature<GeoJSON.Geometry, GeoJSON.GeoJsonProperties>[], z: number, boundaries: Boundaries, context: CanvasRenderingContext2D, phase: string, collisions: CollisionDetector): void;
11
+ drawErroredTile(canvas: HTMLCanvasElement): void;
12
+ drawTilePhase(layer: GeoJSON.Feature<GeoJSON.Geometry, GeoJSON.GeoJsonProperties>[], z: number, boundaries: Boundaries, context: CanvasRenderingContext2D, phase: string, collisions: CollisionDetector): void;
13
+ /**
14
+ * @private
15
+ */
16
+ getBackgroundColor(z: number): string;
17
+ /**
18
+ * @private
19
+ */
20
+ accept(style: Renderer, layer: GeoJSON.Feature<GeoJSON.Geometry, GeoJSON.GeoJsonProperties>): boolean;
21
+ /**
22
+ * @private
23
+ */
24
+ drawPolygon(coordinates: GeoJSON.Position[][], geoJsonProperties: GeoJsonProperties, z: number, boundaries: Boundaries, style: PolygonStyle, context: CanvasRenderingContext2D, phase: string, collisions?: CollisionDetector, texts?: {
25
+ [key: string]: any;
26
+ }): void;
27
+ getCentroid(vertices: Vertex[]): Vertex;
28
+ getBBox(coordinates: PointXY[]): {
29
+ min: {
30
+ x: number;
31
+ y: number;
32
+ };
33
+ max: {
34
+ x: number;
35
+ y: number;
36
+ };
37
+ };
38
+ /**
39
+ * @private
40
+ */
41
+ projectCoordinates(coordinates: GeoJSON.Position[], boundaries: Boundaries): {
42
+ x: number;
43
+ y: number;
44
+ }[];
45
+ /**
46
+ * @private
47
+ */
48
+ drawPolyline(coordinates: GeoJSON.Position[], geoJsonProperties: GeoJsonProperties, boundaries: Boundaries, style: PolylineStyle, context: CanvasRenderingContext2D, phase: "linesOutline" | "lines"): void;
49
+ drawPolylineText(coordinates: GeoJSON.Position[], geoJsonProperties: GeoJsonProperties, boundaries: Boundaries, style: PolylineTextStyle | undefined, context: CanvasRenderingContext2D, collisions: CollisionDetector, texts: {
50
+ [key: string]: any;
51
+ }): void;
52
+ getPolylineLength(points: PointXY[]): number;
53
+ getAngleAndCoordsAtLength(points: PointXY[], dist: number, width: number): {
54
+ angle: number;
55
+ x: number;
56
+ y: number;
57
+ } | undefined;
58
+ getLetterPositions(points: PointXY[], text: string, context: CanvasRenderingContext2D, collisions: CollisionDetector): {
59
+ angle: number;
60
+ x: number;
61
+ y: number;
62
+ }[] | null;
63
+ /**
64
+ * @private
65
+ */
66
+ drawLetter(letter: string, position: PositionXY, outline: number, context: CanvasRenderingContext2D): void;
67
+ /**
68
+ * @private
69
+ */
70
+ drawPath(points: PointXY[], color: string, width: number, context: CanvasRenderingContext2D): void;
71
+ drawImage(coordinate: number[], boundaries: Boundaries, style: PolylineStyle, context: CanvasRenderingContext2D): void;
72
+ /**
73
+ * @private
74
+ */
75
+ isTextCollision(coordinate: GeoJSON.Position, name: string, boundaries: Boundaries, style: PolylineTextStyle, context: CanvasRenderingContext2D, collisions: CollisionDetector): boolean;
76
+ /**
77
+ * @private
78
+ */
79
+ drawText(coordinate: GeoJSON.Position, name: string, boundaries: Boundaries, style: PolylineTextStyle, context: CanvasRenderingContext2D, collisions: CollisionDetector): void;
80
+ preloadImages(): void;
81
+ findConfiguredFonts(): string[];
82
+ static DEFAULT_STYLE: {
83
+ POLYGON: {
84
+ color: string;
85
+ url: undefined;
86
+ outlineColor: undefined;
87
+ outlineWidth: number;
88
+ opacity: number;
89
+ };
90
+ LINE: {
91
+ color: string;
92
+ url: undefined;
93
+ height: number;
94
+ dx: number;
95
+ dy: number;
96
+ direction: string;
97
+ width: number;
98
+ outlineColor: undefined;
99
+ outlineWidth: number;
100
+ dashColor: undefined;
101
+ dashLength: number;
102
+ opacity: number;
103
+ };
104
+ IMAGE: {
105
+ url: undefined;
106
+ width: number;
107
+ height: number;
108
+ dx: number;
109
+ dy: number;
110
+ };
111
+ TEXT: {
112
+ color: string;
113
+ outlineColor: undefined;
114
+ outlineWidth: number;
115
+ font: string;
116
+ fontWeight: string;
117
+ fontStyle: string;
118
+ size: number;
119
+ opacity: number;
120
+ };
121
+ };
122
+ }
123
+ export { VectorTileRenderer };
@@ -0,0 +1,10 @@
1
+ export declare const URL_TEMPLATE = "https://v${index}.maptrip.de/?tilex=${x}&tiley=${y}&acao=true&context=tomtom${z}&project=${project}&projection=wgs84";
2
+ export declare const PROVIDER_PROJECTS: {
3
+ [key: string]: string;
4
+ };
5
+ export declare const PROVIDER_TRAFFIC: {
6
+ [key: string]: string | null;
7
+ };
8
+ export declare const MIN_ZOOM = 2;
9
+ export declare const MAX_ZOOM = 18;
10
+ export declare const ATTRIBUTION = "&#169;&nbsp;<a href=\"https://maptrip.de/\" target=\"_blank\">infoware GmbH</a>";