@maplibre/maplibre-react-native 11.0.0-alpha.16 → 11.0.0-alpha.18
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/android/src/main/java/org/maplibre/reactnative/MLRNPackage.kt +6 -6
- package/android/src/main/java/org/maplibre/reactnative/components/camera/MLRNCameraManager.kt +3 -5
- package/android/src/main/java/org/maplibre/reactnative/components/location/LocationComponentManager.kt +154 -0
- package/android/src/main/java/org/maplibre/reactnative/components/location/MLRNNativeUserLocation.kt +70 -0
- package/android/src/main/java/org/maplibre/reactnative/components/location/MLRNNativeUserLocationManager.kt +50 -0
- package/android/src/main/java/org/maplibre/reactnative/modules/MLRNLocationModule.kt +20 -4
- package/android/src/main/java/org/maplibre/reactnative/modules/MLRNLogModule.kt +99 -0
- package/ios/components/camera/MLRNCameraComponentView.h +0 -8
- package/ios/components/map-view/MLRNMapView.m +1 -1
- package/ios/components/map-view/MLRNMapViewComponentView.h +0 -5
- package/ios/components/user-location/MLRNNativeUserLocation.h +1 -1
- package/ios/components/user-location/MLRNNativeUserLocation.m +6 -5
- package/ios/components/user-location/MLRNNativeUserLocationComponentView.h +10 -0
- package/ios/components/user-location/MLRNNativeUserLocationComponentView.mm +51 -0
- package/ios/modules/location/MLRNLocation.m +17 -14
- package/ios/modules/logging/MLRNLogModule.h +10 -0
- package/ios/modules/logging/MLRNLogModule.mm +39 -0
- package/ios/modules/logging/MLRNLogging.h +15 -7
- package/ios/modules/logging/MLRNLogging.m +22 -55
- package/lib/commonjs/components/annotations/Annotation.js +2 -1
- package/lib/commonjs/components/annotations/Annotation.js.map +1 -1
- package/lib/commonjs/components/map-view/MapView.js +3 -3
- package/lib/commonjs/components/map-view/MapView.js.map +1 -1
- package/lib/commonjs/components/sources/ShapeSource.js +1 -0
- package/lib/commonjs/components/sources/ShapeSource.js.map +1 -1
- package/lib/commonjs/components/user-location/NativeUserLocation.js +3 -4
- package/lib/commonjs/components/user-location/NativeUserLocation.js.map +1 -1
- package/lib/commonjs/components/user-location/UserLocation.js +22 -132
- package/lib/commonjs/components/user-location/UserLocation.js.map +1 -1
- package/lib/commonjs/components/user-location/UserLocationNativeComponent.ts +19 -0
- package/lib/commonjs/components/user-location/UserLocationPuck.js +34 -22
- package/lib/commonjs/components/user-location/UserLocationPuck.js.map +1 -1
- package/lib/commonjs/components/user-location/UserLocationPuckHeading.js +3 -2
- package/lib/commonjs/components/user-location/UserLocationPuckHeading.js.map +1 -1
- package/lib/commonjs/hooks/useCurrentPosition.js +34 -0
- package/lib/commonjs/hooks/useCurrentPosition.js.map +1 -0
- package/lib/commonjs/index.js +16 -15
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/modules/log/LogManager.js +99 -0
- package/lib/commonjs/modules/log/LogManager.js.map +1 -0
- package/lib/commonjs/modules/log/NativeLogModule.js +9 -0
- package/lib/commonjs/modules/log/NativeLogModule.js.map +1 -0
- package/lib/commonjs/utils/animated/Animated.js +1 -7
- package/lib/commonjs/utils/animated/Animated.js.map +1 -1
- package/lib/module/components/annotations/Annotation.js +3 -2
- package/lib/module/components/annotations/Annotation.js.map +1 -1
- package/lib/module/components/map-view/MapView.js +3 -3
- package/lib/module/components/map-view/MapView.js.map +1 -1
- package/lib/module/components/sources/ShapeSource.js +1 -0
- package/lib/module/components/sources/ShapeSource.js.map +1 -1
- package/lib/module/components/user-location/NativeUserLocation.js +2 -4
- package/lib/module/components/user-location/NativeUserLocation.js.map +1 -1
- package/lib/module/components/user-location/UserLocation.js +22 -132
- package/lib/module/components/user-location/UserLocation.js.map +1 -1
- package/lib/module/components/user-location/UserLocationNativeComponent.ts +19 -0
- package/lib/module/components/user-location/UserLocationPuck.js +34 -22
- package/lib/module/components/user-location/UserLocationPuck.js.map +1 -1
- package/lib/module/components/user-location/UserLocationPuckHeading.js +3 -2
- package/lib/module/components/user-location/UserLocationPuckHeading.js.map +1 -1
- package/lib/module/hooks/useCurrentPosition.js +30 -0
- package/lib/module/hooks/useCurrentPosition.js.map +1 -0
- package/lib/module/index.js +4 -3
- package/lib/module/index.js.map +1 -1
- package/lib/module/modules/log/LogManager.js +96 -0
- package/lib/module/modules/log/LogManager.js.map +1 -0
- package/lib/module/modules/log/NativeLogModule.js +5 -0
- package/lib/module/modules/log/NativeLogModule.js.map +1 -0
- package/lib/module/utils/animated/Animated.js +0 -6
- package/lib/module/utils/animated/Animated.js.map +1 -1
- package/lib/typescript/commonjs/src/components/annotations/Annotation.d.ts +3 -2
- package/lib/typescript/commonjs/src/components/annotations/Annotation.d.ts.map +1 -1
- package/lib/typescript/commonjs/src/components/sources/ShapeSource.d.ts.map +1 -1
- package/lib/typescript/commonjs/src/components/user-location/NativeUserLocation.d.ts +12 -13
- package/lib/typescript/commonjs/src/components/user-location/NativeUserLocation.d.ts.map +1 -1
- package/lib/typescript/commonjs/src/components/user-location/UserLocation.d.ts +13 -53
- package/lib/typescript/commonjs/src/components/user-location/UserLocation.d.ts.map +1 -1
- package/lib/typescript/commonjs/src/components/user-location/UserLocationNativeComponent.d.ts +8 -0
- package/lib/typescript/commonjs/src/components/user-location/UserLocationNativeComponent.d.ts.map +1 -0
- package/lib/typescript/commonjs/src/components/user-location/UserLocationPuck.d.ts +2 -1
- package/lib/typescript/commonjs/src/components/user-location/UserLocationPuck.d.ts.map +1 -1
- package/lib/typescript/commonjs/src/components/user-location/UserLocationPuckHeading.d.ts.map +1 -1
- package/lib/typescript/commonjs/src/hooks/useCurrentPosition.d.ts +18 -0
- package/lib/typescript/commonjs/src/hooks/useCurrentPosition.d.ts.map +1 -0
- package/lib/typescript/commonjs/src/index.d.ts +4 -4
- package/lib/typescript/commonjs/src/index.d.ts.map +1 -1
- package/lib/typescript/commonjs/src/modules/location/LocationManager.d.ts +3 -3
- package/lib/typescript/commonjs/src/modules/location/LocationManager.d.ts.map +1 -1
- package/lib/typescript/commonjs/src/modules/location/NativeLocationModule.d.ts +3 -3
- package/lib/typescript/commonjs/src/modules/location/NativeLocationModule.d.ts.map +1 -1
- package/lib/typescript/commonjs/src/modules/log/LogManager.d.ts +45 -0
- package/lib/typescript/commonjs/src/modules/log/LogManager.d.ts.map +1 -0
- package/lib/typescript/commonjs/src/modules/log/NativeLogModule.d.ts +13 -0
- package/lib/typescript/commonjs/src/modules/log/NativeLogModule.d.ts.map +1 -0
- package/lib/typescript/commonjs/src/utils/animated/Animated.d.ts +1 -13
- package/lib/typescript/commonjs/src/utils/animated/Animated.d.ts.map +1 -1
- package/lib/typescript/module/src/components/annotations/Annotation.d.ts +3 -2
- package/lib/typescript/module/src/components/annotations/Annotation.d.ts.map +1 -1
- package/lib/typescript/module/src/components/sources/ShapeSource.d.ts.map +1 -1
- package/lib/typescript/module/src/components/user-location/NativeUserLocation.d.ts +12 -13
- package/lib/typescript/module/src/components/user-location/NativeUserLocation.d.ts.map +1 -1
- package/lib/typescript/module/src/components/user-location/UserLocation.d.ts +13 -53
- package/lib/typescript/module/src/components/user-location/UserLocation.d.ts.map +1 -1
- package/lib/typescript/module/src/components/user-location/UserLocationNativeComponent.d.ts +8 -0
- package/lib/typescript/module/src/components/user-location/UserLocationNativeComponent.d.ts.map +1 -0
- package/lib/typescript/module/src/components/user-location/UserLocationPuck.d.ts +2 -1
- package/lib/typescript/module/src/components/user-location/UserLocationPuck.d.ts.map +1 -1
- package/lib/typescript/module/src/components/user-location/UserLocationPuckHeading.d.ts.map +1 -1
- package/lib/typescript/module/src/hooks/useCurrentPosition.d.ts +18 -0
- package/lib/typescript/module/src/hooks/useCurrentPosition.d.ts.map +1 -0
- package/lib/typescript/module/src/index.d.ts +4 -4
- package/lib/typescript/module/src/index.d.ts.map +1 -1
- package/lib/typescript/module/src/modules/location/LocationManager.d.ts +3 -3
- package/lib/typescript/module/src/modules/location/LocationManager.d.ts.map +1 -1
- package/lib/typescript/module/src/modules/location/NativeLocationModule.d.ts +3 -3
- package/lib/typescript/module/src/modules/location/NativeLocationModule.d.ts.map +1 -1
- package/lib/typescript/module/src/modules/log/LogManager.d.ts +45 -0
- package/lib/typescript/module/src/modules/log/LogManager.d.ts.map +1 -0
- package/lib/typescript/module/src/modules/log/NativeLogModule.d.ts +13 -0
- package/lib/typescript/module/src/modules/log/NativeLogModule.d.ts.map +1 -0
- package/lib/typescript/module/src/utils/animated/Animated.d.ts +1 -13
- package/lib/typescript/module/src/utils/animated/Animated.d.ts.map +1 -1
- package/package.json +4 -2
- package/src/components/annotations/Annotation.tsx +7 -5
- package/src/components/map-view/MapView.tsx +3 -3
- package/src/components/sources/ShapeSource.tsx +1 -0
- package/src/components/user-location/NativeUserLocation.tsx +15 -19
- package/src/components/user-location/UserLocation.tsx +65 -249
- package/src/components/user-location/UserLocationNativeComponent.ts +19 -0
- package/src/components/user-location/UserLocationPuck.tsx +47 -28
- package/src/components/user-location/UserLocationPuckHeading.tsx +2 -1
- package/src/hooks/useCurrentPosition.ts +53 -0
- package/src/index.ts +6 -7
- package/src/modules/location/LocationManager.ts +3 -3
- package/src/modules/location/NativeLocationModule.ts +3 -3
- package/src/modules/log/LogManager.ts +114 -0
- package/src/modules/log/NativeLogModule.ts +16 -0
- package/src/utils/animated/Animated.ts +1 -28
- package/android/src/main/java/org/maplibre/reactnative/components/location/LocationComponentManager.java +0 -165
- package/android/src/main/java/org/maplibre/reactnative/components/location/MLRNNativeUserLocation.java +0 -76
- package/android/src/main/java/org/maplibre/reactnative/components/location/MLRNNativeUserLocationManager.java +0 -40
- package/android/src/main/java/org/maplibre/reactnative/modules/MLRNLogging.java +0 -140
- package/ios/components/user-location/MLRNNativeUserLocationManager.h +0 -5
- package/ios/components/user-location/MLRNNativeUserLocationManager.m +0 -21
- package/lib/commonjs/modules/Logger.js +0 -112
- package/lib/commonjs/modules/Logger.js.map +0 -1
- package/lib/commonjs/modules/location/requestAndroidLocationPermissions.js +0 -14
- package/lib/commonjs/modules/location/requestAndroidLocationPermissions.js.map +0 -1
- package/lib/module/modules/Logger.js +0 -107
- package/lib/module/modules/Logger.js.map +0 -1
- package/lib/module/modules/location/requestAndroidLocationPermissions.js +0 -11
- package/lib/module/modules/location/requestAndroidLocationPermissions.js.map +0 -1
- package/lib/typescript/commonjs/src/modules/Logger.d.ts +0 -49
- package/lib/typescript/commonjs/src/modules/Logger.d.ts.map +0 -1
- package/lib/typescript/commonjs/src/modules/location/requestAndroidLocationPermissions.d.ts +0 -5
- package/lib/typescript/commonjs/src/modules/location/requestAndroidLocationPermissions.d.ts.map +0 -1
- package/lib/typescript/module/src/modules/Logger.d.ts +0 -49
- package/lib/typescript/module/src/modules/Logger.d.ts.map +0 -1
- package/lib/typescript/module/src/modules/location/requestAndroidLocationPermissions.d.ts +0 -5
- package/lib/typescript/module/src/modules/location/requestAndroidLocationPermissions.d.ts.map +0 -1
- package/src/modules/Logger.ts +0 -127
- package/src/modules/location/requestAndroidLocationPermissions.ts +0 -8
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
import { type EventSubscription } from "react-native";
|
|
2
|
+
|
|
3
|
+
import NativeLogModule from "./NativeLogModule";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Log levels in decreasing order of severity
|
|
7
|
+
*/
|
|
8
|
+
export type LogLevel = "error" | "warn" | "info" | "debug" | "verbose";
|
|
9
|
+
|
|
10
|
+
interface LogEvent {
|
|
11
|
+
level: LogLevel;
|
|
12
|
+
tag: string;
|
|
13
|
+
message: string;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Handler for `onLog` events
|
|
18
|
+
*
|
|
19
|
+
* Called before logging a message, return false to proceed with default logging.
|
|
20
|
+
*
|
|
21
|
+
* @param event
|
|
22
|
+
*/
|
|
23
|
+
type LogHandler = (event: LogEvent) => boolean;
|
|
24
|
+
|
|
25
|
+
class LogManager {
|
|
26
|
+
private logLevel: LogLevel = "warn";
|
|
27
|
+
private startedCount: number = 0;
|
|
28
|
+
private logHandler: LogHandler | undefined = undefined;
|
|
29
|
+
private subscription: EventSubscription | undefined = undefined;
|
|
30
|
+
|
|
31
|
+
constructor() {
|
|
32
|
+
this.handleLog = this.handleLog.bind(this);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Override logging behavior
|
|
37
|
+
*
|
|
38
|
+
* @param logHandler
|
|
39
|
+
*/
|
|
40
|
+
onLog(logHandler: LogHandler): void {
|
|
41
|
+
this.logHandler = logHandler;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Set the minimum log level for a message to be logged
|
|
46
|
+
*
|
|
47
|
+
* @param level Minimum log level
|
|
48
|
+
*/
|
|
49
|
+
setLogLevel(level: LogLevel): void {
|
|
50
|
+
this.logLevel = level;
|
|
51
|
+
NativeLogModule.setLogLevel(level);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
start(): void {
|
|
55
|
+
if (this.startedCount === 0) {
|
|
56
|
+
this.subscribe();
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
this.startedCount += 1;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
stop(): void {
|
|
63
|
+
this.startedCount -= 1;
|
|
64
|
+
|
|
65
|
+
if (this.startedCount === 0) {
|
|
66
|
+
this.unsubscribe();
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
private subscribe(): void {
|
|
71
|
+
this.subscription = NativeLogModule.onLog(this.handleLog);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
private unsubscribe(): void {
|
|
75
|
+
if (this.subscription) {
|
|
76
|
+
this.subscription.remove();
|
|
77
|
+
this.subscription = undefined;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
private effectiveLevel({ level, message, tag }: LogEvent): LogLevel {
|
|
82
|
+
// Reduce level of cancelled HTTP requests from warn to info
|
|
83
|
+
if (
|
|
84
|
+
level === "warn" &&
|
|
85
|
+
tag === "Mbgl-HttpRequest" &&
|
|
86
|
+
message.startsWith("Request failed due to a permanent error: Canceled")
|
|
87
|
+
) {
|
|
88
|
+
return "info";
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
return level;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
private handleLog(log: LogEvent): void {
|
|
95
|
+
if (!this.logHandler || !this.logHandler(log)) {
|
|
96
|
+
const { message, tag } = log;
|
|
97
|
+
const level = this.effectiveLevel(log);
|
|
98
|
+
|
|
99
|
+
const consoleMessage = `MapLibre Native [${level.toUpperCase()}] [${tag}] ${message}`;
|
|
100
|
+
|
|
101
|
+
if (level === "error") {
|
|
102
|
+
console.error(consoleMessage);
|
|
103
|
+
} else if (level === "warn" && this.logLevel !== "error") {
|
|
104
|
+
console.warn(consoleMessage);
|
|
105
|
+
} else if (this.logLevel !== "error" && this.logLevel !== "warn") {
|
|
106
|
+
console.info(consoleMessage);
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
const logManager = new LogManager();
|
|
113
|
+
|
|
114
|
+
export { logManager as LogManager };
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { TurboModule, CodegenTypes } from "react-native";
|
|
2
|
+
import { TurboModuleRegistry } from "react-native";
|
|
3
|
+
|
|
4
|
+
type NativeLogLevel = "error" | "warn" | "info" | "debug" | "verbose";
|
|
5
|
+
|
|
6
|
+
export interface Spec extends TurboModule {
|
|
7
|
+
setLogLevel(logLevel: NativeLogLevel): void;
|
|
8
|
+
|
|
9
|
+
readonly onLog: CodegenTypes.EventEmitter<{
|
|
10
|
+
level: NativeLogLevel;
|
|
11
|
+
tag: string;
|
|
12
|
+
message: string;
|
|
13
|
+
}>;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export default TurboModuleRegistry.getEnforcing<Spec>("MLRNLogModule");
|
|
@@ -1,8 +1,3 @@
|
|
|
1
|
-
import {
|
|
2
|
-
type ForwardRefExoticComponent,
|
|
3
|
-
type MemoExoticComponent,
|
|
4
|
-
type RefAttributes,
|
|
5
|
-
} from "react";
|
|
6
1
|
import { Animated as RNAnimated } from "react-native";
|
|
7
2
|
|
|
8
3
|
import { AnimatedCoordinatesArray } from "./AnimatedCoordinatesArray";
|
|
@@ -17,11 +12,7 @@ import { LineLayer } from "../../components/layers/LineLayer";
|
|
|
17
12
|
import { RasterLayer } from "../../components/layers/RasterLayer";
|
|
18
13
|
import { SymbolLayer } from "../../components/layers/SymbolLayer";
|
|
19
14
|
import { ImageSource } from "../../components/sources/ImageSource";
|
|
20
|
-
import {
|
|
21
|
-
ShapeSource,
|
|
22
|
-
type ShapeSourceProps,
|
|
23
|
-
type ShapeSourceRef,
|
|
24
|
-
} from "../../components/sources/ShapeSource";
|
|
15
|
+
import { ShapeSource } from "../../components/sources/ShapeSource";
|
|
25
16
|
|
|
26
17
|
export const Animated = {
|
|
27
18
|
// sources
|
|
@@ -43,21 +34,3 @@ export const Animated = {
|
|
|
43
34
|
Shape: AnimatedShape,
|
|
44
35
|
ExtractCoordinateFromArray: AnimatedExtractCoordinateFromArray,
|
|
45
36
|
};
|
|
46
|
-
|
|
47
|
-
type ShapeSourcePropsWithRef = ShapeSourceProps & RefAttributes<ShapeSourceRef>;
|
|
48
|
-
|
|
49
|
-
type BaseShapeSourceComponent =
|
|
50
|
-
ForwardRefExoticComponent<ShapeSourcePropsWithRef>;
|
|
51
|
-
|
|
52
|
-
type AnimatedShapeSourceType =
|
|
53
|
-
RNAnimated.AnimatedComponent<BaseShapeSourceComponent> &
|
|
54
|
-
MemoExoticComponent<BaseShapeSourceComponent>;
|
|
55
|
-
|
|
56
|
-
/**
|
|
57
|
-
* Manual typing is required for AnimatedShapeSource because the
|
|
58
|
-
* following error:
|
|
59
|
-
* `Type instantiation is excessively deep and possibly infinite.ts(2589)`
|
|
60
|
-
*/
|
|
61
|
-
export const AnimatedShapeSource = RNAnimated.createAnimatedComponent(
|
|
62
|
-
ShapeSource,
|
|
63
|
-
) as AnimatedShapeSourceType;
|
|
@@ -1,165 +0,0 @@
|
|
|
1
|
-
package org.maplibre.reactnative.components.location;
|
|
2
|
-
|
|
3
|
-
import android.annotation.SuppressLint;
|
|
4
|
-
import android.content.Context;
|
|
5
|
-
|
|
6
|
-
import org.maplibre.android.location.LocationComponent;
|
|
7
|
-
import org.maplibre.android.location.LocationComponentActivationOptions;
|
|
8
|
-
import org.maplibre.android.location.LocationComponentOptions;
|
|
9
|
-
import org.maplibre.android.location.OnCameraTrackingChangedListener;
|
|
10
|
-
import org.maplibre.android.location.modes.CameraMode;
|
|
11
|
-
import org.maplibre.android.location.modes.RenderMode;
|
|
12
|
-
import org.maplibre.android.maps.MapLibreMap;
|
|
13
|
-
import org.maplibre.android.maps.Style;
|
|
14
|
-
import org.maplibre.reactnative.R;
|
|
15
|
-
import org.maplibre.reactnative.components.mapview.MLRNMapView;
|
|
16
|
-
import org.maplibre.reactnative.location.LocationManager;
|
|
17
|
-
|
|
18
|
-
import androidx.annotation.NonNull;
|
|
19
|
-
|
|
20
|
-
/**
|
|
21
|
-
* The LocationComponent on android implements both location tracking and display of user's current location.
|
|
22
|
-
* LocationComponentManager attempts to separate that, so that Camera can ask for location tracking independent of display of user current location.
|
|
23
|
-
* And NativeUserLocation can ask for display of user's current location - independent of Camera's user tracking.
|
|
24
|
-
*/
|
|
25
|
-
public class LocationComponentManager {
|
|
26
|
-
private MLRNMapView mMapView = null;
|
|
27
|
-
private MapLibreMap mMap = null;
|
|
28
|
-
|
|
29
|
-
private LocationManager mLocationManager = null;
|
|
30
|
-
private LocationComponent mLocationComponent = null;
|
|
31
|
-
private Context mContext = null;
|
|
32
|
-
|
|
33
|
-
private @RenderMode.Mode int mRenderMode = RenderMode.COMPASS;
|
|
34
|
-
|
|
35
|
-
public LocationComponentManager(MLRNMapView mlrnMapView, Context context) {
|
|
36
|
-
mMapView = mlrnMapView;
|
|
37
|
-
mMap = mMapView.getMapLibreMap();
|
|
38
|
-
mContext = context;
|
|
39
|
-
|
|
40
|
-
mLocationManager = LocationManager.getInstance(context);
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
private boolean mShowUserLocation = false;
|
|
44
|
-
|
|
45
|
-
private boolean mFollowUserLocation = false;
|
|
46
|
-
|
|
47
|
-
private boolean mShowingUserLocation = false;
|
|
48
|
-
|
|
49
|
-
private OnCameraTrackingChangedListener mOnCameraTrackingChangedListener = null;
|
|
50
|
-
|
|
51
|
-
public void showUserLocation(boolean showUserLocation) {
|
|
52
|
-
mShowUserLocation = showUserLocation;
|
|
53
|
-
stateChanged();
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
public void setFollowUserLocation(boolean followUserLocation) {
|
|
57
|
-
mFollowUserLocation = followUserLocation;
|
|
58
|
-
stateChanged();
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
public void setCameraMode(@CameraMode.Mode int cameraMode) {
|
|
62
|
-
mLocationComponent.setCameraMode(cameraMode);
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
public void setRenderMode(@RenderMode.Mode int renderMode) {
|
|
66
|
-
mRenderMode = renderMode;
|
|
67
|
-
if (mShowingUserLocation) {
|
|
68
|
-
mLocationComponent.setRenderMode(renderMode);
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
public void setPreferredFramesPerSecond(int preferredFramesPerSecond) {
|
|
73
|
-
if (mLocationComponent == null || preferredFramesPerSecond <= 0) {
|
|
74
|
-
return;
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
mLocationComponent.setMaxAnimationFps(preferredFramesPerSecond);
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
public void addOnCameraTrackingChangedListener(OnCameraTrackingChangedListener onCameraTrackingChangedListener) {
|
|
81
|
-
if (mOnCameraTrackingChangedListener != null) {
|
|
82
|
-
mLocationComponent.removeOnCameraTrackingChangedListener(mOnCameraTrackingChangedListener);
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
mOnCameraTrackingChangedListener = onCameraTrackingChangedListener;
|
|
86
|
-
|
|
87
|
-
mLocationComponent.addOnCameraTrackingChangedListener(mOnCameraTrackingChangedListener);
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
@SuppressLint("MissingPermission")
|
|
91
|
-
private void stateChanged() {
|
|
92
|
-
mLocationComponent.setLocationComponentEnabled((mFollowUserLocation || mShowUserLocation));
|
|
93
|
-
|
|
94
|
-
if (mShowingUserLocation != mShowUserLocation) {
|
|
95
|
-
updateShowUserLocation(mShowUserLocation);
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
if (mFollowUserLocation) {
|
|
99
|
-
if (!mShowUserLocation) {
|
|
100
|
-
mLocationComponent.setRenderMode(RenderMode.GPS);
|
|
101
|
-
} else {
|
|
102
|
-
mLocationComponent.setRenderMode(mRenderMode);
|
|
103
|
-
}
|
|
104
|
-
mLocationComponent.onStart();
|
|
105
|
-
} else {
|
|
106
|
-
mLocationComponent.setCameraMode(CameraMode.NONE);
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
public boolean hasLocationComponent() {
|
|
111
|
-
return (mLocationComponent != null);
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
public void update(@NonNull Style style) {
|
|
115
|
-
update(mShowUserLocation, style);
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
public void update(boolean displayUserLocation, @NonNull Style style) {
|
|
119
|
-
Integer tintColor = mMapView.getTintColor();
|
|
120
|
-
|
|
121
|
-
if (mLocationComponent == null || tintColor != null) {
|
|
122
|
-
mLocationComponent = mMap.getLocationComponent();
|
|
123
|
-
|
|
124
|
-
LocationComponentActivationOptions locationComponentActivationOptions = LocationComponentActivationOptions
|
|
125
|
-
.builder(mContext, style)
|
|
126
|
-
.locationComponentOptions(options(displayUserLocation))
|
|
127
|
-
.build();
|
|
128
|
-
mLocationComponent.activateLocationComponent(locationComponentActivationOptions);
|
|
129
|
-
mLocationComponent.setLocationEngine(mLocationManager.getEngine());
|
|
130
|
-
mShowingUserLocation = displayUserLocation;
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
updateShowUserLocation(displayUserLocation);
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
private void updateShowUserLocation(boolean displayUserLocation) {
|
|
137
|
-
if (mShowingUserLocation != displayUserLocation) {
|
|
138
|
-
mLocationComponent.applyStyle(options(displayUserLocation));
|
|
139
|
-
mShowingUserLocation = displayUserLocation;
|
|
140
|
-
}
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
LocationComponentOptions options(boolean displayUserLocation) {
|
|
144
|
-
LocationComponentOptions.Builder builder = LocationComponentOptions.builder(mContext);
|
|
145
|
-
Integer tintColor = mMapView.getTintColor();
|
|
146
|
-
if (!displayUserLocation) {
|
|
147
|
-
builder = builder
|
|
148
|
-
.padding(mMap.getPadding())
|
|
149
|
-
.backgroundDrawable(R.drawable.empty)
|
|
150
|
-
.backgroundDrawableStale(R.drawable.empty)
|
|
151
|
-
.bearingDrawable(R.drawable.empty)
|
|
152
|
-
.foregroundDrawable(R.drawable.empty)
|
|
153
|
-
.foregroundDrawableStale(R.drawable.empty)
|
|
154
|
-
.gpsDrawable(R.drawable.empty)
|
|
155
|
-
.accuracyAlpha(0.0f);
|
|
156
|
-
} else if (tintColor != null) {
|
|
157
|
-
builder = builder
|
|
158
|
-
.enableStaleState(false)
|
|
159
|
-
.bearingTintColor(tintColor)
|
|
160
|
-
.foregroundTintColor(tintColor)
|
|
161
|
-
.accuracyColor(tintColor);
|
|
162
|
-
}
|
|
163
|
-
return builder.build();
|
|
164
|
-
}
|
|
165
|
-
}
|
|
@@ -1,76 +0,0 @@
|
|
|
1
|
-
package org.maplibre.reactnative.components.location;
|
|
2
|
-
|
|
3
|
-
import android.annotation.SuppressLint;
|
|
4
|
-
import android.content.Context;
|
|
5
|
-
import androidx.annotation.NonNull;
|
|
6
|
-
|
|
7
|
-
import org.maplibre.android.location.permissions.PermissionsManager;
|
|
8
|
-
import org.maplibre.android.location.modes.RenderMode;
|
|
9
|
-
import org.maplibre.android.maps.MapLibreMap;
|
|
10
|
-
import org.maplibre.android.maps.OnMapReadyCallback;
|
|
11
|
-
import org.maplibre.android.maps.Style;
|
|
12
|
-
import org.maplibre.reactnative.components.AbstractMapFeature;
|
|
13
|
-
import org.maplibre.reactnative.components.mapview.MLRNMapView;
|
|
14
|
-
|
|
15
|
-
public class MLRNNativeUserLocation extends AbstractMapFeature implements OnMapReadyCallback, Style.OnStyleLoaded {
|
|
16
|
-
private boolean mEnabled = true;
|
|
17
|
-
private MapLibreMap mMap;
|
|
18
|
-
private MLRNMapView mMapView;
|
|
19
|
-
private @RenderMode.Mode int mRenderMode = RenderMode.COMPASS;
|
|
20
|
-
private int mPreferredFramesPerSecond;
|
|
21
|
-
|
|
22
|
-
public MLRNNativeUserLocation(Context context) {
|
|
23
|
-
super(context);
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
@Override
|
|
27
|
-
public void addToMap(MLRNMapView mapView) {
|
|
28
|
-
mEnabled = true;
|
|
29
|
-
mMapView = mapView;
|
|
30
|
-
mapView.getMapAsync(this);
|
|
31
|
-
setRenderMode(mRenderMode);
|
|
32
|
-
setPreferredFramesPerSecond(mPreferredFramesPerSecond);
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
@Override
|
|
36
|
-
public void removeFromMap(MLRNMapView mapView) {
|
|
37
|
-
mEnabled = false;
|
|
38
|
-
if (mMap != null) mMap.getStyle(this);
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
@SuppressLint("MissingPermission")
|
|
42
|
-
@Override
|
|
43
|
-
public void onMapReady(@NonNull MapLibreMap mapboxMap) {
|
|
44
|
-
mMap = mapboxMap;
|
|
45
|
-
mapboxMap.getStyle(this);
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
@SuppressLint("MissingPermission")
|
|
49
|
-
@Override
|
|
50
|
-
public void onStyleLoaded(@NonNull Style style) {
|
|
51
|
-
Context context = getContext();
|
|
52
|
-
if (!PermissionsManager.areLocationPermissionsGranted(context)) {
|
|
53
|
-
return;
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
LocationComponentManager locationComponent = mMapView.getLocationComponentManager();
|
|
57
|
-
locationComponent.update(style);
|
|
58
|
-
locationComponent.showUserLocation(mEnabled);
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
public void setRenderMode(@RenderMode.Mode int renderMode) {
|
|
62
|
-
mRenderMode = renderMode;
|
|
63
|
-
if (mMapView != null) {
|
|
64
|
-
LocationComponentManager locationComponent = mMapView.getLocationComponentManager();
|
|
65
|
-
locationComponent.setRenderMode(renderMode);
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
public void setPreferredFramesPerSecond(int framesPerSecond) {
|
|
70
|
-
mPreferredFramesPerSecond = framesPerSecond;
|
|
71
|
-
if (mMapView != null) {
|
|
72
|
-
LocationComponentManager locationComponent = mMapView.getLocationComponentManager();
|
|
73
|
-
locationComponent.setPreferredFramesPerSecond(framesPerSecond);
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
}
|
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
package org.maplibre.reactnative.components.location;
|
|
2
|
-
|
|
3
|
-
import com.facebook.react.uimanager.ThemedReactContext;
|
|
4
|
-
import com.facebook.react.uimanager.ViewGroupManager;
|
|
5
|
-
import com.facebook.react.uimanager.annotations.ReactProp;
|
|
6
|
-
import org.maplibre.android.location.modes.RenderMode;
|
|
7
|
-
|
|
8
|
-
import javax.annotation.Nonnull;
|
|
9
|
-
|
|
10
|
-
public class MLRNNativeUserLocationManager extends ViewGroupManager<MLRNNativeUserLocation> {
|
|
11
|
-
public static final String REACT_CLASS = "MLRNNativeUserLocation";
|
|
12
|
-
|
|
13
|
-
@Nonnull
|
|
14
|
-
@Override
|
|
15
|
-
public String getName() {
|
|
16
|
-
return REACT_CLASS;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
@ReactProp(name="androidRenderMode")
|
|
20
|
-
public void setAndroidRenderMode(MLRNNativeUserLocation userLocation, String mode) {
|
|
21
|
-
if ("compass".equalsIgnoreCase(mode)) {
|
|
22
|
-
userLocation.setRenderMode(RenderMode.COMPASS);
|
|
23
|
-
} else if ("gps".equalsIgnoreCase(mode)) {
|
|
24
|
-
userLocation.setRenderMode(RenderMode.GPS);
|
|
25
|
-
} else {
|
|
26
|
-
userLocation.setRenderMode(RenderMode.NORMAL);
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
@ReactProp(name="androidPreferredFramesPerSecond")
|
|
31
|
-
public void setPreferredFramesPerSecond(MLRNNativeUserLocation userLocation, int preferredFramesPerSecond) {
|
|
32
|
-
userLocation.setPreferredFramesPerSecond(preferredFramesPerSecond);
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
@Nonnull
|
|
36
|
-
@Override
|
|
37
|
-
protected MLRNNativeUserLocation createViewInstance(@Nonnull ThemedReactContext reactContext) {
|
|
38
|
-
return new MLRNNativeUserLocation(reactContext);
|
|
39
|
-
}
|
|
40
|
-
}
|
|
@@ -1,140 +0,0 @@
|
|
|
1
|
-
package org.maplibre.reactnative.modules;
|
|
2
|
-
|
|
3
|
-
import com.facebook.react.bridge.Arguments;
|
|
4
|
-
import com.facebook.react.bridge.ReactApplicationContext;
|
|
5
|
-
import com.facebook.react.bridge.ReactContextBaseJavaModule;
|
|
6
|
-
import com.facebook.react.bridge.ReactMethod;
|
|
7
|
-
import com.facebook.react.bridge.WritableMap;
|
|
8
|
-
import com.facebook.react.module.annotations.ReactModule;
|
|
9
|
-
import com.facebook.react.modules.core.DeviceEventManagerModule;
|
|
10
|
-
import org.maplibre.android.log.Logger;
|
|
11
|
-
import org.maplibre.android.log.LoggerDefinition;
|
|
12
|
-
import android.util.Log;
|
|
13
|
-
|
|
14
|
-
@ReactModule(name = MLRNLogging.REACT_CLASS)
|
|
15
|
-
public class MLRNLogging extends ReactContextBaseJavaModule {
|
|
16
|
-
public static final String REACT_CLASS = "MLRNLogging";
|
|
17
|
-
private ReactApplicationContext mReactContext;
|
|
18
|
-
|
|
19
|
-
public MLRNLogging(ReactApplicationContext reactApplicationContext) {
|
|
20
|
-
super(reactApplicationContext);
|
|
21
|
-
mReactContext = reactApplicationContext;
|
|
22
|
-
|
|
23
|
-
Logger.setVerbosity(Logger.WARN);
|
|
24
|
-
Logger.setLoggerDefinition(new LoggerDefinition() {
|
|
25
|
-
@Override
|
|
26
|
-
public void v(String tag, String msg) {
|
|
27
|
-
Log.v(tag, msg);
|
|
28
|
-
onLog("verbose", tag, msg, null);
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
@Override
|
|
32
|
-
public void v(String tag, String msg, Throwable tr) {
|
|
33
|
-
Log.v(tag, msg, tr);
|
|
34
|
-
onLog("verbose", tag, msg, tr);
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
@Override
|
|
38
|
-
public void d(String tag, String msg) {
|
|
39
|
-
Log.d(tag, msg);
|
|
40
|
-
onLog("debug", tag, msg, null);
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
@Override
|
|
44
|
-
public void d(String tag, String msg, Throwable tr) {
|
|
45
|
-
Log.d(tag, msg, tr);
|
|
46
|
-
onLog("debug",tag,msg,tr);
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
@Override
|
|
50
|
-
public void i(String tag, String msg) {
|
|
51
|
-
Log.i(tag, msg);
|
|
52
|
-
onLog("info", tag, msg, null);
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
@Override
|
|
56
|
-
public void i(String tag, String msg, Throwable tr) {
|
|
57
|
-
Log.i(tag, msg, tr);
|
|
58
|
-
onLog("info", tag, msg, tr);
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
@Override
|
|
62
|
-
public void w(String tag, String msg) {
|
|
63
|
-
Log.w(tag, msg);
|
|
64
|
-
onLog("warning", tag, msg, null);
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
@Override
|
|
68
|
-
public void w(String tag, String msg, Throwable tr) {
|
|
69
|
-
Log.w(tag, msg, tr);
|
|
70
|
-
onLog("warning", tag, msg, tr);
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
@Override
|
|
74
|
-
public void e(String tag, String msg) {
|
|
75
|
-
Log.e(tag, msg);
|
|
76
|
-
onLog("error", tag, msg, null);
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
@Override
|
|
80
|
-
public void e(String tag, String msg, Throwable tr) {
|
|
81
|
-
Log.e(tag, msg, tr);
|
|
82
|
-
onLog("error", tag, msg, tr);
|
|
83
|
-
}
|
|
84
|
-
});
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
@Override
|
|
88
|
-
public String getName() {
|
|
89
|
-
return REACT_CLASS;
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
@ReactMethod
|
|
93
|
-
public void setLogLevel(String level) {
|
|
94
|
-
@Logger.LogLevel int logLevel = Logger.NONE;
|
|
95
|
-
switch(level)
|
|
96
|
-
{
|
|
97
|
-
case "error":
|
|
98
|
-
logLevel = Logger.ERROR;
|
|
99
|
-
break;
|
|
100
|
-
case "warning":
|
|
101
|
-
logLevel = Logger.WARN;
|
|
102
|
-
break;
|
|
103
|
-
case "info":
|
|
104
|
-
logLevel = Logger.INFO;
|
|
105
|
-
break;
|
|
106
|
-
case "debug":
|
|
107
|
-
logLevel = Logger.DEBUG;
|
|
108
|
-
break;
|
|
109
|
-
case "verbose":
|
|
110
|
-
logLevel = Logger.VERBOSE;
|
|
111
|
-
break;
|
|
112
|
-
default:
|
|
113
|
-
logLevel = Logger.NONE;
|
|
114
|
-
break;
|
|
115
|
-
}
|
|
116
|
-
Logger.setVerbosity(logLevel);
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
@ReactMethod
|
|
120
|
-
public void addListener(String eventName) {
|
|
121
|
-
// Set up any upstream listeners or background tasks as necessary
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
@ReactMethod
|
|
125
|
-
public void removeListeners(Integer count) {
|
|
126
|
-
// Remove upstream listeners, stop unnecessary background tasks
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
public void onLog(String level, String tag, String msg, Throwable tr) {
|
|
130
|
-
WritableMap event = Arguments.createMap();
|
|
131
|
-
event.putString("message", msg);
|
|
132
|
-
event.putString("tag", tag);
|
|
133
|
-
event.putString("level", level);
|
|
134
|
-
|
|
135
|
-
mReactContext
|
|
136
|
-
.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class)
|
|
137
|
-
.emit("LogEvent", event);
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
}
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
#import "MLRNNativeUserLocationManager.h"
|
|
2
|
-
#import "MLRNNativeUserLocation.h"
|
|
3
|
-
|
|
4
|
-
@implementation MLRNNativeUserLocationManager
|
|
5
|
-
|
|
6
|
-
RCT_EXPORT_MODULE(MLRNNativeUserLocation)
|
|
7
|
-
RCT_EXPORT_VIEW_PROPERTY(iosShowsUserHeadingIndicator, BOOL)
|
|
8
|
-
|
|
9
|
-
#pragma - View Properties
|
|
10
|
-
|
|
11
|
-
#pragma Methods
|
|
12
|
-
|
|
13
|
-
- (BOOL)requiresMainQueueSetup {
|
|
14
|
-
return YES;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
- (UIView *)view {
|
|
18
|
-
return [[MLRNNativeUserLocation alloc] init];
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
@end
|