@maptrip/map-tiles 1.2.0 → 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.
@@ -35,13 +35,6 @@ export interface Renderer {
35
35
  dy: number;
36
36
  };
37
37
  filters?: Filter[];
38
- [key: string]: any;
39
- }
40
- export interface Filter {
41
- interface: string;
42
- key: string;
43
- value?: any;
44
- type: string;
45
38
  }
46
39
  export interface RENDERING_CONFIG {
47
40
  background: {
@@ -56,6 +49,12 @@ export interface RENDERING_CONFIG {
56
49
  [key: string]: Renderer[];
57
50
  };
58
51
  }
52
+ export interface Filter {
53
+ interface: string;
54
+ key: string;
55
+ value?: any;
56
+ type: string;
57
+ }
59
58
  export interface PolylineTextStyle {
60
59
  size: number;
61
60
  color: string;
@@ -79,8 +78,8 @@ export interface PolygonStyle {
79
78
  opacity?: number | undefined;
80
79
  outlineColor?: string | undefined;
81
80
  outlineWidth?: number | undefined;
82
- url: string;
83
- font: string;
81
+ url?: string | undefined;
82
+ font?: string | undefined;
84
83
  fontStyle?: string | undefined;
85
84
  fontWeight?: string | undefined;
86
85
  size?: number | undefined;
@@ -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 { PointXY, RENDERING_CONFIG } from "../../types/interfaces.js";
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,17 @@
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 type { PointXY, RENDERING_CONFIG } from "../../types/interfaces.js";
6
-
7
- const MapTripLeafletGridLayer = L.GridLayer.extend({
8
- MIN_ZOOM: MIN_ZOOM,
9
- MAX_ZOOM: MAX_ZOOM,
4
+ import type { PointXY } from "../../types/interfaces.js";
5
+ import {
6
+ RENDERING_CONFIG
7
+ } from "../../types/interfaces.js";
10
8
 
11
- initialize: function (options: {
9
+ class MapTripLeafletGridLayer extends L.GridLayer {
10
+ MIN_ZOOM = MIN_ZOOM;
11
+ MAX_ZOOM = MAX_ZOOM;
12
+ token: string;
13
+ factory: VectorTileFactory;
14
+ constructor(options: {
12
15
  provider?: string;
13
16
  baseMap?: boolean;
14
17
  traffic?: boolean;
@@ -21,24 +24,25 @@ const MapTripLeafletGridLayer = L.GridLayer.extend({
21
24
  minZoom?: number;
22
25
  maxZoom?: number;
23
26
  }) {
24
- if (options) {
25
- this.token = options.token;
26
- this.options.attribution = options.attribution
27
- ? options.attribution
28
- : ATTRIBUTION;
29
- this.options.minZoom = options.minZoom
30
- ? Math.max(this.MIN_ZOOM, options.minZoom)
31
- : this.MIN_ZOOM;
32
- this.options.maxZoom = options.maxZoom
33
- ? Math.min(this.MAX_ZOOM, options.maxZoom)
34
- : this.MAX_ZOOM;
35
- this.factory = VectorTileFactory.createFactory(options);
36
- }
37
- },
27
+ super(options as L.GridLayerOptions);
28
+ this.token = options.token!;
29
+ this.options.attribution = options.attribution
30
+ ? options.attribution
31
+ : ATTRIBUTION;
32
+ //@ts-expect-error picking up LayerOptions rather than GridLayerOptions
33
+ this.options.minZoom = options.minZoom
34
+ ? Math.max(this.MIN_ZOOM, options.minZoom)
35
+ : this.MIN_ZOOM;
36
+ //@ts-expect-error
37
+ this.options.maxZoom = options.maxZoom
38
+ ? Math.min(this.MAX_ZOOM, options.maxZoom)
39
+ : this.MAX_ZOOM;
40
+ this.factory = VectorTileFactory.createFactory(options);
41
+ }
38
42
 
39
- createTile: function (coords: PointXY) {
40
- return this.factory.getJsonTile(coords.z, coords.x, coords.y, this.token);
41
- },
42
- });
43
+ createTile(coords: PointXY) {
44
+ return this.factory.getJsonTile(coords.z!, coords.x, coords.y, this.token);
45
+ }
46
+ }
43
47
 
44
48
  export { MapTripLeafletGridLayer };
@@ -18,6 +18,7 @@ class MapTripOpenLayersSource extends XYZ {
18
18
  renderingConfig?: RENDERING_CONFIG;
19
19
  token?: string;
20
20
  }) {
21
+ super();
21
22
  const options: XYZOptions = {};
22
23
  const projection = "EPSG:3857";
23
24
 
@@ -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
  *
@@ -145,17 +145,21 @@ class VectorTileFactory {
145
145
  }
146
146
  }
147
147
 
148
- private static getRenderingConfig(properties: MapTilesProperties) {
149
- if (properties) {
150
- if (properties.renderingConfig) {
151
- return properties.renderingConfig;
152
- } else if (properties.baseMap) {
153
- return RENDERING_CONFIG_DEFAULT;
154
- } else {
155
- return RENDERING_CONFIG_TRAFFIC;
156
- }
157
- } else {
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
- const rendererName = this._styles?.layers[kind];
163
+ //@ts-ignore
164
+ const rendererName = this._styles.layers[kind];
163
165
  const renderer = rendererName
164
- ? this._styles?.renderers[rendererName]
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
- var merged = { ...VectorTileRenderer.DEFAULT_STYLE.POLYGON, ...style };
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 };