@maplibre/maplibre-react-native 11.0.0-alpha.33 → 11.0.0-alpha.34

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 (152) hide show
  1. package/MapLibreReactNative.podspec +1 -1
  2. package/android/src/main/java/org/maplibre/reactnative/MLRNPackage.kt +102 -90
  3. package/android/src/main/java/org/maplibre/reactnative/components/mapview/MLRNMapView.kt +271 -176
  4. package/android/src/main/java/org/maplibre/reactnative/components/mapview/MLRNMapViewModule.kt +66 -34
  5. package/android/src/main/java/org/maplibre/reactnative/http/RequestHeadersInterceptor.kt +65 -0
  6. package/android/src/main/java/org/maplibre/reactnative/modules/MLRNNetworkModule.kt +67 -0
  7. package/ios/modules/network/MLRNNetworkHTTPHeaders.h +14 -0
  8. package/ios/modules/network/MLRNNetworkHTTPHeaders.m +97 -0
  9. package/ios/modules/network/MLRNNetworkModule.h +8 -0
  10. package/ios/modules/network/MLRNNetworkModule.mm +28 -0
  11. package/lib/commonjs/components/layers/BackgroundLayer.js +2 -9
  12. package/lib/commonjs/components/layers/BackgroundLayer.js.map +1 -1
  13. package/lib/commonjs/components/layers/CircleLayer.js +2 -9
  14. package/lib/commonjs/components/layers/CircleLayer.js.map +1 -1
  15. package/lib/commonjs/components/layers/FillExtrusionLayer.js +2 -9
  16. package/lib/commonjs/components/layers/FillExtrusionLayer.js.map +1 -1
  17. package/lib/commonjs/components/layers/FillLayer.js +2 -9
  18. package/lib/commonjs/components/layers/FillLayer.js.map +1 -1
  19. package/lib/commonjs/components/layers/HeatmapLayer.js +2 -9
  20. package/lib/commonjs/components/layers/HeatmapLayer.js.map +1 -1
  21. package/lib/commonjs/components/layers/LineLayer.js +2 -9
  22. package/lib/commonjs/components/layers/LineLayer.js.map +1 -1
  23. package/lib/commonjs/components/layers/RasterLayer.js +2 -9
  24. package/lib/commonjs/components/layers/RasterLayer.js.map +1 -1
  25. package/lib/commonjs/components/layers/SymbolLayer.js +2 -9
  26. package/lib/commonjs/components/layers/SymbolLayer.js.map +1 -1
  27. package/lib/commonjs/components/map-view/MapView.js +0 -4
  28. package/lib/commonjs/components/map-view/MapView.js.map +1 -1
  29. package/lib/commonjs/index.js +8 -43
  30. package/lib/commonjs/index.js.map +1 -1
  31. package/lib/commonjs/modules/network/NativeNetworkModule.js +9 -0
  32. package/lib/commonjs/modules/network/NativeNetworkModule.js.map +1 -0
  33. package/lib/commonjs/modules/network/NetworkManager.js +72 -0
  34. package/lib/commonjs/modules/network/NetworkManager.js.map +1 -0
  35. package/lib/commonjs/modules/snapshot/SnapshotManager.js +3 -5
  36. package/lib/commonjs/modules/snapshot/SnapshotManager.js.map +1 -1
  37. package/lib/commonjs/modules/snapshot/SnapshotOptions.js +1 -3
  38. package/lib/commonjs/modules/snapshot/SnapshotOptions.js.map +1 -1
  39. package/lib/module/components/layers/BackgroundLayer.js +3 -10
  40. package/lib/module/components/layers/BackgroundLayer.js.map +1 -1
  41. package/lib/module/components/layers/CircleLayer.js +3 -10
  42. package/lib/module/components/layers/CircleLayer.js.map +1 -1
  43. package/lib/module/components/layers/FillExtrusionLayer.js +3 -10
  44. package/lib/module/components/layers/FillExtrusionLayer.js.map +1 -1
  45. package/lib/module/components/layers/FillLayer.js +3 -10
  46. package/lib/module/components/layers/FillLayer.js.map +1 -1
  47. package/lib/module/components/layers/HeatmapLayer.js +3 -10
  48. package/lib/module/components/layers/HeatmapLayer.js.map +1 -1
  49. package/lib/module/components/layers/LineLayer.js +3 -10
  50. package/lib/module/components/layers/LineLayer.js.map +1 -1
  51. package/lib/module/components/layers/RasterLayer.js +3 -10
  52. package/lib/module/components/layers/RasterLayer.js.map +1 -1
  53. package/lib/module/components/layers/SymbolLayer.js +3 -10
  54. package/lib/module/components/layers/SymbolLayer.js.map +1 -1
  55. package/lib/module/components/map-view/MapView.js +1 -5
  56. package/lib/module/components/map-view/MapView.js.map +1 -1
  57. package/lib/module/index.js +2 -2
  58. package/lib/module/index.js.map +1 -1
  59. package/lib/module/modules/network/NativeNetworkModule.js +5 -0
  60. package/lib/module/modules/network/NativeNetworkModule.js.map +1 -0
  61. package/lib/module/modules/network/NetworkManager.js +68 -0
  62. package/lib/module/modules/network/NetworkManager.js.map +1 -0
  63. package/lib/module/modules/snapshot/SnapshotManager.js +3 -5
  64. package/lib/module/modules/snapshot/SnapshotManager.js.map +1 -1
  65. package/lib/module/modules/snapshot/SnapshotOptions.js +1 -3
  66. package/lib/module/modules/snapshot/SnapshotOptions.js.map +1 -1
  67. package/lib/typescript/commonjs/src/components/layers/BackgroundLayer.d.ts +1 -1
  68. package/lib/typescript/commonjs/src/components/layers/BackgroundLayer.d.ts.map +1 -1
  69. package/lib/typescript/commonjs/src/components/layers/CircleLayer.d.ts +1 -1
  70. package/lib/typescript/commonjs/src/components/layers/CircleLayer.d.ts.map +1 -1
  71. package/lib/typescript/commonjs/src/components/layers/FillExtrusionLayer.d.ts +1 -1
  72. package/lib/typescript/commonjs/src/components/layers/FillExtrusionLayer.d.ts.map +1 -1
  73. package/lib/typescript/commonjs/src/components/layers/FillLayer.d.ts +1 -1
  74. package/lib/typescript/commonjs/src/components/layers/FillLayer.d.ts.map +1 -1
  75. package/lib/typescript/commonjs/src/components/layers/HeatmapLayer.d.ts +1 -1
  76. package/lib/typescript/commonjs/src/components/layers/HeatmapLayer.d.ts.map +1 -1
  77. package/lib/typescript/commonjs/src/components/layers/LineLayer.d.ts +1 -1
  78. package/lib/typescript/commonjs/src/components/layers/LineLayer.d.ts.map +1 -1
  79. package/lib/typescript/commonjs/src/components/layers/RasterLayer.d.ts +1 -1
  80. package/lib/typescript/commonjs/src/components/layers/RasterLayer.d.ts.map +1 -1
  81. package/lib/typescript/commonjs/src/components/layers/SymbolLayer.d.ts +1 -1
  82. package/lib/typescript/commonjs/src/components/layers/SymbolLayer.d.ts.map +1 -1
  83. package/lib/typescript/commonjs/src/components/map-view/MapView.d.ts.map +1 -1
  84. package/lib/typescript/commonjs/src/index.d.ts +2 -2
  85. package/lib/typescript/commonjs/src/index.d.ts.map +1 -1
  86. package/lib/typescript/commonjs/src/modules/network/NativeNetworkModule.d.ts +9 -0
  87. package/lib/typescript/commonjs/src/modules/network/NativeNetworkModule.d.ts.map +1 -0
  88. package/lib/typescript/commonjs/src/modules/network/NetworkManager.d.ts +56 -0
  89. package/lib/typescript/commonjs/src/modules/network/NetworkManager.d.ts.map +1 -0
  90. package/lib/typescript/commonjs/src/modules/snapshot/SnapshotManager.d.ts +2 -3
  91. package/lib/typescript/commonjs/src/modules/snapshot/SnapshotManager.d.ts.map +1 -1
  92. package/lib/typescript/commonjs/src/modules/snapshot/SnapshotOptions.d.ts +2 -1
  93. package/lib/typescript/commonjs/src/modules/snapshot/SnapshotOptions.d.ts.map +1 -1
  94. package/lib/typescript/commonjs/src/utils/animated/Animated.d.ts +7 -7
  95. package/lib/typescript/module/src/components/layers/BackgroundLayer.d.ts +1 -1
  96. package/lib/typescript/module/src/components/layers/BackgroundLayer.d.ts.map +1 -1
  97. package/lib/typescript/module/src/components/layers/CircleLayer.d.ts +1 -1
  98. package/lib/typescript/module/src/components/layers/CircleLayer.d.ts.map +1 -1
  99. package/lib/typescript/module/src/components/layers/FillExtrusionLayer.d.ts +1 -1
  100. package/lib/typescript/module/src/components/layers/FillExtrusionLayer.d.ts.map +1 -1
  101. package/lib/typescript/module/src/components/layers/FillLayer.d.ts +1 -1
  102. package/lib/typescript/module/src/components/layers/FillLayer.d.ts.map +1 -1
  103. package/lib/typescript/module/src/components/layers/HeatmapLayer.d.ts +1 -1
  104. package/lib/typescript/module/src/components/layers/HeatmapLayer.d.ts.map +1 -1
  105. package/lib/typescript/module/src/components/layers/LineLayer.d.ts +1 -1
  106. package/lib/typescript/module/src/components/layers/LineLayer.d.ts.map +1 -1
  107. package/lib/typescript/module/src/components/layers/RasterLayer.d.ts +1 -1
  108. package/lib/typescript/module/src/components/layers/RasterLayer.d.ts.map +1 -1
  109. package/lib/typescript/module/src/components/layers/SymbolLayer.d.ts +1 -1
  110. package/lib/typescript/module/src/components/layers/SymbolLayer.d.ts.map +1 -1
  111. package/lib/typescript/module/src/components/map-view/MapView.d.ts.map +1 -1
  112. package/lib/typescript/module/src/index.d.ts +2 -2
  113. package/lib/typescript/module/src/index.d.ts.map +1 -1
  114. package/lib/typescript/module/src/modules/network/NativeNetworkModule.d.ts +9 -0
  115. package/lib/typescript/module/src/modules/network/NativeNetworkModule.d.ts.map +1 -0
  116. package/lib/typescript/module/src/modules/network/NetworkManager.d.ts +56 -0
  117. package/lib/typescript/module/src/modules/network/NetworkManager.d.ts.map +1 -0
  118. package/lib/typescript/module/src/modules/snapshot/SnapshotManager.d.ts +2 -3
  119. package/lib/typescript/module/src/modules/snapshot/SnapshotManager.d.ts.map +1 -1
  120. package/lib/typescript/module/src/modules/snapshot/SnapshotOptions.d.ts +2 -1
  121. package/lib/typescript/module/src/modules/snapshot/SnapshotOptions.d.ts.map +1 -1
  122. package/lib/typescript/module/src/utils/animated/Animated.d.ts +7 -7
  123. package/package.json +2 -2
  124. package/src/components/layers/BackgroundLayer.tsx +3 -11
  125. package/src/components/layers/CircleLayer.tsx +3 -11
  126. package/src/components/layers/FillExtrusionLayer.tsx +3 -11
  127. package/src/components/layers/FillLayer.tsx +3 -11
  128. package/src/components/layers/HeatmapLayer.tsx +3 -11
  129. package/src/components/layers/LineLayer.tsx +3 -11
  130. package/src/components/layers/RasterLayer.tsx +3 -11
  131. package/src/components/layers/SymbolLayer.tsx +3 -11
  132. package/src/components/map-view/MapView.tsx +0 -8
  133. package/src/index.ts +4 -3
  134. package/src/modules/network/NativeNetworkModule.ts +12 -0
  135. package/src/modules/network/NetworkManager.ts +74 -0
  136. package/src/modules/snapshot/SnapshotManager.ts +3 -5
  137. package/src/modules/snapshot/SnapshotOptions.ts +3 -5
  138. package/android/src/main/java/org/maplibre/reactnative/http/CustomHeadersInterceptor.java +0 -38
  139. package/android/src/main/java/org/maplibre/reactnative/modules/MLRNModule.java +0 -112
  140. package/ios/modules/mlrn/MLRNCustomHeaders.h +0 -20
  141. package/ios/modules/mlrn/MLRNCustomHeaders.m +0 -98
  142. package/ios/modules/mlrn/MLRNModule.h +0 -5
  143. package/ios/modules/mlrn/MLRNModule.m +0 -45
  144. package/lib/commonjs/MLRNModule.js +0 -21
  145. package/lib/commonjs/MLRNModule.js.map +0 -1
  146. package/lib/module/MLRNModule.js +0 -12
  147. package/lib/module/MLRNModule.js.map +0 -1
  148. package/lib/typescript/commonjs/src/MLRNModule.d.ts +0 -6
  149. package/lib/typescript/commonjs/src/MLRNModule.d.ts.map +0 -1
  150. package/lib/typescript/module/src/MLRNModule.d.ts +0 -6
  151. package/lib/typescript/module/src/MLRNModule.d.ts.map +0 -1
  152. package/src/MLRNModule.ts +0 -28
@@ -1,4 +1,4 @@
1
- import { NativeModules, requireNativeComponent } from "react-native";
1
+ import { requireNativeComponent } from "react-native";
2
2
 
3
3
  import {
4
4
  useAbstractLayer,
@@ -8,8 +8,6 @@ import {
8
8
  import { type BaseProps } from "../../types/BaseProps";
9
9
  import { type LineLayerStyle } from "../../types/MapLibreRNStyles";
10
10
 
11
- const MLRNModule = NativeModules.MLRNModule;
12
-
13
11
  export const NATIVE_MODULE_NAME = "MLRNLineLayer";
14
12
 
15
13
  export interface LineLayerProps extends BaseProps, BaseLayerProps {
@@ -27,17 +25,11 @@ const MLRNLineLayer =
27
25
  /**
28
26
  * LineLayer is a style layer that renders one or more stroked polylines on the map.
29
27
  */
30
- export const LineLayer = ({
31
- sourceID = MLRNModule.StyleSource.DefaultSourceID,
32
- ...props
33
- }: LineLayerProps) => {
28
+ export const LineLayer = (props: LineLayerProps) => {
34
29
  const { baseProps, setNativeLayer } = useAbstractLayer<
35
30
  LineLayerProps,
36
31
  NativeProps
37
- >({
38
- ...props,
39
- sourceID,
40
- });
32
+ >(props);
41
33
 
42
34
  return <MLRNLineLayer ref={setNativeLayer} {...baseProps} />;
43
35
  };
@@ -1,4 +1,4 @@
1
- import { NativeModules, requireNativeComponent } from "react-native";
1
+ import { requireNativeComponent } from "react-native";
2
2
 
3
3
  import {
4
4
  useAbstractLayer,
@@ -8,8 +8,6 @@ import {
8
8
  import { type BaseProps } from "../../types/BaseProps";
9
9
  import { type RasterLayerStyle } from "../../types/MapLibreRNStyles";
10
10
 
11
- const MLRNModule = NativeModules.MLRNModule;
12
-
13
11
  export const NATIVE_MODULE_NAME = "MLRNRasterLayer";
14
12
 
15
13
  export interface RasterLayerProps extends BaseProps, BaseLayerProps {
@@ -24,17 +22,11 @@ interface NativeProps
24
22
 
25
23
  const MLRNRasterLayer = requireNativeComponent<NativeProps>(NATIVE_MODULE_NAME);
26
24
 
27
- export const RasterLayer = ({
28
- sourceID = MLRNModule.StyleSource.DefaultSourceID,
29
- ...props
30
- }: RasterLayerProps) => {
25
+ export const RasterLayer = (props: RasterLayerProps) => {
31
26
  const { baseProps, setNativeLayer } = useAbstractLayer<
32
27
  RasterLayerProps,
33
28
  NativeProps
34
- >({
35
- ...props,
36
- sourceID,
37
- });
29
+ >(props);
38
30
 
39
31
  return <MLRNRasterLayer ref={setNativeLayer} {...baseProps} />;
40
32
  };
@@ -1,4 +1,4 @@
1
- import { NativeModules, requireNativeComponent } from "react-native";
1
+ import { requireNativeComponent } from "react-native";
2
2
 
3
3
  import {
4
4
  useAbstractLayer,
@@ -8,8 +8,6 @@ import {
8
8
  import { type BaseProps } from "../../types/BaseProps";
9
9
  import { type SymbolLayerStyle } from "../../types/MapLibreRNStyles";
10
10
 
11
- const MLRNModule = NativeModules.MLRNModule;
12
-
13
11
  export const NATIVE_MODULE_NAME = "MLRNSymbolLayer";
14
12
 
15
13
  export interface SymbolLayerProps extends BaseProps, BaseLayerProps {
@@ -27,17 +25,11 @@ const MLRNSymbolLayer = requireNativeComponent<NativeProps>(NATIVE_MODULE_NAME);
27
25
  /**
28
26
  * SymbolLayer is a style layer that renders icon and text labels at points or along lines on the map.
29
27
  */
30
- export const SymbolLayer = ({
31
- sourceID = MLRNModule.StyleSource.DefaultSourceID,
32
- ...props
33
- }: SymbolLayerProps) => {
28
+ export const SymbolLayer = (props: SymbolLayerProps) => {
34
29
  const { baseProps, setNativeLayer } = useAbstractLayer<
35
30
  SymbolLayerProps,
36
31
  NativeBaseProps
37
- >({
38
- ...props,
39
- sourceID,
40
- });
32
+ >(props);
41
33
 
42
34
  const updatedProps = {
43
35
  ...baseProps,
@@ -13,7 +13,6 @@ import {
13
13
  } from "react";
14
14
  import {
15
15
  type NativeMethods,
16
- NativeModules,
17
16
  type NativeSyntheticEvent,
18
17
  Platform,
19
18
  StyleSheet,
@@ -41,13 +40,6 @@ import { transformStyle } from "../../utils/StyleValue";
41
40
  import { findNodeHandle } from "../../utils/findNodeHandle";
42
41
  import { getFilter } from "../../utils/getFilter";
43
42
 
44
- const MLRNModule = NativeModules.MLRNModule;
45
- if (MLRNModule == null) {
46
- console.error(
47
- "Native module of @maplibre/maplibre-react-native library was not registered properly, please consult the docs: https://github.com/maplibre/maplibre-react-native",
48
- );
49
- }
50
-
51
43
  const styles = StyleSheet.create({
52
44
  flex1: { flex: 1 },
53
45
  });
package/src/index.ts CHANGED
@@ -1,5 +1,3 @@
1
- export * from "./MLRNModule";
2
-
3
1
  export {
4
2
  type CameraOptions,
5
3
  type CameraEasing,
@@ -72,6 +70,8 @@ export {
72
70
  type GeolocationPosition,
73
71
  } from "./modules/location/LocationManager";
74
72
 
73
+ export { LogManager, type LogLevel } from "./modules/log/LogManager";
74
+
75
75
  export {
76
76
  OfflineManager,
77
77
  type OfflinePackCreateOptions,
@@ -85,6 +85,8 @@ export {
85
85
  type OfflinePackStatus,
86
86
  } from "./modules/offline/OfflinePack";
87
87
 
88
+ export { NetworkManager } from "./modules/network/NetworkManager";
89
+
88
90
  export { SnapshotManager } from "./modules/snapshot/SnapshotManager";
89
91
  export type { SnapshotInputOptions } from "./modules/snapshot/SnapshotOptions";
90
92
 
@@ -110,6 +112,5 @@ export type { PressEventWithFeatures } from "./types/PressEventWithFeatures";
110
112
  export type { ViewPadding } from "./types/ViewPadding";
111
113
 
112
114
  export { Animated } from "./utils/animated/Animated";
113
- export { LogManager, type LogLevel } from "./modules/log/LogManager";
114
115
 
115
116
  export type { MapLibrePluginProps } from "./plugin/MapLibrePluginProps";
@@ -0,0 +1,12 @@
1
+ import type { TurboModule } from "react-native";
2
+ import { TurboModuleRegistry } from "react-native";
3
+
4
+ export interface Spec extends TurboModule {
5
+ addRequestHeader(name: string, value: string, match: string | null): void;
6
+
7
+ removeRequestHeader(name: string): void;
8
+
9
+ setConnected(connected: boolean): void;
10
+ }
11
+
12
+ export default TurboModuleRegistry.getEnforcing<Spec>("MLRNNetworkModule");
@@ -0,0 +1,74 @@
1
+ import NativeNetworkModule from "./NativeNetworkModule";
2
+
3
+ /**
4
+ * NetworkManager provides methods for managing HTTP requests made by MapLibre.
5
+ * This includes adding custom headers to tile requests and controlling network connectivity.
6
+ */
7
+ class NetworkManager {
8
+ /**
9
+ * Adds a custom HTTP header that will be sent with all map tile requests.
10
+ * This is useful for adding authentication tokens or other custom headers
11
+ * required by your tile server.
12
+ *
13
+ * @example
14
+ * // Add header to all requests
15
+ * NetworkManager.addRequestHeader("Authorization", "Bearer token123");
16
+ *
17
+ * // Add header only to requests matching a regex pattern (string)
18
+ * NetworkManager.addRequestHeader("X-API-Key", "key123", "https:\\/\\/api\\.example\\.com\\/tiles\\/");
19
+ *
20
+ * // Add header only to requests matching a regex pattern (RegExp)
21
+ * NetworkManager.addRequestHeader("X-API-Key", "key123", /https:\/\/api\.example\.com\/tiles\//);
22
+ *
23
+ * @param name The name of the header (e.g., "Authorization")
24
+ * @param value The value of the header (e.g., "Bearer token123")
25
+ * @param match Optional regex pattern to match against network URLs. If provided, the header will only be added to requests whose URLs match this pattern. Can be a RegExp object or a regex string.
26
+ */
27
+ static addRequestHeader(
28
+ name: string,
29
+ value: string,
30
+ match?: string | RegExp,
31
+ ): void {
32
+ NativeNetworkModule.addRequestHeader(
33
+ name,
34
+ value,
35
+ (match instanceof RegExp ? match.source : match) || null,
36
+ );
37
+ }
38
+
39
+ /**
40
+ * Removes a previously added custom HTTP header.
41
+ *
42
+ * @example
43
+ * ```ts
44
+ * NetworkManager.removeRequestHeader("Authorization");
45
+ * ```
46
+ *
47
+ * @param headerName The name of the header to remove
48
+ */
49
+ static removeRequestHeader(headerName: string): void {
50
+ NativeNetworkModule.removeRequestHeader(headerName);
51
+ }
52
+
53
+ /**
54
+ * Android only: Sets the connectivity state of the map. When set to false, the map will
55
+ * not make any network requests and will only use cached tiles. This is
56
+ * useful for implementing offline mode or reducing data usage.
57
+ *
58
+ * @example
59
+ * ```ts
60
+ * // Enable offline mode
61
+ * NetworkManager.setConnected(false);
62
+ *
63
+ * // Re-enable network requests
64
+ * NetworkManager.setConnected(true);
65
+ * ```
66
+ *
67
+ * @param connected Whether the map should be connected to the network
68
+ */
69
+ static setConnected(connected: boolean): void {
70
+ NativeNetworkModule.setConnected(connected);
71
+ }
72
+ }
73
+
74
+ export { NetworkManager };
@@ -44,14 +44,12 @@ class SnapshotManager {
44
44
  * styleURL: StyleURL.Default,
45
45
  * });
46
46
  *
47
- * @param {SnapshotOptions} options Snapshot options for create a static image of the base map
48
- * @return {Promise}
47
+ * @param options Snapshot options for create a static image of the base map
49
48
  */
50
- async takeSnap(options: SnapshotInputOptions = {}): Promise<string> {
49
+ async takeSnap(options: SnapshotInputOptions): Promise<string> {
51
50
  const snapshotOptions = new SnapshotOptions(options);
52
51
 
53
- const uri = await NativeSnapshotModule.takeSnap(snapshotOptions.toJSON());
54
- return uri;
52
+ return NativeSnapshotModule.takeSnap(snapshotOptions.toJSON());
55
53
  }
56
54
  }
57
55
 
@@ -1,14 +1,12 @@
1
1
  import { featureCollection, point } from "@turf/helpers";
2
- import { NativeModules } from "react-native";
3
2
 
4
3
  import type { SnapshotJsonOptions } from "./NativeSnapshotModule";
5
4
  import { toJSONString } from "../../utils";
6
5
 
7
- const MLRNModule = NativeModules.MLRNModule;
8
-
9
6
  export interface SnapshotInputOptions extends Partial<
10
- Omit<SnapshotJsonOptions, "centerCoordinate" | "bounds">
7
+ Omit<SnapshotJsonOptions, "styleURL" | "centerCoordinate" | "bounds">
11
8
  > {
9
+ styleURL: string;
12
10
  centerCoordinate?: GeoJSON.Position;
13
11
  bounds?: GeoJSON.Position[];
14
12
  }
@@ -32,7 +30,7 @@ export class SnapshotOptions implements SnapshotJsonOptions {
32
30
  );
33
31
  }
34
32
 
35
- this.styleURL = options.styleURL || MLRNModule.StyleURL.Default;
33
+ this.styleURL = options.styleURL;
36
34
  this.heading = options.heading || 0.0;
37
35
  this.pitch = options.pitch || 0.0;
38
36
  this.zoomLevel = options.zoomLevel || 16.0;
@@ -1,38 +0,0 @@
1
- package org.maplibre.reactnative.http;
2
-
3
- import android.util.Log;
4
-
5
- import org.jetbrains.annotations.NotNull;
6
-
7
- import java.io.IOException;
8
- import java.util.HashMap;
9
- import java.util.Map;
10
-
11
- import okhttp3.Interceptor;
12
- import okhttp3.Request;
13
- import okhttp3.Response;
14
-
15
- public class CustomHeadersInterceptor implements Interceptor {
16
-
17
- public static final CustomHeadersInterceptor INSTANCE = new CustomHeadersInterceptor();
18
- private Map<String, String> customHeaders = new HashMap<>();
19
-
20
- public void addHeader(@NotNull final String headerName, @NotNull String headerValue) {
21
- customHeaders.put(headerName, headerValue);
22
- }
23
-
24
- public void removeHeader(@NotNull final String headerName) {
25
- customHeaders.remove(headerName);
26
- }
27
-
28
- @Override
29
- public Response intercept(@NotNull Chain chain) throws IOException {
30
- Request.Builder modifiedHeaderBuilder = chain.request().newBuilder();
31
- for (Map.Entry<String, String> entry : customHeaders.entrySet()) {
32
- modifiedHeaderBuilder.addHeader(entry.getKey(), entry.getValue());
33
- }
34
-
35
- Request request = modifiedHeaderBuilder.build();
36
- return chain.proceed(request);
37
- }
38
- }
@@ -1,112 +0,0 @@
1
- package org.maplibre.reactnative.modules;
2
-
3
- import android.os.Handler;
4
- import android.util.Log;
5
-
6
- import com.facebook.react.bridge.ReactApplicationContext;
7
- import com.facebook.react.bridge.ReactContextBaseJavaModule;
8
- import com.facebook.react.bridge.ReactMethod;
9
- import com.facebook.react.common.MapBuilder;
10
- import com.facebook.react.module.annotations.ReactModule;
11
-
12
- import org.maplibre.android.MapLibre;
13
- import org.maplibre.android.module.http.HttpRequestUtil;
14
- import org.maplibre.reactnative.http.CustomHeadersInterceptor;
15
-
16
- import java.util.HashMap;
17
- import java.util.Map;
18
-
19
- import javax.annotation.Nullable;
20
-
21
- import okhttp3.Dispatcher;
22
- import okhttp3.OkHttpClient;
23
-
24
- @ReactModule(name = MLRNModule.REACT_CLASS)
25
- public class MLRNModule extends ReactContextBaseJavaModule {
26
- public static final String REACT_CLASS = "MLRNModule";
27
-
28
- public static final String DEFAULT_STYLE_URL = "https://demotiles.maplibre.org/style.json";
29
-
30
- private static boolean customHeaderInterceptorAdded = false;
31
-
32
- private Handler mUiThreadHandler;
33
- private ReactApplicationContext mReactContext;
34
-
35
- public MLRNModule(ReactApplicationContext reactApplicationContext) {
36
- super(reactApplicationContext);
37
- mReactContext = reactApplicationContext;
38
- }
39
-
40
- @Override
41
- public void initialize() {
42
- initializeMapLibreInstance();
43
- }
44
-
45
- @Override
46
- public String getName() {
47
- return REACT_CLASS;
48
- }
49
-
50
- @Override
51
- @Nullable
52
- public Map<String, Object> getConstants() {
53
- Map<String, String> styleURLS = new HashMap<>();
54
- styleURLS.put("Default", DEFAULT_STYLE_URL);
55
-
56
- return MapBuilder.<String, Object>builder().put("StyleURL", styleURLS).build();
57
- }
58
-
59
- @ReactMethod
60
- public void removeCustomHeader(final String headerName) {
61
- mReactContext.runOnUiQueueThread(new Runnable() {
62
- @Override
63
- public void run() {
64
- CustomHeadersInterceptor.INSTANCE.removeHeader(headerName);
65
- }
66
- });
67
- }
68
-
69
- @ReactMethod
70
- public void addCustomHeader(final String headerName, final String headerValue) {
71
- mReactContext.runOnUiQueueThread(new Runnable() {
72
- @Override
73
- public void run() {
74
- if (!customHeaderInterceptorAdded) {
75
- Log.i("header", "Add interceptor");
76
- OkHttpClient httpClient = new OkHttpClient.Builder().addInterceptor(CustomHeadersInterceptor.INSTANCE).dispatcher(getDispatcher()).build();
77
- HttpRequestUtil.setOkHttpClient(httpClient);
78
- customHeaderInterceptorAdded = true;
79
- }
80
-
81
- CustomHeadersInterceptor.INSTANCE.addHeader(headerName, headerValue);
82
- }
83
- });
84
- }
85
-
86
- @ReactMethod
87
- public void setConnected(final boolean connected) {
88
- mReactContext.runOnUiQueueThread(new Runnable() {
89
- @Override
90
- public void run() {
91
- MapLibre.setConnected(connected);
92
- }
93
- });
94
- }
95
-
96
- private Dispatcher getDispatcher() {
97
- Dispatcher dispatcher = new Dispatcher();
98
- // Matches core limit set on
99
- // https://github.com/mapbox/mapbox-gl-native/blob/master/platform/android/src/http_file_source.cpp#L192
100
- dispatcher.setMaxRequestsPerHost(20);
101
- return dispatcher;
102
- }
103
-
104
- private void initializeMapLibreInstance() {
105
- mReactContext.runOnUiQueueThread(new Runnable() {
106
- @Override
107
- public void run() {
108
- MapLibre.getInstance(getReactApplicationContext());
109
- }
110
- });
111
- }
112
- }
@@ -1,20 +0,0 @@
1
- //
2
- // MLRNCustomHeaders.h
3
- // MLRN
4
- //
5
-
6
- #import <Foundation/Foundation.h>
7
-
8
- @interface NSMutableURLRequest (CustomHeaders)
9
- @end
10
-
11
- @interface MLRNCustomHeaders : NSObject
12
-
13
- @property (nonatomic, strong) NSMutableDictionary<NSString *, NSString *> *currentHeaders;
14
-
15
- + (id)sharedInstance;
16
- - (void)initHeaders;
17
- - (void)addHeader:(NSString *)value forHeaderName:(NSString *)header;
18
- - (void)removeHeader:(NSString *)header;
19
-
20
- @end
@@ -1,98 +0,0 @@
1
- //
2
- // MLRNCustomHeaders.h
3
- // MLRN
4
- //
5
-
6
- #import <objc/runtime.h>
7
-
8
- #import <MapLibre/MLNNetworkConfiguration.h>
9
- #import <MapLibre/MapLibre.h>
10
- #import "MLRNCustomHeaders.h"
11
-
12
- @implementation NSMutableURLRequest (CustomHeaders)
13
-
14
- + (NSMutableURLRequest *)__swizzle_requestWithURL:(NSURL *)url {
15
- if ([url.scheme isEqualToString:@"ws"]) {
16
- return [NSMutableURLRequest __swizzle_requestWithURL:url];
17
- }
18
-
19
- NSArray<NSString *> *stack = [NSThread callStackSymbols];
20
- if ([stack count] < 2) {
21
- return [NSMutableURLRequest __swizzle_requestWithURL:url];
22
- }
23
-
24
- if ([stack[1] containsString:@"MapLibre"] == NO) {
25
- return [NSMutableURLRequest __swizzle_requestWithURL:url];
26
- }
27
-
28
- NSMutableURLRequest *req = [NSMutableURLRequest __swizzle_requestWithURL:url];
29
- NSDictionary<NSString *, NSString *> *currentHeaders =
30
- [[[MLRNCustomHeaders sharedInstance] currentHeaders] copy];
31
- if (currentHeaders != nil && [currentHeaders count] > 0) {
32
- for (NSString *headerName in currentHeaders) {
33
- id headerValue = currentHeaders[headerName];
34
- [req setValue:headerValue forHTTPHeaderField:headerName];
35
- }
36
- }
37
- return req;
38
- }
39
-
40
- @end
41
-
42
- @implementation MLRNCustomHeaders {
43
- NSMutableDictionary<NSString *, NSString *> *_currentHeaders;
44
- BOOL areHeadersAdded;
45
- }
46
-
47
- + (id)sharedInstance {
48
- static MLRNCustomHeaders *customHeaders;
49
- static dispatch_once_t onceToken;
50
- dispatch_once(&onceToken, ^{
51
- customHeaders = [[self alloc] init];
52
- });
53
- return customHeaders;
54
- }
55
-
56
- // This replaces the [NSMutableURLRequest requestWithURL:] with custom implementation which
57
- // adds runtime headers copied from [MLRNCustomHeaders _currentHeaders]
58
- - (void)initHeaders {
59
- if (!areHeadersAdded) {
60
- areHeadersAdded = YES;
61
- NSLog(@"Replace method [NSMutableURLRequest requestWithURL]");
62
- static dispatch_once_t onceToken;
63
- dispatch_once(&onceToken, ^{
64
- Class targetClass = [NSMutableURLRequest class];
65
- Method oldMethod = class_getClassMethod(targetClass, @selector(requestWithURL:));
66
- Method newMethod = class_getClassMethod(targetClass, @selector(__swizzle_requestWithURL:));
67
- method_exchangeImplementations(oldMethod, newMethod);
68
- });
69
- }
70
- }
71
-
72
- - (instancetype)init {
73
- if (self = [super init]) {
74
- _currentHeaders = [[NSMutableDictionary alloc] init];
75
- areHeadersAdded = NO;
76
- }
77
- return self;
78
- }
79
-
80
- - (void)addHeader:(NSString *)value forHeaderName:(NSString *)headerName {
81
- if (!areHeadersAdded) {
82
- areHeadersAdded = YES;
83
- }
84
-
85
- [_currentHeaders setObject:value forKey:headerName];
86
- [[[MLNNetworkConfiguration sharedManager] sessionConfiguration]
87
- setHTTPAdditionalHeaders:_currentHeaders];
88
- }
89
-
90
- - (void)removeHeader:(NSString *)header {
91
- if (!areHeadersAdded) {
92
- return;
93
- }
94
-
95
- [_currentHeaders removeObjectForKey:header];
96
- }
97
-
98
- @end
@@ -1,5 +0,0 @@
1
- #import <Foundation/Foundation.h>
2
- #import <React/RCTBridgeModule.h>
3
-
4
- @interface MLRNModule : NSObject <RCTBridgeModule>
5
- @end
@@ -1,45 +0,0 @@
1
- #import "MLRNModule.h"
2
- #import "MLRNCustomHeaders.h"
3
- #import "MLRNEventTypes.h"
4
- #import "MLRNSource.h"
5
- @import MapLibre;
6
-
7
- @implementation MLRNModule
8
-
9
- RCT_EXPORT_MODULE();
10
-
11
- + (BOOL)requiresMainQueueSetup {
12
- return YES;
13
- }
14
-
15
- - (NSDictionary<NSString *, id> *)constantsToExport {
16
- // style urls
17
- NSMutableDictionary *styleURLS = [[NSMutableDictionary alloc] init];
18
- [styleURLS setObject:[[MLNStyle defaultStyleURL] absoluteString] forKey:@"Default"];
19
-
20
- // event types
21
- NSMutableDictionary *eventTypes = [[NSMutableDictionary alloc] init];
22
- [eventTypes setObject:RCT_MLRN_PRESS forKey:@"Press"];
23
- [eventTypes setObject:RCT_MLRN_LONG_PRESS forKey:@"LongPress"];
24
-
25
- // style sources
26
- NSMutableDictionary *styleSourceConsts = [[NSMutableDictionary alloc] init];
27
- [styleSourceConsts setObject:DEFAULT_SOURCE_ID forKey:@"DefaultSourceID"];
28
-
29
- return @{
30
- @"StyleURL" : styleURLS,
31
- @"EventTypes" : eventTypes,
32
- @"StyleSource" : styleSourceConsts,
33
- };
34
- }
35
-
36
- RCT_EXPORT_METHOD(addCustomHeader : (NSString *)headerName forHeaderValue : (NSString *)
37
- headerValue) {
38
- [MLRNCustomHeaders.sharedInstance addHeader:headerValue forHeaderName:headerName];
39
- }
40
-
41
- RCT_EXPORT_METHOD(removeCustomHeader : (NSString *)headerName) {
42
- [MLRNCustomHeaders.sharedInstance removeHeader:headerName];
43
- }
44
-
45
- @end
@@ -1,21 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.setConnected = exports.removeCustomHeader = exports.addCustomHeader = exports.StyleURL = exports.StyleSource = void 0;
7
- var _reactNative = require("react-native");
8
- const MLRNModule = Object.create(_reactNative.NativeModules.MLRNModule);
9
- const {
10
- StyleSource,
11
- StyleURL,
12
- addCustomHeader,
13
- removeCustomHeader,
14
- setConnected
15
- } = MLRNModule;
16
- exports.setConnected = setConnected;
17
- exports.removeCustomHeader = removeCustomHeader;
18
- exports.addCustomHeader = addCustomHeader;
19
- exports.StyleURL = StyleURL;
20
- exports.StyleSource = StyleSource;
21
- //# sourceMappingURL=MLRNModule.js.map
@@ -1 +0,0 @@
1
- {"version":3,"names":["_reactNative","require","MLRNModule","Object","create","NativeModules","StyleSource","StyleURL","addCustomHeader","removeCustomHeader","setConnected","exports"],"sourceRoot":"../../src","sources":["MLRNModule.ts"],"mappings":";;;;;;AAAA,IAAAA,YAAA,GAAAC,OAAA;AAiBA,MAAMC,UAAuB,GAAGC,MAAM,CAACC,MAAM,CAACC,0BAAa,CAACH,UAAU,CAAC;AAEhE,MAAM;EACXI,WAAW;EACXC,QAAQ;EAERC,eAAe;EACfC,kBAAkB;EAElBC;AACF,CAAC,GAAGR,UAAU;AAACS,OAAA,CAAAD,YAAA,GAAAA,YAAA;AAAAC,OAAA,CAAAF,kBAAA,GAAAA,kBAAA;AAAAE,OAAA,CAAAH,eAAA,GAAAA,eAAA;AAAAG,OAAA,CAAAJ,QAAA,GAAAA,QAAA;AAAAI,OAAA,CAAAL,WAAA,GAAAA,WAAA","ignoreList":[]}
@@ -1,12 +0,0 @@
1
- "use strict";
2
-
3
- import { NativeModules } from "react-native";
4
- const MLRNModule = Object.create(NativeModules.MLRNModule);
5
- export const {
6
- StyleSource,
7
- StyleURL,
8
- addCustomHeader,
9
- removeCustomHeader,
10
- setConnected
11
- } = MLRNModule;
12
- //# sourceMappingURL=MLRNModule.js.map
@@ -1 +0,0 @@
1
- {"version":3,"names":["NativeModules","MLRNModule","Object","create","StyleSource","StyleURL","addCustomHeader","removeCustomHeader","setConnected"],"sourceRoot":"../../src","sources":["MLRNModule.ts"],"mappings":";;AAAA,SAASA,aAAa,QAAQ,cAAc;AAiB5C,MAAMC,UAAuB,GAAGC,MAAM,CAACC,MAAM,CAACH,aAAa,CAACC,UAAU,CAAC;AAEvE,OAAO,MAAM;EACXG,WAAW;EACXC,QAAQ;EAERC,eAAe;EACfC,kBAAkB;EAElBC;AACF,CAAC,GAAGP,UAAU","ignoreList":[]}
@@ -1,6 +0,0 @@
1
- export declare const StyleSource: {
2
- DefaultSourceID: string;
3
- }, StyleURL: {
4
- Default: string;
5
- }, addCustomHeader: (headerName: string, headerValue: string) => void, removeCustomHeader: (headerName: string) => void, setConnected: (connected: boolean) => void;
6
- //# sourceMappingURL=MLRNModule.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"MLRNModule.d.ts","sourceRoot":"","sources":["../../../../src/MLRNModule.ts"],"names":[],"mappings":"AAmBA,eAAO,MACL,WAAW;qBAhBQ,MAAM;GAiBzB,QAAQ;aAbG,MAAM;GAejB,eAAe,eAZa,MAAM,eAAe,MAAM,KAAG,IAAI,EAa9D,kBAAkB,eAZa,MAAM,KAAG,IAAI,EAc5C,YAAY,cAZY,OAAO,KAAG,IAatB,CAAC"}
@@ -1,6 +0,0 @@
1
- export declare const StyleSource: {
2
- DefaultSourceID: string;
3
- }, StyleURL: {
4
- Default: string;
5
- }, addCustomHeader: (headerName: string, headerValue: string) => void, removeCustomHeader: (headerName: string) => void, setConnected: (connected: boolean) => void;
6
- //# sourceMappingURL=MLRNModule.d.ts.map