@maplibre/maplibre-react-native 11.0.0-alpha.7 → 11.0.0-alpha.9
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/MapLibreReactNative.podspec +1 -1
- package/android/build.gradle +0 -3
- package/android/src/main/java/org/maplibre/reactnative/MLRNPackage.kt +43 -0
- package/android/src/main/java/org/maplibre/reactnative/components/AbstractEvent.kt +24 -0
- package/android/src/main/java/org/maplibre/reactnative/components/AbstractEventEmitter.kt +71 -0
- package/android/src/main/java/org/maplibre/reactnative/components/annotation/MLRNPointAnnotation.java +1 -1
- package/android/src/main/java/org/maplibre/reactnative/components/camera/CameraStop.kt +203 -0
- package/android/src/main/java/org/maplibre/reactnative/components/camera/CameraUpdateItem.kt +109 -0
- package/android/src/main/java/org/maplibre/reactnative/components/camera/CameraUpdateQueue.kt +60 -0
- package/android/src/main/java/org/maplibre/reactnative/components/camera/MLRNCamera.kt +409 -0
- package/android/src/main/java/org/maplibre/reactnative/components/camera/MLRNCameraManager.kt +69 -0
- package/android/src/main/java/org/maplibre/reactnative/components/camera/MLRNCameraModule.kt +34 -0
- package/android/src/main/java/org/maplibre/reactnative/components/camera/constants/CameraEasing.kt +24 -0
- package/android/src/main/java/org/maplibre/reactnative/components/images/MLRNImages.java +1 -2
- package/android/src/main/java/org/maplibre/reactnative/components/location/LocationComponentManager.java +1 -1
- package/android/src/main/java/org/maplibre/reactnative/components/mapview/MLRNAndroidTextureMapView.kt +23 -0
- package/android/src/main/java/org/maplibre/reactnative/components/mapview/MLRNAndroidTextureMapViewManager.kt +23 -0
- package/android/src/main/java/org/maplibre/reactnative/components/mapview/MLRNMapView.kt +1338 -0
- package/android/src/main/java/org/maplibre/reactnative/components/mapview/MLRNMapViewManager.kt +187 -0
- package/android/src/main/java/org/maplibre/reactnative/components/mapview/MLRNMapViewModule.kt +159 -0
- package/android/src/main/java/org/maplibre/reactnative/components/mapview/helpers/CameraChangeTracker.kt +26 -0
- package/android/src/main/java/org/maplibre/reactnative/components/mapview/helpers/LayerSourceInfo.kt +74 -0
- package/android/src/main/java/org/maplibre/reactnative/components/styles/layers/MLRNLayer.java +1 -5
- package/android/src/main/java/org/maplibre/reactnative/components/styles/light/MLRNLight.java +1 -6
- package/android/src/main/java/org/maplibre/reactnative/components/styles/sources/MLRNShapeSource.java +2 -9
- package/android/src/main/java/org/maplibre/reactnative/components/styles/sources/MLRNSource.java +1 -1
- package/android/src/main/java/org/maplibre/reactnative/events/AbstractEvent.java +2 -5
- package/android/src/main/java/org/maplibre/reactnative/events/MapChangeEvent.kt +18 -0
- package/android/src/main/java/org/maplibre/reactnative/events/MapClickEvent.java +4 -0
- package/android/src/main/java/org/maplibre/reactnative/events/MapPressEvent.kt +27 -0
- package/android/src/main/java/org/maplibre/reactnative/events/TrackUserLocationChangeEvent.kt +24 -0
- package/android/src/main/java/org/maplibre/reactnative/events/constants/EventKeys.java +0 -1
- package/android/src/main/java/org/maplibre/reactnative/events/constants/EventTypes.java +0 -19
- package/android/src/main/java/org/maplibre/reactnative/location/LocationManager.java +1 -1
- package/android/src/main/java/org/maplibre/reactnative/location/TrackUserLocationMode.kt +43 -0
- package/android/src/main/java/org/maplibre/reactnative/location/{UserTrackingState.java → TrackUserLocationState.java} +1 -1
- package/android/src/main/java/org/maplibre/reactnative/location/UserLocation.java +1 -1
- package/android/src/main/java/org/maplibre/reactnative/modules/MLRNModule.java +1 -49
- package/android/src/main/java/org/maplibre/reactnative/utils/ConvertUtils.java +2 -9
- package/android/src/main/java/org/maplibre/reactnative/utils/GeoJSONUtils.kt +322 -0
- package/android/src/main/java/org/maplibre/reactnative/utils/ReactTagResolver.kt +85 -0
- package/ios/MLRNCallout.h +1 -1
- package/ios/MLRNEvent.m +3 -1
- package/ios/MLRNEventTypes.h +10 -31
- package/ios/MLRNEventTypes.m +10 -30
- package/ios/MLRNImages.h +1 -1
- package/ios/MLRNImages.m +1 -1
- package/ios/MLRNLayer.h +1 -1
- package/ios/MLRNLayer.m +2 -2
- package/ios/MLRNLight.h +2 -1
- package/ios/MLRNLocationModule.m +2 -2
- package/ios/MLRNMapTouchEvent.h +2 -1
- package/ios/MLRNMapTouchEvent.m +12 -10
- package/ios/MLRNModule.m +5 -52
- package/ios/MLRNNativeUserLocation.m +0 -1
- package/ios/MLRNOfflineModule.h +2 -2
- package/ios/MLRNOfflineModule.m +9 -9
- package/ios/MLRNPointAnnotation.h +1 -1
- package/ios/MLRNShapeSource.h +1 -1
- package/ios/MLRNSource.h +3 -1
- package/ios/MLRNStyle.m +20 -20
- package/ios/MLRNUtils.h +17 -2
- package/ios/MLRNUtils.m +25 -2
- package/ios/components/camera/CameraEasing.h +8 -0
- package/ios/{CameraStop.h → components/camera/CameraStop.h} +10 -6
- package/ios/components/camera/CameraStop.m +75 -0
- package/ios/{CameraUpdateItem.m → components/camera/CameraUpdateItem.m} +45 -46
- package/ios/components/camera/MLRNCamera.h +26 -0
- package/ios/components/camera/MLRNCamera.m +195 -0
- package/ios/components/camera/MLRNCameraComponentView.h +18 -0
- package/ios/components/camera/MLRNCameraComponentView.mm +192 -0
- package/ios/components/camera/MLRNCameraManager.h +11 -0
- package/ios/components/camera/MLRNCameraManager.m +20 -0
- package/ios/components/camera/MLRNCameraModule.h +4 -0
- package/ios/components/camera/MLRNCameraModule.mm +111 -0
- package/ios/{MLRNMapView.h → components/map-view/MLRNMapView.h} +42 -20
- package/ios/components/map-view/MLRNMapView.m +809 -0
- package/ios/components/map-view/MLRNMapViewComponentView.h +18 -0
- package/ios/components/map-view/MLRNMapViewComponentView.mm +400 -0
- package/ios/components/map-view/MLRNMapViewManager.h +70 -0
- package/ios/components/map-view/MLRNMapViewManager.m +163 -0
- package/ios/components/map-view/MLRNMapViewModule.h +4 -0
- package/ios/components/map-view/MLRNMapViewModule.mm +249 -0
- package/ios/{MLRNSnapshotModule → modules/snapshot}/MLRNSnapshotModule.mm +0 -1
- package/lib/commonjs/MLRNModule.js +1 -3
- package/lib/commonjs/MLRNModule.js.map +1 -1
- package/lib/commonjs/components/Annotation.js +1 -13
- package/lib/commonjs/components/Annotation.js.map +1 -1
- package/lib/commonjs/components/Images.js.map +1 -1
- package/lib/commonjs/components/ShapeSource.js +2 -21
- package/lib/commonjs/components/ShapeSource.js.map +1 -1
- package/lib/commonjs/components/VectorSource.js +3 -26
- package/lib/commonjs/components/VectorSource.js.map +1 -1
- package/lib/commonjs/components/camera/Camera.js +97 -0
- package/lib/commonjs/components/camera/Camera.js.map +1 -0
- package/lib/commonjs/components/camera/CameraNativeComponent.ts +61 -0
- package/lib/commonjs/components/camera/NativeCameraModule.js +11 -0
- package/lib/commonjs/components/camera/NativeCameraModule.js.map +1 -0
- package/lib/commonjs/components/map-view/MapView.js +115 -0
- package/lib/commonjs/components/map-view/MapView.js.map +1 -0
- package/lib/commonjs/components/map-view/MapViewNativeComponent.ts +96 -0
- package/lib/commonjs/components/map-view/NativeMapViewModule.js +9 -0
- package/lib/commonjs/components/map-view/NativeMapViewModule.js.map +1 -0
- package/lib/commonjs/index.js +246 -4
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/modules/snapshot/NativeSnapshotModule.js +2 -2
- package/lib/commonjs/modules/snapshot/NativeSnapshotModule.js.map +1 -1
- package/lib/commonjs/modules/snapshot/SnapshotManager.js +3 -2
- package/lib/commonjs/modules/snapshot/SnapshotManager.js.map +1 -1
- package/lib/commonjs/types/Bounds.js +2 -0
- package/lib/commonjs/types/{OnPressEvent.js.map → Bounds.js.map} +1 -1
- package/lib/commonjs/types/PressEvent.js +2 -0
- package/lib/{module/types/OnPressEvent.js.map → commonjs/types/PressEvent.js.map} +1 -1
- package/lib/commonjs/types/ViewPadding.js +2 -0
- package/lib/commonjs/types/{MapLibreRNEvent.js.map → ViewPadding.js.map} +1 -1
- package/lib/commonjs/types/codegen/UnsafeMixed.js +2 -0
- package/lib/commonjs/types/codegen/UnsafeMixed.js.map +1 -0
- package/lib/commonjs/utils/index.js +0 -11
- package/lib/commonjs/utils/index.js.map +1 -1
- package/lib/module/MLRNModule.js +0 -1
- package/lib/module/MLRNModule.js.map +1 -1
- package/lib/module/components/Annotation.js +2 -14
- package/lib/module/components/Annotation.js.map +1 -1
- package/lib/module/components/Images.js.map +1 -1
- package/lib/module/components/ShapeSource.js +3 -22
- package/lib/module/components/ShapeSource.js.map +1 -1
- package/lib/module/components/VectorSource.js +4 -27
- package/lib/module/components/VectorSource.js.map +1 -1
- package/lib/module/components/camera/Camera.js +92 -0
- package/lib/module/components/camera/Camera.js.map +1 -0
- package/lib/module/components/camera/CameraNativeComponent.ts +61 -0
- package/lib/module/components/camera/NativeCameraModule.js +10 -0
- package/lib/module/components/camera/NativeCameraModule.js.map +1 -0
- package/lib/module/components/map-view/MapView.js +110 -0
- package/lib/module/components/map-view/MapView.js.map +1 -0
- package/lib/module/components/map-view/MapViewNativeComponent.ts +96 -0
- package/lib/module/components/map-view/NativeMapViewModule.js +5 -0
- package/lib/module/components/map-view/NativeMapViewModule.js.map +1 -0
- package/lib/module/index.js +30 -1
- package/lib/module/index.js.map +1 -1
- package/lib/module/modules/snapshot/NativeSnapshotModule.js +1 -1
- package/lib/module/modules/snapshot/NativeSnapshotModule.js.map +1 -1
- package/lib/module/modules/snapshot/SnapshotManager.js +1 -1
- package/lib/module/modules/snapshot/SnapshotManager.js.map +1 -1
- package/lib/module/types/Bounds.js +2 -0
- package/lib/module/types/{MapLibreRNEvent.js.map → Bounds.js.map} +1 -1
- package/lib/module/types/PressEvent.js +2 -0
- package/lib/module/types/PressEvent.js.map +1 -0
- package/lib/module/types/ViewPadding.js +2 -0
- package/lib/module/types/ViewPadding.js.map +1 -0
- package/lib/module/types/codegen/UnsafeMixed.js +2 -0
- package/lib/module/types/codegen/UnsafeMixed.js.map +1 -0
- package/lib/module/utils/index.js +0 -9
- package/lib/module/utils/index.js.map +1 -1
- package/lib/typescript/commonjs/src/MLRNModule.d.ts +1 -7
- package/lib/typescript/commonjs/src/MLRNModule.d.ts.map +1 -1
- package/lib/typescript/commonjs/src/components/Annotation.d.ts +3 -3
- package/lib/typescript/commonjs/src/components/Annotation.d.ts.map +1 -1
- package/lib/typescript/commonjs/src/components/Images.d.ts +1 -2
- package/lib/typescript/commonjs/src/components/Images.d.ts.map +1 -1
- package/lib/typescript/commonjs/src/components/ShapeSource.d.ts +2 -5
- package/lib/typescript/commonjs/src/components/ShapeSource.d.ts.map +1 -1
- package/lib/typescript/commonjs/src/components/VectorSource.d.ts +3 -2
- package/lib/typescript/commonjs/src/components/VectorSource.d.ts.map +1 -1
- package/lib/typescript/commonjs/src/components/camera/Camera.d.ts +180 -0
- package/lib/typescript/commonjs/src/components/camera/Camera.d.ts.map +1 -0
- package/lib/typescript/commonjs/src/components/camera/CameraNativeComponent.d.ts +37 -0
- package/lib/typescript/commonjs/src/components/camera/CameraNativeComponent.d.ts.map +1 -0
- package/lib/typescript/commonjs/src/components/camera/NativeCameraModule.d.ts +27 -0
- package/lib/typescript/commonjs/src/components/camera/NativeCameraModule.d.ts.map +1 -0
- package/lib/typescript/commonjs/src/components/map-view/MapView.d.ts +323 -0
- package/lib/typescript/commonjs/src/components/map-view/MapView.d.ts.map +1 -0
- package/lib/typescript/commonjs/src/components/map-view/MapViewNativeComponent.d.ts +69 -0
- package/lib/typescript/commonjs/src/components/map-view/MapViewNativeComponent.d.ts.map +1 -0
- package/lib/typescript/commonjs/src/components/map-view/NativeMapViewModule.d.ts +45 -0
- package/lib/typescript/commonjs/src/components/map-view/NativeMapViewModule.d.ts.map +1 -0
- package/lib/typescript/commonjs/src/index.d.ts +41 -1
- package/lib/typescript/commonjs/src/index.d.ts.map +1 -1
- package/lib/typescript/commonjs/src/modules/snapshot/NativeSnapshotModule.d.ts +2 -1
- package/lib/typescript/commonjs/src/modules/snapshot/NativeSnapshotModule.d.ts.map +1 -1
- package/lib/typescript/commonjs/src/types/Bounds.d.ts +2 -0
- package/lib/typescript/commonjs/src/types/Bounds.d.ts.map +1 -0
- package/lib/typescript/commonjs/src/types/PressEvent.d.ts +16 -0
- package/lib/typescript/commonjs/src/types/PressEvent.d.ts.map +1 -0
- package/lib/typescript/commonjs/src/types/ViewPadding.d.ts +7 -0
- package/lib/typescript/commonjs/src/types/ViewPadding.d.ts.map +1 -0
- package/lib/typescript/commonjs/src/types/codegen/UnsafeMixed.d.ts +10 -0
- package/lib/typescript/commonjs/src/types/codegen/UnsafeMixed.d.ts.map +1 -0
- package/lib/typescript/commonjs/src/utils/index.d.ts +1 -3
- package/lib/typescript/commonjs/src/utils/index.d.ts.map +1 -1
- package/lib/typescript/module/src/MLRNModule.d.ts +1 -7
- package/lib/typescript/module/src/MLRNModule.d.ts.map +1 -1
- package/lib/typescript/module/src/components/Annotation.d.ts +3 -3
- package/lib/typescript/module/src/components/Annotation.d.ts.map +1 -1
- package/lib/typescript/module/src/components/Images.d.ts +1 -2
- package/lib/typescript/module/src/components/Images.d.ts.map +1 -1
- package/lib/typescript/module/src/components/ShapeSource.d.ts +2 -5
- package/lib/typescript/module/src/components/ShapeSource.d.ts.map +1 -1
- package/lib/typescript/module/src/components/VectorSource.d.ts +3 -2
- package/lib/typescript/module/src/components/VectorSource.d.ts.map +1 -1
- package/lib/typescript/module/src/components/camera/Camera.d.ts +180 -0
- package/lib/typescript/module/src/components/camera/Camera.d.ts.map +1 -0
- package/lib/typescript/module/src/components/camera/CameraNativeComponent.d.ts +37 -0
- package/lib/typescript/module/src/components/camera/CameraNativeComponent.d.ts.map +1 -0
- package/lib/typescript/module/src/components/camera/NativeCameraModule.d.ts +27 -0
- package/lib/typescript/module/src/components/camera/NativeCameraModule.d.ts.map +1 -0
- package/lib/typescript/module/src/components/map-view/MapView.d.ts +323 -0
- package/lib/typescript/module/src/components/map-view/MapView.d.ts.map +1 -0
- package/lib/typescript/module/src/components/map-view/MapViewNativeComponent.d.ts +69 -0
- package/lib/typescript/module/src/components/map-view/MapViewNativeComponent.d.ts.map +1 -0
- package/lib/typescript/module/src/components/map-view/NativeMapViewModule.d.ts +45 -0
- package/lib/typescript/module/src/components/map-view/NativeMapViewModule.d.ts.map +1 -0
- package/lib/typescript/module/src/index.d.ts +41 -1
- package/lib/typescript/module/src/index.d.ts.map +1 -1
- package/lib/typescript/module/src/modules/snapshot/NativeSnapshotModule.d.ts +2 -1
- package/lib/typescript/module/src/modules/snapshot/NativeSnapshotModule.d.ts.map +1 -1
- package/lib/typescript/module/src/types/Bounds.d.ts +2 -0
- package/lib/typescript/module/src/types/Bounds.d.ts.map +1 -0
- package/lib/typescript/module/src/types/PressEvent.d.ts +16 -0
- package/lib/typescript/module/src/types/PressEvent.d.ts.map +1 -0
- package/lib/typescript/module/src/types/ViewPadding.d.ts +7 -0
- package/lib/typescript/module/src/types/ViewPadding.d.ts.map +1 -0
- package/lib/typescript/module/src/types/codegen/UnsafeMixed.d.ts +10 -0
- package/lib/typescript/module/src/types/codegen/UnsafeMixed.d.ts.map +1 -0
- package/lib/typescript/module/src/utils/index.d.ts +1 -3
- package/lib/typescript/module/src/utils/index.d.ts.map +1 -1
- package/package.json +38 -28
- package/src/MLRNModule.ts +0 -10
- package/src/components/Annotation.tsx +8 -23
- package/src/components/Images.tsx +2 -4
- package/src/components/ShapeSource.tsx +18 -31
- package/src/components/VectorSource.tsx +5 -28
- package/src/components/camera/Camera.tsx +311 -0
- package/src/components/camera/CameraNativeComponent.ts +61 -0
- package/src/components/camera/NativeCameraModule.ts +39 -0
- package/src/components/map-view/MapView.tsx +582 -0
- package/src/components/map-view/MapViewNativeComponent.ts +96 -0
- package/src/components/map-view/NativeMapViewModule.ts +83 -0
- package/src/index.ts +86 -1
- package/src/modules/snapshot/NativeSnapshotModule.ts +1 -2
- package/src/modules/snapshot/SnapshotManager.ts +1 -1
- package/src/types/Bounds.ts +1 -0
- package/src/types/PressEvent.ts +19 -0
- package/src/types/ViewPadding.ts +6 -0
- package/src/types/codegen/UnsafeMixed.ts +9 -0
- package/src/utils/index.ts +1 -14
- package/android/src/main/java/org/maplibre/reactnative/components/AbstractEvent.java +0 -35
- package/android/src/main/java/org/maplibre/reactnative/components/AbstractEventEmitter.java +0 -80
- package/android/src/main/java/org/maplibre/reactnative/components/camera/CameraStop.java +0 -245
- package/android/src/main/java/org/maplibre/reactnative/components/camera/CameraUpdateItem.java +0 -121
- package/android/src/main/java/org/maplibre/reactnative/components/camera/CameraUpdateQueue.java +0 -68
- package/android/src/main/java/org/maplibre/reactnative/components/camera/MLRNCamera.java +0 -519
- package/android/src/main/java/org/maplibre/reactnative/components/camera/MLRNCameraManager.java +0 -101
- package/android/src/main/java/org/maplibre/reactnative/components/camera/constants/CameraMode.java +0 -18
- package/android/src/main/java/org/maplibre/reactnative/components/mapview/LayerSourceInfo.java +0 -59
- package/android/src/main/java/org/maplibre/reactnative/components/mapview/MLRNAndroidTextureMapView.java +0 -13
- package/android/src/main/java/org/maplibre/reactnative/components/mapview/MLRNAndroidTextureMapViewManager.java +0 -27
- package/android/src/main/java/org/maplibre/reactnative/components/mapview/MLRNMapView.java +0 -1521
- package/android/src/main/java/org/maplibre/reactnative/components/mapview/MLRNMapViewManager.java +0 -342
- package/android/src/main/java/org/maplibre/reactnative/components/mapview/helpers/CameraChangeTracker.java +0 -37
- package/android/src/main/java/org/maplibre/reactnative/events/MapChangeEvent.java +0 -43
- package/android/src/main/java/org/maplibre/reactnative/events/MapUserTrackingModeEvent.java +0 -32
- package/android/src/main/java/org/maplibre/reactnative/location/UserLocationVerticalAlignment.java +0 -7
- package/android/src/main/java/org/maplibre/reactnative/location/UserTrackingMode.java +0 -59
- package/android/src/main/java/org/maplibre/reactnative/utils/GeoJSONUtils.java +0 -310
- package/ios/CameraMode.h +0 -10
- package/ios/CameraMode.m +0 -10
- package/ios/CameraStop.m +0 -73
- package/ios/MLRNCamera.h +0 -29
- package/ios/MLRNCamera.m +0 -236
- package/ios/MLRNCameraManager.h +0 -5
- package/ios/MLRNCameraManager.m +0 -39
- package/ios/MLRNMapView.m +0 -497
- package/ios/MLRNMapViewManager.h +0 -9
- package/ios/MLRNMapViewManager.m +0 -604
- package/lib/commonjs/MapLibreRN.js +0 -266
- package/lib/commonjs/MapLibreRN.js.map +0 -1
- package/lib/commonjs/components/Camera.js +0 -333
- package/lib/commonjs/components/Camera.js.map +0 -1
- package/lib/commonjs/components/MapView.js +0 -449
- package/lib/commonjs/components/MapView.js.map +0 -1
- package/lib/commonjs/hooks/useNativeRef.js +0 -14
- package/lib/commonjs/hooks/useNativeRef.js.map +0 -1
- package/lib/commonjs/types/CameraMode.js +0 -14
- package/lib/commonjs/types/CameraMode.js.map +0 -1
- package/lib/commonjs/types/MapLibreRNEvent.js +0 -6
- package/lib/commonjs/types/OnPressEvent.js +0 -2
- package/lib/module/MapLibreRN.js +0 -33
- package/lib/module/MapLibreRN.js.map +0 -1
- package/lib/module/components/Camera.js +0 -328
- package/lib/module/components/Camera.js.map +0 -1
- package/lib/module/components/MapView.js +0 -444
- package/lib/module/components/MapView.js.map +0 -1
- package/lib/module/hooks/useNativeRef.js +0 -10
- package/lib/module/hooks/useNativeRef.js.map +0 -1
- package/lib/module/types/CameraMode.js +0 -10
- package/lib/module/types/CameraMode.js.map +0 -1
- package/lib/module/types/MapLibreRNEvent.js +0 -4
- package/lib/module/types/OnPressEvent.js +0 -2
- package/lib/typescript/commonjs/src/MapLibreRN.d.ts +0 -41
- package/lib/typescript/commonjs/src/MapLibreRN.d.ts.map +0 -1
- package/lib/typescript/commonjs/src/components/Camera.d.ts +0 -134
- package/lib/typescript/commonjs/src/components/Camera.d.ts.map +0 -1
- package/lib/typescript/commonjs/src/components/MapView.d.ts +0 -223
- package/lib/typescript/commonjs/src/components/MapView.d.ts.map +0 -1
- package/lib/typescript/commonjs/src/hooks/useNativeRef.d.ts +0 -8
- package/lib/typescript/commonjs/src/hooks/useNativeRef.d.ts.map +0 -1
- package/lib/typescript/commonjs/src/types/CameraMode.d.ts +0 -7
- package/lib/typescript/commonjs/src/types/CameraMode.d.ts.map +0 -1
- package/lib/typescript/commonjs/src/types/MapLibreRNEvent.d.ts +0 -6
- package/lib/typescript/commonjs/src/types/MapLibreRNEvent.d.ts.map +0 -1
- package/lib/typescript/commonjs/src/types/OnPressEvent.d.ts +0 -12
- package/lib/typescript/commonjs/src/types/OnPressEvent.d.ts.map +0 -1
- package/lib/typescript/module/src/MapLibreRN.d.ts +0 -41
- package/lib/typescript/module/src/MapLibreRN.d.ts.map +0 -1
- package/lib/typescript/module/src/components/Camera.d.ts +0 -134
- package/lib/typescript/module/src/components/Camera.d.ts.map +0 -1
- package/lib/typescript/module/src/components/MapView.d.ts +0 -223
- package/lib/typescript/module/src/components/MapView.d.ts.map +0 -1
- package/lib/typescript/module/src/hooks/useNativeRef.d.ts +0 -8
- package/lib/typescript/module/src/hooks/useNativeRef.d.ts.map +0 -1
- package/lib/typescript/module/src/types/CameraMode.d.ts +0 -7
- package/lib/typescript/module/src/types/CameraMode.d.ts.map +0 -1
- package/lib/typescript/module/src/types/MapLibreRNEvent.d.ts +0 -6
- package/lib/typescript/module/src/types/MapLibreRNEvent.d.ts.map +0 -1
- package/lib/typescript/module/src/types/OnPressEvent.d.ts +0 -12
- package/lib/typescript/module/src/types/OnPressEvent.d.ts.map +0 -1
- package/src/MapLibreRN.ts +0 -75
- package/src/components/Camera.tsx +0 -568
- package/src/components/MapView.tsx +0 -838
- package/src/hooks/useNativeRef.ts +0 -14
- package/src/types/CameraMode.ts +0 -6
- package/src/types/MapLibreRNEvent.ts +0 -7
- package/src/types/OnPressEvent.ts +0 -11
- /package/ios/{CameraUpdateItem.h → components/camera/CameraUpdateItem.h} +0 -0
- /package/ios/{CameraUpdateQueue.h → components/camera/CameraUpdateQueue.h} +0 -0
- /package/ios/{CameraUpdateQueue.m → components/camera/CameraUpdateQueue.m} +0 -0
- /package/ios/{MLRNSnapshotModule → modules/snapshot}/MLRNSnapshotModule.h +0 -0
|
@@ -1,1521 +0,0 @@
|
|
|
1
|
-
package org.maplibre.reactnative.components.mapview;
|
|
2
|
-
|
|
3
|
-
import android.content.Context;
|
|
4
|
-
import android.graphics.Bitmap;
|
|
5
|
-
import android.graphics.BitmapFactory;
|
|
6
|
-
import android.graphics.PointF;
|
|
7
|
-
import android.graphics.RectF;
|
|
8
|
-
import android.location.Location;
|
|
9
|
-
import android.os.Handler;
|
|
10
|
-
import androidx.annotation.NonNull;
|
|
11
|
-
|
|
12
|
-
import android.util.DisplayMetrics;
|
|
13
|
-
import android.util.Pair;
|
|
14
|
-
import android.view.Gravity;
|
|
15
|
-
import android.view.MotionEvent;
|
|
16
|
-
import android.view.View;
|
|
17
|
-
import android.view.ViewGroup;
|
|
18
|
-
import android.widget.FrameLayout;
|
|
19
|
-
import org.maplibre.android.log.Logger;
|
|
20
|
-
|
|
21
|
-
import com.facebook.react.bridge.LifecycleEventListener;
|
|
22
|
-
import com.facebook.react.bridge.ReactContext;
|
|
23
|
-
import com.facebook.react.bridge.ReadableArray;
|
|
24
|
-
import com.facebook.react.bridge.ReadableMap;
|
|
25
|
-
import com.facebook.react.bridge.WritableArray;
|
|
26
|
-
import com.facebook.react.bridge.WritableMap;
|
|
27
|
-
import com.facebook.react.bridge.WritableNativeArray;
|
|
28
|
-
import com.facebook.react.bridge.WritableNativeMap;
|
|
29
|
-
import org.maplibre.android.gestures.MoveGestureDetector;
|
|
30
|
-
import org.maplibre.geojson.Feature;
|
|
31
|
-
import org.maplibre.geojson.FeatureCollection;
|
|
32
|
-
import org.maplibre.android.camera.CameraPosition;
|
|
33
|
-
import org.maplibre.android.camera.CameraUpdate;
|
|
34
|
-
import org.maplibre.android.geometry.LatLng;
|
|
35
|
-
import org.maplibre.android.geometry.VisibleRegion;
|
|
36
|
-
import org.maplibre.android.maps.AttributionDialogManager;
|
|
37
|
-
import org.maplibre.android.maps.MapView;
|
|
38
|
-
import org.maplibre.android.maps.MapLibreMap;
|
|
39
|
-
import org.maplibre.android.maps.MapLibreMapOptions;
|
|
40
|
-
import org.maplibre.android.maps.OnMapReadyCallback;
|
|
41
|
-
import org.maplibre.android.maps.Style;
|
|
42
|
-
import org.maplibre.android.maps.UiSettings;
|
|
43
|
-
import org.maplibre.android.plugins.localization.LocalizationPlugin;
|
|
44
|
-
import org.maplibre.android.plugins.annotation.OnSymbolClickListener;
|
|
45
|
-
import org.maplibre.android.plugins.annotation.OnSymbolDragListener;
|
|
46
|
-
import org.maplibre.android.plugins.annotation.Symbol;
|
|
47
|
-
import org.maplibre.android.plugins.annotation.SymbolManager;
|
|
48
|
-
import org.maplibre.android.style.expressions.Expression;
|
|
49
|
-
import org.maplibre.android.style.layers.Layer;
|
|
50
|
-
import org.maplibre.android.style.layers.Property;
|
|
51
|
-
import org.maplibre.reactnative.R;
|
|
52
|
-
import org.maplibre.reactnative.components.AbstractMapFeature;
|
|
53
|
-
import org.maplibre.reactnative.components.annotation.MLRNPointAnnotation;
|
|
54
|
-
import org.maplibre.reactnative.components.annotation.MLRNMarkerView;
|
|
55
|
-
import org.maplibre.reactnative.components.annotation.MarkerViewManager;
|
|
56
|
-
import org.maplibre.reactnative.components.camera.MLRNCamera;
|
|
57
|
-
import org.maplibre.reactnative.components.images.MLRNImages;
|
|
58
|
-
import org.maplibre.reactnative.components.location.LocationComponentManager;
|
|
59
|
-
import org.maplibre.reactnative.components.location.MLRNNativeUserLocation;
|
|
60
|
-
import org.maplibre.reactnative.components.mapview.helpers.CameraChangeTracker;
|
|
61
|
-
import org.maplibre.reactnative.components.styles.layers.MLRNLayer;
|
|
62
|
-
import org.maplibre.reactnative.components.styles.light.MLRNLight;
|
|
63
|
-
import org.maplibre.reactnative.components.styles.sources.MLRNShapeSource;
|
|
64
|
-
import org.maplibre.reactnative.components.styles.sources.MLRNSource;
|
|
65
|
-
import org.maplibre.reactnative.events.AndroidCallbackEvent;
|
|
66
|
-
import org.maplibre.reactnative.events.IEvent;
|
|
67
|
-
import org.maplibre.reactnative.events.MapChangeEvent;
|
|
68
|
-
import org.maplibre.reactnative.events.MapClickEvent;
|
|
69
|
-
import org.maplibre.reactnative.events.constants.EventTypes;
|
|
70
|
-
import org.maplibre.reactnative.modules.MLRNModule;
|
|
71
|
-
import org.maplibre.reactnative.utils.BitmapUtils;
|
|
72
|
-
import org.maplibre.reactnative.utils.GeoJSONUtils;
|
|
73
|
-
import org.maplibre.reactnative.utils.GeoViewport;
|
|
74
|
-
|
|
75
|
-
import java.util.ArrayList;
|
|
76
|
-
import java.util.Arrays;
|
|
77
|
-
import java.util.HashMap;
|
|
78
|
-
import java.util.HashSet;
|
|
79
|
-
import java.util.List;
|
|
80
|
-
import java.util.Map;
|
|
81
|
-
import java.util.Locale;
|
|
82
|
-
import org.json.*;
|
|
83
|
-
|
|
84
|
-
import javax.annotation.Nullable;
|
|
85
|
-
|
|
86
|
-
import static org.maplibre.android.style.layers.PropertyFactory.visibility;
|
|
87
|
-
|
|
88
|
-
@SuppressWarnings({ "MissingPermission" })
|
|
89
|
-
public class MLRNMapView extends MapView implements OnMapReadyCallback, MapLibreMap.OnMapClickListener,
|
|
90
|
-
MapLibreMap.OnMapLongClickListener, MapView.OnCameraIsChangingListener, MapView.OnCameraDidChangeListener,
|
|
91
|
-
MapView.OnDidFailLoadingMapListener, MapView.OnDidFinishLoadingMapListener,
|
|
92
|
-
MapView.OnWillStartRenderingFrameListener, MapView.OnWillStartRenderingMapListener,
|
|
93
|
-
MapView.OnDidFinishRenderingFrameListener, MapView.OnDidFinishRenderingMapListener,
|
|
94
|
-
MapView.OnDidFinishLoadingStyleListener, MapView.OnStyleImageMissingListener {
|
|
95
|
-
public static final String LOG_TAG = "MLRNMapView";
|
|
96
|
-
|
|
97
|
-
private MLRNMapViewManager mManager;
|
|
98
|
-
private Context mContext;
|
|
99
|
-
private Handler mHandler;
|
|
100
|
-
private LifecycleEventListener mLifeCycleListener;
|
|
101
|
-
private boolean mPaused;
|
|
102
|
-
private boolean mDestroyed;
|
|
103
|
-
|
|
104
|
-
private MLRNCamera mCamera;
|
|
105
|
-
private List<AbstractMapFeature> mFeatures;
|
|
106
|
-
private List<AbstractMapFeature> mQueuedFeatures;
|
|
107
|
-
private Map<String, MLRNPointAnnotation> mPointAnnotations;
|
|
108
|
-
private Map<String, MLRNSource> mSources;
|
|
109
|
-
private List<MLRNImages> mImages;
|
|
110
|
-
|
|
111
|
-
private CameraChangeTracker mCameraChangeTracker = new CameraChangeTracker();
|
|
112
|
-
private List<Pair<Integer, ReadableArray>> mPreRenderMethods = new ArrayList<>();
|
|
113
|
-
|
|
114
|
-
private MapLibreMap mMap;
|
|
115
|
-
|
|
116
|
-
private LocalizationPlugin mLocalizationPlugin;
|
|
117
|
-
|
|
118
|
-
private String mMapStyle;
|
|
119
|
-
|
|
120
|
-
private Integer mPreferredFramesPerSecond;
|
|
121
|
-
private boolean mLocalizeLabels;
|
|
122
|
-
private Boolean mScrollEnabled;
|
|
123
|
-
private Boolean mPitchEnabled;
|
|
124
|
-
private Boolean mRotateEnabled;
|
|
125
|
-
private Boolean mAttributionEnabled;
|
|
126
|
-
private Integer mAttributionGravity;
|
|
127
|
-
private int[] mAttributionMargin;
|
|
128
|
-
private Boolean mLogoEnabled;
|
|
129
|
-
private Integer mLogoGravity;
|
|
130
|
-
private int[] mLogoMargins;
|
|
131
|
-
private Boolean mCompassEnabled;
|
|
132
|
-
private ReadableMap mCompassViewMargins;
|
|
133
|
-
private int mCompassViewPosition = -1;
|
|
134
|
-
private Boolean mZoomEnabled;
|
|
135
|
-
|
|
136
|
-
private SymbolManager symbolManager;
|
|
137
|
-
|
|
138
|
-
private long mActiveMarkerID = -1;
|
|
139
|
-
|
|
140
|
-
private ReadableArray mInsets;
|
|
141
|
-
|
|
142
|
-
private HashSet<String> mHandledMapChangedEvents = null;
|
|
143
|
-
|
|
144
|
-
private MarkerViewManager markerViewManager = null;
|
|
145
|
-
private ViewGroup mOffscreenAnnotationViewContainer = null;
|
|
146
|
-
|
|
147
|
-
private boolean mAnnotationClicked = false;
|
|
148
|
-
|
|
149
|
-
private LocationComponentManager mLocationComponentManager = null;
|
|
150
|
-
|
|
151
|
-
private @Nullable Integer mTintColor = null;
|
|
152
|
-
|
|
153
|
-
public MLRNMapView(Context context, MLRNMapViewManager manager, MapLibreMapOptions options) {
|
|
154
|
-
super(context, options);
|
|
155
|
-
|
|
156
|
-
mContext = context;
|
|
157
|
-
onCreate(null);
|
|
158
|
-
onStart();
|
|
159
|
-
onResume();
|
|
160
|
-
getMapAsync(this);
|
|
161
|
-
|
|
162
|
-
mManager = manager;
|
|
163
|
-
|
|
164
|
-
mSources = new HashMap<>();
|
|
165
|
-
mImages = new ArrayList<>();
|
|
166
|
-
mPointAnnotations = new HashMap<>();
|
|
167
|
-
mQueuedFeatures = new ArrayList<>();
|
|
168
|
-
mFeatures = new ArrayList<>();
|
|
169
|
-
|
|
170
|
-
mHandler = new Handler();
|
|
171
|
-
|
|
172
|
-
mMapStyle = MLRNModule.DEFAULT_STYLE_URL;
|
|
173
|
-
|
|
174
|
-
setLifecycleListeners();
|
|
175
|
-
|
|
176
|
-
addOnCameraIsChangingListener(this);
|
|
177
|
-
addOnCameraDidChangeListener(this);
|
|
178
|
-
addOnDidFailLoadingMapListener(this);
|
|
179
|
-
addOnDidFinishLoadingMapListener(this);
|
|
180
|
-
addOnStyleImageMissingListener(this);
|
|
181
|
-
|
|
182
|
-
addOnWillStartRenderingFrameListener(this);
|
|
183
|
-
addOnDidFinishRenderingFrameListener(this);
|
|
184
|
-
addOnWillStartRenderingMapListener(this);
|
|
185
|
-
addOnDidFinishRenderingMapListener(this);
|
|
186
|
-
addOnDidFinishLoadingStyleListener(this);
|
|
187
|
-
}
|
|
188
|
-
|
|
189
|
-
@Override
|
|
190
|
-
public void onResume() {
|
|
191
|
-
super.onResume();
|
|
192
|
-
mPaused = false;
|
|
193
|
-
}
|
|
194
|
-
|
|
195
|
-
@Override
|
|
196
|
-
public void onPause() {
|
|
197
|
-
super.onPause();
|
|
198
|
-
mPaused = true;
|
|
199
|
-
}
|
|
200
|
-
|
|
201
|
-
@Override
|
|
202
|
-
public void onDestroy() {
|
|
203
|
-
super.onDestroy();
|
|
204
|
-
mDestroyed = true;
|
|
205
|
-
}
|
|
206
|
-
|
|
207
|
-
public void enqueuePreRenderMapMethod(Integer methodID, @Nullable ReadableArray args) {
|
|
208
|
-
mPreRenderMethods.add(new Pair<>(methodID, args));
|
|
209
|
-
}
|
|
210
|
-
|
|
211
|
-
public void addFeature(View childView, int childPosition) {
|
|
212
|
-
AbstractMapFeature feature = null;
|
|
213
|
-
|
|
214
|
-
if (childView instanceof MLRNSource) {
|
|
215
|
-
MLRNSource source = (MLRNSource) childView;
|
|
216
|
-
mSources.put(source.getID(), source);
|
|
217
|
-
feature = (AbstractMapFeature) childView;
|
|
218
|
-
} else if (childView instanceof MLRNImages) {
|
|
219
|
-
MLRNImages images = (MLRNImages) childView;
|
|
220
|
-
mImages.add(images);
|
|
221
|
-
feature = (AbstractMapFeature) childView;
|
|
222
|
-
} else if (childView instanceof MLRNLight) {
|
|
223
|
-
feature = (AbstractMapFeature) childView;
|
|
224
|
-
} else if (childView instanceof MLRNNativeUserLocation) {
|
|
225
|
-
feature = (AbstractMapFeature) childView;
|
|
226
|
-
} else if (childView instanceof MLRNPointAnnotation) {
|
|
227
|
-
MLRNPointAnnotation annotation = (MLRNPointAnnotation) childView;
|
|
228
|
-
mPointAnnotations.put(annotation.getID(), annotation);
|
|
229
|
-
feature = (AbstractMapFeature) childView;
|
|
230
|
-
} else if (childView instanceof MLRNMarkerView) {
|
|
231
|
-
MLRNMarkerView marker = (MLRNMarkerView) childView;
|
|
232
|
-
feature = (AbstractMapFeature) childView;
|
|
233
|
-
} else if (childView instanceof MLRNCamera) {
|
|
234
|
-
mCamera = (MLRNCamera) childView;
|
|
235
|
-
feature = (AbstractMapFeature) childView;
|
|
236
|
-
} else if (childView instanceof MLRNLayer) {
|
|
237
|
-
feature = (MLRNLayer) childView;
|
|
238
|
-
} else if (childView instanceof ViewGroup) {
|
|
239
|
-
ViewGroup children = (ViewGroup) childView;
|
|
240
|
-
|
|
241
|
-
for (int i = 0; i < children.getChildCount(); i++) {
|
|
242
|
-
addFeature(children.getChildAt(i), childPosition);
|
|
243
|
-
}
|
|
244
|
-
}
|
|
245
|
-
|
|
246
|
-
if (feature != null) {
|
|
247
|
-
if (mQueuedFeatures == null) {
|
|
248
|
-
feature.addToMap(this);
|
|
249
|
-
mFeatures.add(childPosition, feature);
|
|
250
|
-
} else {
|
|
251
|
-
mQueuedFeatures.add(childPosition, feature);
|
|
252
|
-
}
|
|
253
|
-
}
|
|
254
|
-
}
|
|
255
|
-
|
|
256
|
-
public void removeFeature(int childPosition) {
|
|
257
|
-
AbstractMapFeature feature = features().get(childPosition);
|
|
258
|
-
|
|
259
|
-
if (feature == null) {
|
|
260
|
-
return;
|
|
261
|
-
}
|
|
262
|
-
|
|
263
|
-
if (feature instanceof MLRNSource) {
|
|
264
|
-
MLRNSource source = (MLRNSource) feature;
|
|
265
|
-
mSources.remove(source.getID());
|
|
266
|
-
} else if (feature instanceof MLRNPointAnnotation) {
|
|
267
|
-
MLRNPointAnnotation annotation = (MLRNPointAnnotation) feature;
|
|
268
|
-
|
|
269
|
-
if (annotation.getMapboxID() == mActiveMarkerID) {
|
|
270
|
-
mActiveMarkerID = -1;
|
|
271
|
-
}
|
|
272
|
-
|
|
273
|
-
mPointAnnotations.remove(annotation.getID());
|
|
274
|
-
} else if (feature instanceof MLRNImages) {
|
|
275
|
-
MLRNImages images = (MLRNImages) feature;
|
|
276
|
-
mImages.remove(images);
|
|
277
|
-
}
|
|
278
|
-
|
|
279
|
-
feature.removeFromMap(this);
|
|
280
|
-
features().remove(feature);
|
|
281
|
-
}
|
|
282
|
-
|
|
283
|
-
private List<AbstractMapFeature> features() {
|
|
284
|
-
if (mQueuedFeatures != null && mQueuedFeatures.size() > 0) {
|
|
285
|
-
return mQueuedFeatures;
|
|
286
|
-
} else {
|
|
287
|
-
return mFeatures;
|
|
288
|
-
}
|
|
289
|
-
}
|
|
290
|
-
|
|
291
|
-
public int getFeatureCount() {
|
|
292
|
-
return features().size();
|
|
293
|
-
}
|
|
294
|
-
|
|
295
|
-
public AbstractMapFeature getFeatureAt(int i) {
|
|
296
|
-
return features().get(i);
|
|
297
|
-
}
|
|
298
|
-
|
|
299
|
-
public synchronized void dispose() {
|
|
300
|
-
if (mDestroyed) {
|
|
301
|
-
return;
|
|
302
|
-
}
|
|
303
|
-
|
|
304
|
-
if (!layerWaiters.isEmpty()) {
|
|
305
|
-
layerWaiters.clear();
|
|
306
|
-
}
|
|
307
|
-
|
|
308
|
-
ReactContext reactContext = (ReactContext) mContext;
|
|
309
|
-
reactContext.removeLifecycleEventListener(mLifeCycleListener);
|
|
310
|
-
|
|
311
|
-
if (!mPaused) {
|
|
312
|
-
onPause();
|
|
313
|
-
}
|
|
314
|
-
|
|
315
|
-
onStop();
|
|
316
|
-
onDestroy();
|
|
317
|
-
}
|
|
318
|
-
|
|
319
|
-
public VisibleRegion getVisibleRegion(LatLng center, double zoomLevel) {
|
|
320
|
-
DisplayMetrics metrics = mContext.getResources().getDisplayMetrics();
|
|
321
|
-
int[] contentPadding = mMap.getPadding();
|
|
322
|
-
|
|
323
|
-
int mapWidth = (int) ((mMap.getWidth() * 0.75 - (contentPadding[0] + contentPadding[2]))
|
|
324
|
-
/ metrics.scaledDensity);
|
|
325
|
-
int mapHeight = (int) ((mMap.getHeight() * 0.75 - (contentPadding[1] + contentPadding[3]))
|
|
326
|
-
/ metrics.scaledDensity);
|
|
327
|
-
VisibleRegion region = GeoViewport.getRegion(center, (int) zoomLevel, mapWidth, mapHeight);
|
|
328
|
-
return region;
|
|
329
|
-
}
|
|
330
|
-
|
|
331
|
-
public CameraPosition getCameraPosition() {
|
|
332
|
-
return mMap.getCameraPosition();
|
|
333
|
-
}
|
|
334
|
-
|
|
335
|
-
public void animateCamera(CameraUpdate cameraUpdate, MapLibreMap.CancelableCallback callback) {
|
|
336
|
-
mMap.animateCamera(cameraUpdate, callback);
|
|
337
|
-
}
|
|
338
|
-
|
|
339
|
-
public void moveCamera(CameraUpdate cameraUpdate, MapLibreMap.CancelableCallback callback) {
|
|
340
|
-
mMap.moveCamera(cameraUpdate, callback);
|
|
341
|
-
}
|
|
342
|
-
|
|
343
|
-
public void moveCamera(CameraUpdate cameraUpdate) {
|
|
344
|
-
mMap.moveCamera(cameraUpdate);
|
|
345
|
-
}
|
|
346
|
-
|
|
347
|
-
public void easeCamera(CameraUpdate cameraUpdate, int duration, boolean easingInterpolator,
|
|
348
|
-
MapLibreMap.CancelableCallback callback) {
|
|
349
|
-
mMap.easeCamera(cameraUpdate, duration, easingInterpolator, callback);
|
|
350
|
-
}
|
|
351
|
-
|
|
352
|
-
public void easeCamera(CameraUpdate cameraUpdate) {
|
|
353
|
-
mMap.easeCamera(cameraUpdate);
|
|
354
|
-
}
|
|
355
|
-
|
|
356
|
-
public MLRNPointAnnotation getPointAnnotationByID(String annotationID) {
|
|
357
|
-
if (annotationID == null) {
|
|
358
|
-
return null;
|
|
359
|
-
}
|
|
360
|
-
|
|
361
|
-
for (String key : mPointAnnotations.keySet()) {
|
|
362
|
-
MLRNPointAnnotation annotation = mPointAnnotations.get(key);
|
|
363
|
-
|
|
364
|
-
if (annotation != null && annotationID.equals(annotation.getID())) {
|
|
365
|
-
return annotation;
|
|
366
|
-
}
|
|
367
|
-
}
|
|
368
|
-
|
|
369
|
-
return null;
|
|
370
|
-
}
|
|
371
|
-
|
|
372
|
-
public MLRNPointAnnotation getPointAnnotationByMarkerID(long markerID) {
|
|
373
|
-
for (String key : mPointAnnotations.keySet()) {
|
|
374
|
-
MLRNPointAnnotation annotation = mPointAnnotations.get(key);
|
|
375
|
-
|
|
376
|
-
if (annotation != null && markerID == annotation.getMapboxID()) {
|
|
377
|
-
return annotation;
|
|
378
|
-
}
|
|
379
|
-
}
|
|
380
|
-
|
|
381
|
-
return null;
|
|
382
|
-
}
|
|
383
|
-
|
|
384
|
-
public MapLibreMap getMapboxMap() {
|
|
385
|
-
return mMap;
|
|
386
|
-
}
|
|
387
|
-
|
|
388
|
-
public SymbolManager getSymbolManager() {
|
|
389
|
-
return symbolManager;
|
|
390
|
-
}
|
|
391
|
-
|
|
392
|
-
public interface FoundLayerCallback {
|
|
393
|
-
public void found(Layer layer);
|
|
394
|
-
}
|
|
395
|
-
|
|
396
|
-
private Map<String, List<FoundLayerCallback>> layerWaiters = new HashMap<String, List<FoundLayerCallback>>();
|
|
397
|
-
|
|
398
|
-
public void layerAdded(Layer layer) {
|
|
399
|
-
String layerId = layer.getId();
|
|
400
|
-
|
|
401
|
-
List<FoundLayerCallback> callbacks = layerWaiters.get(layerId);
|
|
402
|
-
if (callbacks != null) {
|
|
403
|
-
for (FoundLayerCallback callback : callbacks) {
|
|
404
|
-
callback.found(layer);
|
|
405
|
-
}
|
|
406
|
-
}
|
|
407
|
-
layerWaiters.remove(layerId);
|
|
408
|
-
}
|
|
409
|
-
|
|
410
|
-
public void waitForLayer(String layerID, FoundLayerCallback callback) {
|
|
411
|
-
Layer layer = mMap.getStyle().getLayer(layerID);
|
|
412
|
-
if (layer != null) {
|
|
413
|
-
callback.found(layer);
|
|
414
|
-
} else {
|
|
415
|
-
List<FoundLayerCallback> waiters = layerWaiters.get(layerID);
|
|
416
|
-
if (waiters == null) {
|
|
417
|
-
waiters = new ArrayList<FoundLayerCallback>();
|
|
418
|
-
layerWaiters.put(layerID, waiters);
|
|
419
|
-
}
|
|
420
|
-
waiters.add(callback);
|
|
421
|
-
}
|
|
422
|
-
}
|
|
423
|
-
|
|
424
|
-
public boolean isJSONValid(String test) {
|
|
425
|
-
try {
|
|
426
|
-
new JSONObject(test);
|
|
427
|
-
} catch (JSONException ex) {
|
|
428
|
-
return false;
|
|
429
|
-
}
|
|
430
|
-
return true;
|
|
431
|
-
}
|
|
432
|
-
|
|
433
|
-
@Override
|
|
434
|
-
public void onMapReady(final MapLibreMap mapboxMap) {
|
|
435
|
-
mMap = mapboxMap;
|
|
436
|
-
|
|
437
|
-
if (isJSONValid(mMapStyle)) {
|
|
438
|
-
mMap.setStyle(new Style.Builder().fromJson(mMapStyle));
|
|
439
|
-
} else {
|
|
440
|
-
mMap.setStyle(new Style.Builder().fromUri(mMapStyle));
|
|
441
|
-
}
|
|
442
|
-
|
|
443
|
-
reflow();
|
|
444
|
-
|
|
445
|
-
mMap.getStyle(new Style.OnStyleLoaded() {
|
|
446
|
-
@Override
|
|
447
|
-
public void onStyleLoaded(@NonNull Style style) {
|
|
448
|
-
createSymbolManager(style);
|
|
449
|
-
setUpImage(style);
|
|
450
|
-
addQueuedFeatures();
|
|
451
|
-
setupLocalization(style);
|
|
452
|
-
}
|
|
453
|
-
});
|
|
454
|
-
|
|
455
|
-
updatePreferredFramesPerSecond();
|
|
456
|
-
updateInsets();
|
|
457
|
-
updateUISettings();
|
|
458
|
-
|
|
459
|
-
mMap.addOnCameraIdleListener(new MapLibreMap.OnCameraIdleListener() {
|
|
460
|
-
@Override
|
|
461
|
-
public void onCameraIdle() {
|
|
462
|
-
sendRegionDidChangeEvent();
|
|
463
|
-
}
|
|
464
|
-
});
|
|
465
|
-
|
|
466
|
-
mMap.addOnCameraMoveStartedListener(new MapLibreMap.OnCameraMoveStartedListener() {
|
|
467
|
-
@Override
|
|
468
|
-
public void onCameraMoveStarted(int reason) {
|
|
469
|
-
mCameraChangeTracker.setReason(reason);
|
|
470
|
-
handleMapChangedEvent(EventTypes.REGION_WILL_CHANGE);
|
|
471
|
-
}
|
|
472
|
-
});
|
|
473
|
-
|
|
474
|
-
mMap.addOnCameraMoveListener(new MapLibreMap.OnCameraMoveListener() {
|
|
475
|
-
@Override
|
|
476
|
-
public void onCameraMove() {
|
|
477
|
-
if (markerViewManager != null) {
|
|
478
|
-
markerViewManager.updateMarkers();
|
|
479
|
-
}
|
|
480
|
-
}
|
|
481
|
-
});
|
|
482
|
-
|
|
483
|
-
mMap.addOnMoveListener(new MapLibreMap.OnMoveListener() {
|
|
484
|
-
@Override
|
|
485
|
-
public void onMoveBegin(MoveGestureDetector detector) {
|
|
486
|
-
mCameraChangeTracker.setReason(CameraChangeTracker.USER_GESTURE);
|
|
487
|
-
handleMapChangedEvent(EventTypes.REGION_WILL_CHANGE);
|
|
488
|
-
}
|
|
489
|
-
|
|
490
|
-
@Override
|
|
491
|
-
public void onMove(MoveGestureDetector detector) {
|
|
492
|
-
mCameraChangeTracker.setReason(CameraChangeTracker.USER_GESTURE);
|
|
493
|
-
handleMapChangedEvent(EventTypes.REGION_IS_CHANGING);
|
|
494
|
-
}
|
|
495
|
-
|
|
496
|
-
@Override
|
|
497
|
-
public void onMoveEnd(MoveGestureDetector detector) {
|
|
498
|
-
}
|
|
499
|
-
});
|
|
500
|
-
}
|
|
501
|
-
|
|
502
|
-
public void reflow() {
|
|
503
|
-
mHandler.post(new Runnable() {
|
|
504
|
-
@Override
|
|
505
|
-
public void run() {
|
|
506
|
-
measure(View.MeasureSpec.makeMeasureSpec(getMeasuredWidth(), View.MeasureSpec.EXACTLY),
|
|
507
|
-
View.MeasureSpec.makeMeasureSpec(getMeasuredHeight(), View.MeasureSpec.EXACTLY));
|
|
508
|
-
layout(getLeft(), getTop(), getRight(), getBottom());
|
|
509
|
-
}
|
|
510
|
-
});
|
|
511
|
-
}
|
|
512
|
-
|
|
513
|
-
public void createSymbolManager(Style style) {
|
|
514
|
-
symbolManager = new SymbolManager(this, mMap, style);
|
|
515
|
-
symbolManager.setIconAllowOverlap(true);
|
|
516
|
-
symbolManager.addClickListener(new OnSymbolClickListener() {
|
|
517
|
-
@Override
|
|
518
|
-
public boolean onAnnotationClick(Symbol symbol) {
|
|
519
|
-
onMarkerClick(symbol);
|
|
520
|
-
return true;
|
|
521
|
-
}
|
|
522
|
-
});
|
|
523
|
-
symbolManager.addDragListener(new OnSymbolDragListener() {
|
|
524
|
-
@Override
|
|
525
|
-
public void onAnnotationDragStarted(Symbol symbol) {
|
|
526
|
-
mAnnotationClicked = true;
|
|
527
|
-
final long selectedMarkerID = symbol.getId();
|
|
528
|
-
MLRNPointAnnotation annotation = getPointAnnotationByMarkerID(selectedMarkerID);
|
|
529
|
-
if (annotation != null) {
|
|
530
|
-
annotation.onDragStart();
|
|
531
|
-
}
|
|
532
|
-
}
|
|
533
|
-
|
|
534
|
-
@Override
|
|
535
|
-
public void onAnnotationDrag(Symbol symbol) {
|
|
536
|
-
final long selectedMarkerID = symbol.getId();
|
|
537
|
-
MLRNPointAnnotation annotation = getPointAnnotationByMarkerID(selectedMarkerID);
|
|
538
|
-
if (annotation != null) {
|
|
539
|
-
annotation.onDrag();
|
|
540
|
-
}
|
|
541
|
-
}
|
|
542
|
-
|
|
543
|
-
@Override
|
|
544
|
-
public void onAnnotationDragFinished(Symbol symbol) {
|
|
545
|
-
mAnnotationClicked = false;
|
|
546
|
-
final long selectedMarkerID = symbol.getId();
|
|
547
|
-
MLRNPointAnnotation annotation = getPointAnnotationByMarkerID(selectedMarkerID);
|
|
548
|
-
if (annotation != null) {
|
|
549
|
-
annotation.onDragEnd();
|
|
550
|
-
}
|
|
551
|
-
}
|
|
552
|
-
});
|
|
553
|
-
mMap.addOnMapClickListener(this);
|
|
554
|
-
mMap.addOnMapLongClickListener(this);
|
|
555
|
-
}
|
|
556
|
-
|
|
557
|
-
public void addQueuedFeatures() {
|
|
558
|
-
if (mQueuedFeatures != null && mQueuedFeatures.size() > 0) {
|
|
559
|
-
for (int i = 0; i < mQueuedFeatures.size(); i++) {
|
|
560
|
-
AbstractMapFeature feature = mQueuedFeatures.get(i);
|
|
561
|
-
feature.addToMap(this);
|
|
562
|
-
mFeatures.add(feature);
|
|
563
|
-
}
|
|
564
|
-
mQueuedFeatures = null;
|
|
565
|
-
}
|
|
566
|
-
}
|
|
567
|
-
|
|
568
|
-
private void setupLocalization(Style style) {
|
|
569
|
-
mLocalizationPlugin = new LocalizationPlugin(MLRNMapView.this, mMap, style);
|
|
570
|
-
if (mLocalizeLabels) {
|
|
571
|
-
try {
|
|
572
|
-
mLocalizationPlugin.matchMapLanguageWithDeviceDefault();
|
|
573
|
-
} catch (Exception e) {
|
|
574
|
-
final String localeString = Locale.getDefault().toString();
|
|
575
|
-
Logger.w(LOG_TAG, String.format("Could not find matching locale for %s", localeString));
|
|
576
|
-
}
|
|
577
|
-
}
|
|
578
|
-
}
|
|
579
|
-
|
|
580
|
-
@Override
|
|
581
|
-
public boolean onTouchEvent(MotionEvent ev) {
|
|
582
|
-
boolean result = super.onTouchEvent(ev);
|
|
583
|
-
|
|
584
|
-
if (result && mScrollEnabled) {
|
|
585
|
-
requestDisallowInterceptTouchEvent(true);
|
|
586
|
-
}
|
|
587
|
-
|
|
588
|
-
return result;
|
|
589
|
-
}
|
|
590
|
-
|
|
591
|
-
@Override
|
|
592
|
-
protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
|
|
593
|
-
if (!mPaused) {
|
|
594
|
-
if (markerViewManager != null) {
|
|
595
|
-
markerViewManager.removeViews();
|
|
596
|
-
}
|
|
597
|
-
super.onLayout(changed, left, top, right, bottom);
|
|
598
|
-
if (markerViewManager != null) {
|
|
599
|
-
markerViewManager.restoreViews();
|
|
600
|
-
}
|
|
601
|
-
}
|
|
602
|
-
}
|
|
603
|
-
|
|
604
|
-
@Override
|
|
605
|
-
public boolean onMapClick(@NonNull LatLng point) {
|
|
606
|
-
if (mAnnotationClicked) {
|
|
607
|
-
mAnnotationClicked = false;
|
|
608
|
-
return true;
|
|
609
|
-
}
|
|
610
|
-
|
|
611
|
-
PointF screenPoint = mMap.getProjection().toScreenLocation(point);
|
|
612
|
-
List<MLRNSource> touchableSources = getAllTouchableSources();
|
|
613
|
-
|
|
614
|
-
Map<String, List<Feature>> hits = new HashMap<>();
|
|
615
|
-
List<MLRNSource> hitTouchableSources = new ArrayList<>();
|
|
616
|
-
for (MLRNSource touchableSource : touchableSources) {
|
|
617
|
-
Map<String, Double> hitbox = touchableSource.getTouchHitbox();
|
|
618
|
-
if (hitbox == null) {
|
|
619
|
-
continue;
|
|
620
|
-
}
|
|
621
|
-
|
|
622
|
-
float halfWidth = hitbox.get("width").floatValue() / 2.0f;
|
|
623
|
-
float halfHeight = hitbox.get("height").floatValue() / 2.0f;
|
|
624
|
-
|
|
625
|
-
RectF hitboxF = new RectF();
|
|
626
|
-
hitboxF.set(screenPoint.x - halfWidth, screenPoint.y - halfHeight, screenPoint.x + halfWidth,
|
|
627
|
-
screenPoint.y + halfHeight);
|
|
628
|
-
|
|
629
|
-
List<Feature> features = mMap.queryRenderedFeatures(hitboxF, touchableSource.getLayerIDs());
|
|
630
|
-
if (features.size() > 0) {
|
|
631
|
-
hits.put(touchableSource.getID(), features);
|
|
632
|
-
hitTouchableSources.add(touchableSource);
|
|
633
|
-
}
|
|
634
|
-
}
|
|
635
|
-
|
|
636
|
-
if (hits.size() > 0) {
|
|
637
|
-
MLRNSource source = getTouchableSourceWithHighestZIndex(hitTouchableSources);
|
|
638
|
-
if (source != null && source.hasPressListener()) {
|
|
639
|
-
source.onPress(new MLRNSource.OnPressEvent(
|
|
640
|
-
hits.get(source.getID()),
|
|
641
|
-
point,
|
|
642
|
-
screenPoint));
|
|
643
|
-
return true;
|
|
644
|
-
}
|
|
645
|
-
}
|
|
646
|
-
|
|
647
|
-
MapClickEvent event = new MapClickEvent(this, point, screenPoint);
|
|
648
|
-
mManager.handleEvent(event);
|
|
649
|
-
return false;
|
|
650
|
-
}
|
|
651
|
-
|
|
652
|
-
@Override
|
|
653
|
-
public boolean onMapLongClick(@NonNull LatLng point) {
|
|
654
|
-
if (mAnnotationClicked) {
|
|
655
|
-
mAnnotationClicked = false;
|
|
656
|
-
return true;
|
|
657
|
-
}
|
|
658
|
-
PointF screenPoint = mMap.getProjection().toScreenLocation(point);
|
|
659
|
-
MapClickEvent event = new MapClickEvent(this, point, screenPoint, EventTypes.MAP_LONG_CLICK);
|
|
660
|
-
mManager.handleEvent(event);
|
|
661
|
-
return false;
|
|
662
|
-
}
|
|
663
|
-
|
|
664
|
-
public void onMarkerClick(@NonNull Symbol symbol) {
|
|
665
|
-
mAnnotationClicked = true;
|
|
666
|
-
final long selectedMarkerID = symbol.getId();
|
|
667
|
-
|
|
668
|
-
MLRNPointAnnotation activeAnnotation = null;
|
|
669
|
-
MLRNPointAnnotation nextActiveAnnotation = null;
|
|
670
|
-
|
|
671
|
-
for (String key : mPointAnnotations.keySet()) {
|
|
672
|
-
MLRNPointAnnotation annotation = mPointAnnotations.get(key);
|
|
673
|
-
final long curMarkerID = annotation.getMapboxID();
|
|
674
|
-
if (mActiveMarkerID == curMarkerID) {
|
|
675
|
-
activeAnnotation = annotation;
|
|
676
|
-
}
|
|
677
|
-
if (selectedMarkerID == curMarkerID && mActiveMarkerID != curMarkerID) {
|
|
678
|
-
nextActiveAnnotation = annotation;
|
|
679
|
-
}
|
|
680
|
-
}
|
|
681
|
-
|
|
682
|
-
if (activeAnnotation != null) {
|
|
683
|
-
deselectAnnotation(activeAnnotation);
|
|
684
|
-
}
|
|
685
|
-
|
|
686
|
-
if (nextActiveAnnotation != null) {
|
|
687
|
-
selectAnnotation(nextActiveAnnotation);
|
|
688
|
-
}
|
|
689
|
-
|
|
690
|
-
}
|
|
691
|
-
|
|
692
|
-
public void selectAnnotation(MLRNPointAnnotation annotation) {
|
|
693
|
-
mActiveMarkerID = annotation.getMapboxID();
|
|
694
|
-
annotation.onSelect(true);
|
|
695
|
-
}
|
|
696
|
-
|
|
697
|
-
public void deselectAnnotation(MLRNPointAnnotation annotation) {
|
|
698
|
-
mActiveMarkerID = -1;
|
|
699
|
-
annotation.onDeselect();
|
|
700
|
-
}
|
|
701
|
-
|
|
702
|
-
@Override
|
|
703
|
-
public void onCameraDidChange(boolean animated) {
|
|
704
|
-
mCameraChangeTracker.setIsAnimating(animated);
|
|
705
|
-
}
|
|
706
|
-
|
|
707
|
-
@Override
|
|
708
|
-
public void onCameraIsChanging() {
|
|
709
|
-
handleMapChangedEvent(EventTypes.REGION_IS_CHANGING);
|
|
710
|
-
}
|
|
711
|
-
|
|
712
|
-
@Override
|
|
713
|
-
public void onDidFailLoadingMap(String errorMessage) {
|
|
714
|
-
handleMapChangedEvent(EventTypes.DID_FAIL_LOADING_MAP);
|
|
715
|
-
}
|
|
716
|
-
|
|
717
|
-
@Override
|
|
718
|
-
public void onDidFinishLoadingMap() {
|
|
719
|
-
handleMapChangedEvent(EventTypes.DID_FINISH_LOADING_MAP);
|
|
720
|
-
}
|
|
721
|
-
|
|
722
|
-
@Override
|
|
723
|
-
public void onWillStartRenderingFrame() {
|
|
724
|
-
handleMapChangedEvent(EventTypes.WILL_START_RENDERING_FRAME);
|
|
725
|
-
}
|
|
726
|
-
|
|
727
|
-
@Override
|
|
728
|
-
public void onDidFinishRenderingFrame(boolean fully, double frameEncodingTime, double frameRenderingTime) {
|
|
729
|
-
if (fully) {
|
|
730
|
-
handleMapChangedEvent(EventTypes.DID_FINISH_RENDERING_FRAME_FULLY);
|
|
731
|
-
} else {
|
|
732
|
-
handleMapChangedEvent(EventTypes.DID_FINISH_RENDERING_FRAME);
|
|
733
|
-
}
|
|
734
|
-
}
|
|
735
|
-
|
|
736
|
-
@Override
|
|
737
|
-
public void onWillStartRenderingMap() {
|
|
738
|
-
handleMapChangedEvent(EventTypes.WILL_START_RENDERING_MAP);
|
|
739
|
-
}
|
|
740
|
-
|
|
741
|
-
@Override
|
|
742
|
-
public void onDidFinishRenderingMap(boolean fully) {
|
|
743
|
-
if (fully) {
|
|
744
|
-
for (Pair<Integer, ReadableArray> preRenderMethod : mPreRenderMethods) {
|
|
745
|
-
Integer methodID = preRenderMethod.first;
|
|
746
|
-
ReadableArray args = preRenderMethod.second;
|
|
747
|
-
mManager.receiveCommand(this, methodID, args);
|
|
748
|
-
}
|
|
749
|
-
mPreRenderMethods.clear();
|
|
750
|
-
handleMapChangedEvent(EventTypes.DID_FINISH_RENDERING_MAP_FULLY);
|
|
751
|
-
} else {
|
|
752
|
-
handleMapChangedEvent(EventTypes.DID_FINISH_RENDERING_MAP);
|
|
753
|
-
}
|
|
754
|
-
}
|
|
755
|
-
|
|
756
|
-
@Override
|
|
757
|
-
public void onDidFinishLoadingStyle() {
|
|
758
|
-
handleMapChangedEvent(EventTypes.DID_FINISH_LOADING_STYLE);
|
|
759
|
-
}
|
|
760
|
-
|
|
761
|
-
@Override
|
|
762
|
-
public void onStyleImageMissing(@NonNull String id) {
|
|
763
|
-
for (MLRNImages images : mImages) {
|
|
764
|
-
if (images.addMissingImageToStyle(id, mMap)) {
|
|
765
|
-
return;
|
|
766
|
-
}
|
|
767
|
-
}
|
|
768
|
-
for (MLRNImages images : mImages) {
|
|
769
|
-
images.sendImageMissingEvent(id, mMap);
|
|
770
|
-
}
|
|
771
|
-
}
|
|
772
|
-
|
|
773
|
-
private float getDisplayDensity() {
|
|
774
|
-
return mContext.getResources().getDisplayMetrics().density;
|
|
775
|
-
}
|
|
776
|
-
|
|
777
|
-
public void setReactMapStyle(String mapStyle) {
|
|
778
|
-
mMapStyle = mapStyle;
|
|
779
|
-
|
|
780
|
-
if (mMap != null) {
|
|
781
|
-
removeAllSourcesFromMap();
|
|
782
|
-
|
|
783
|
-
if (isJSONValid(mMapStyle)) {
|
|
784
|
-
mMap.setStyle(new Style.Builder().fromJson(mMapStyle), new Style.OnStyleLoaded() {
|
|
785
|
-
@Override
|
|
786
|
-
public void onStyleLoaded(@NonNull Style style) {
|
|
787
|
-
addAllSourcesToMap();
|
|
788
|
-
}
|
|
789
|
-
});
|
|
790
|
-
} else {
|
|
791
|
-
mMap.setStyle(mapStyle, new Style.OnStyleLoaded() {
|
|
792
|
-
@Override
|
|
793
|
-
public void onStyleLoaded(@NonNull Style style) {
|
|
794
|
-
addAllSourcesToMap();
|
|
795
|
-
}
|
|
796
|
-
});
|
|
797
|
-
}
|
|
798
|
-
}
|
|
799
|
-
}
|
|
800
|
-
|
|
801
|
-
public void setReactPreferredFramesPerSecond(Integer preferredFramesPerSecond) {
|
|
802
|
-
mPreferredFramesPerSecond = preferredFramesPerSecond;
|
|
803
|
-
updatePreferredFramesPerSecond();
|
|
804
|
-
}
|
|
805
|
-
|
|
806
|
-
public void setReactContentInset(ReadableArray array) {
|
|
807
|
-
mInsets = array;
|
|
808
|
-
updateInsets();
|
|
809
|
-
}
|
|
810
|
-
|
|
811
|
-
public void setLocalizeLabels(boolean localizeLabels) {
|
|
812
|
-
mLocalizeLabels = localizeLabels;
|
|
813
|
-
}
|
|
814
|
-
|
|
815
|
-
public void setReactZoomEnabled(boolean zoomEnabled) {
|
|
816
|
-
mZoomEnabled = zoomEnabled;
|
|
817
|
-
updateUISettings();
|
|
818
|
-
}
|
|
819
|
-
|
|
820
|
-
public void setReactScrollEnabled(boolean scrollEnabled) {
|
|
821
|
-
mScrollEnabled = scrollEnabled;
|
|
822
|
-
updateUISettings();
|
|
823
|
-
}
|
|
824
|
-
|
|
825
|
-
public void setReactPitchEnabled(boolean pitchEnabled) {
|
|
826
|
-
mPitchEnabled = pitchEnabled;
|
|
827
|
-
updateUISettings();
|
|
828
|
-
}
|
|
829
|
-
|
|
830
|
-
public void setReactRotateEnabled(boolean rotateEnabled) {
|
|
831
|
-
mRotateEnabled = rotateEnabled;
|
|
832
|
-
updateUISettings();
|
|
833
|
-
}
|
|
834
|
-
|
|
835
|
-
public void setReactLogoEnabled(boolean logoEnabled) {
|
|
836
|
-
mLogoEnabled = logoEnabled;
|
|
837
|
-
updateUISettings();
|
|
838
|
-
}
|
|
839
|
-
|
|
840
|
-
public void setReactLogoPosition(ReadableMap position) {
|
|
841
|
-
if (position == null) {
|
|
842
|
-
// reset from explicit to default
|
|
843
|
-
if (mLogoGravity != null) {
|
|
844
|
-
MapLibreMapOptions defaultOptions = MapLibreMapOptions.createFromAttributes(mContext);
|
|
845
|
-
mLogoGravity = defaultOptions.getLogoGravity();
|
|
846
|
-
mLogoMargins = Arrays.copyOf(defaultOptions.getLogoMargins(), 4);
|
|
847
|
-
updateUISettings();
|
|
848
|
-
}
|
|
849
|
-
return;
|
|
850
|
-
}
|
|
851
|
-
|
|
852
|
-
mLogoGravity = Gravity.NO_GRAVITY;
|
|
853
|
-
if (position.hasKey("left")) {
|
|
854
|
-
mLogoGravity |= Gravity.START;
|
|
855
|
-
}
|
|
856
|
-
if (position.hasKey("right")) {
|
|
857
|
-
mLogoGravity |= Gravity.END;
|
|
858
|
-
}
|
|
859
|
-
if (position.hasKey("top")) {
|
|
860
|
-
mLogoGravity |= Gravity.TOP;
|
|
861
|
-
}
|
|
862
|
-
if (position.hasKey("bottom")) {
|
|
863
|
-
mLogoGravity |= Gravity.BOTTOM;
|
|
864
|
-
}
|
|
865
|
-
float density = getDisplayDensity();
|
|
866
|
-
mLogoMargins = new int[] {
|
|
867
|
-
position.hasKey("left") ? (int) density * position.getInt("left") : 0,
|
|
868
|
-
position.hasKey("top") ? (int) density * position.getInt("top") : 0,
|
|
869
|
-
position.hasKey("right") ? (int) density * position.getInt("right") : 0,
|
|
870
|
-
position.hasKey("bottom") ? (int) density * position.getInt("bottom") : 0
|
|
871
|
-
};
|
|
872
|
-
updateUISettings();
|
|
873
|
-
}
|
|
874
|
-
|
|
875
|
-
public void setReactCompassEnabled(boolean compassEnabled) {
|
|
876
|
-
mCompassEnabled = compassEnabled;
|
|
877
|
-
updateUISettings();
|
|
878
|
-
}
|
|
879
|
-
|
|
880
|
-
public void setReactCompassViewMargins(ReadableMap compassViewMargins) {
|
|
881
|
-
mCompassViewMargins = compassViewMargins;
|
|
882
|
-
updateUISettings();
|
|
883
|
-
}
|
|
884
|
-
|
|
885
|
-
public void setReactCompassViewPosition(int compassViewPosition) {
|
|
886
|
-
mCompassViewPosition = compassViewPosition;
|
|
887
|
-
updateUISettings();
|
|
888
|
-
}
|
|
889
|
-
|
|
890
|
-
public void setReactAttributionEnabled(boolean attributionEnabled) {
|
|
891
|
-
mAttributionEnabled = attributionEnabled;
|
|
892
|
-
updateUISettings();
|
|
893
|
-
}
|
|
894
|
-
|
|
895
|
-
public void setReactAttributionPosition(ReadableMap position) {
|
|
896
|
-
if (position == null) {
|
|
897
|
-
// reset from explicit to default
|
|
898
|
-
if (mAttributionGravity != null) {
|
|
899
|
-
MapLibreMapOptions defaultOptions = MapLibreMapOptions.createFromAttributes(mContext);
|
|
900
|
-
mAttributionGravity = defaultOptions.getAttributionGravity();
|
|
901
|
-
mAttributionMargin = Arrays.copyOf(defaultOptions.getAttributionMargins(), 4);
|
|
902
|
-
updateUISettings();
|
|
903
|
-
}
|
|
904
|
-
return;
|
|
905
|
-
}
|
|
906
|
-
mAttributionGravity = Gravity.NO_GRAVITY;
|
|
907
|
-
if (position.hasKey("left")) {
|
|
908
|
-
mAttributionGravity |= Gravity.START;
|
|
909
|
-
}
|
|
910
|
-
if (position.hasKey("right")) {
|
|
911
|
-
mAttributionGravity |= Gravity.END;
|
|
912
|
-
}
|
|
913
|
-
if (position.hasKey("top")) {
|
|
914
|
-
mAttributionGravity |= Gravity.TOP;
|
|
915
|
-
}
|
|
916
|
-
if (position.hasKey("bottom")) {
|
|
917
|
-
mAttributionGravity |= Gravity.BOTTOM;
|
|
918
|
-
}
|
|
919
|
-
float density = getDisplayDensity();
|
|
920
|
-
mAttributionMargin = new int[] {
|
|
921
|
-
position.hasKey("left") ? Math.round(density * position.getInt("left")) : 0,
|
|
922
|
-
position.hasKey("top") ? Math.round(density * position.getInt("top")) : 0,
|
|
923
|
-
position.hasKey("right") ? Math.round(density * position.getInt("right")) : 0,
|
|
924
|
-
position.hasKey("bottom") ? Math.round(density * position.getInt("bottom")) : 0
|
|
925
|
-
};
|
|
926
|
-
updateUISettings();
|
|
927
|
-
}
|
|
928
|
-
|
|
929
|
-
public void queryRenderedFeaturesAtPoint(String callbackID, PointF point, Expression filter,
|
|
930
|
-
List<String> layerIDs) {
|
|
931
|
-
List<Feature> features = mMap.queryRenderedFeatures(point, filter,
|
|
932
|
-
layerIDs.toArray(new String[layerIDs.size()]));
|
|
933
|
-
|
|
934
|
-
WritableMap payload = new WritableNativeMap();
|
|
935
|
-
payload.putString("data", FeatureCollection.fromFeatures(features).toJson());
|
|
936
|
-
|
|
937
|
-
AndroidCallbackEvent event = new AndroidCallbackEvent(this, callbackID, payload);
|
|
938
|
-
mManager.handleEvent(event);
|
|
939
|
-
}
|
|
940
|
-
|
|
941
|
-
public void getZoom(String callbackID) {
|
|
942
|
-
CameraPosition position = mMap.getCameraPosition();
|
|
943
|
-
|
|
944
|
-
WritableMap payload = new WritableNativeMap();
|
|
945
|
-
payload.putDouble("zoom", position.zoom);
|
|
946
|
-
|
|
947
|
-
AndroidCallbackEvent event = new AndroidCallbackEvent(this, callbackID, payload);
|
|
948
|
-
mManager.handleEvent(event);
|
|
949
|
-
}
|
|
950
|
-
|
|
951
|
-
public void queryRenderedFeaturesInRect(String callbackID, RectF rect, Expression filter, List<String> layerIDs) {
|
|
952
|
-
List<Feature> features = mMap.queryRenderedFeatures(rect, filter,
|
|
953
|
-
layerIDs.toArray(new String[layerIDs.size()]));
|
|
954
|
-
|
|
955
|
-
WritableMap payload = new WritableNativeMap();
|
|
956
|
-
payload.putString("data", FeatureCollection.fromFeatures(features).toJson());
|
|
957
|
-
|
|
958
|
-
AndroidCallbackEvent event = new AndroidCallbackEvent(this, callbackID, payload);
|
|
959
|
-
mManager.handleEvent(event);
|
|
960
|
-
}
|
|
961
|
-
|
|
962
|
-
public void getVisibleBounds(String callbackID) {
|
|
963
|
-
VisibleRegion region = mMap.getProjection().getVisibleRegion();
|
|
964
|
-
|
|
965
|
-
WritableMap payload = new WritableNativeMap();
|
|
966
|
-
payload.putArray("visibleBounds", GeoJSONUtils.fromLatLngBounds(region.latLngBounds));
|
|
967
|
-
|
|
968
|
-
AndroidCallbackEvent event = new AndroidCallbackEvent(this, callbackID, payload);
|
|
969
|
-
mManager.handleEvent(event);
|
|
970
|
-
}
|
|
971
|
-
|
|
972
|
-
public void getPointInView(String callbackID, LatLng mapCoordinate) {
|
|
973
|
-
|
|
974
|
-
PointF pointInView = mMap.getProjection().toScreenLocation(mapCoordinate);
|
|
975
|
-
float density = getDisplayDensity();
|
|
976
|
-
pointInView.x /= density;
|
|
977
|
-
pointInView.y /= density;
|
|
978
|
-
WritableMap payload = new WritableNativeMap();
|
|
979
|
-
|
|
980
|
-
WritableArray array = new WritableNativeArray();
|
|
981
|
-
array.pushDouble(pointInView.x);
|
|
982
|
-
array.pushDouble(pointInView.y);
|
|
983
|
-
payload.putArray("pointInView", array);
|
|
984
|
-
|
|
985
|
-
AndroidCallbackEvent event = new AndroidCallbackEvent(this, callbackID, payload);
|
|
986
|
-
mManager.handleEvent(event);
|
|
987
|
-
}
|
|
988
|
-
|
|
989
|
-
public void getCoordinateFromView(String callbackID, PointF pointInView) {
|
|
990
|
-
float density = getDisplayDensity();
|
|
991
|
-
pointInView.x *= density;
|
|
992
|
-
pointInView.y *= density;
|
|
993
|
-
|
|
994
|
-
LatLng mapCoordinate = mMap.getProjection().fromScreenLocation(pointInView);
|
|
995
|
-
WritableMap payload = new WritableNativeMap();
|
|
996
|
-
|
|
997
|
-
WritableArray array = new WritableNativeArray();
|
|
998
|
-
array.pushDouble(mapCoordinate.getLongitude());
|
|
999
|
-
array.pushDouble(mapCoordinate.getLatitude());
|
|
1000
|
-
payload.putArray("coordinateFromView", array);
|
|
1001
|
-
|
|
1002
|
-
AndroidCallbackEvent event = new AndroidCallbackEvent(this, callbackID, payload);
|
|
1003
|
-
mManager.handleEvent(event);
|
|
1004
|
-
}
|
|
1005
|
-
|
|
1006
|
-
public void takeSnap(final String callbackID, final boolean writeToDisk) {
|
|
1007
|
-
|
|
1008
|
-
if (mMap == null) {
|
|
1009
|
-
throw new Error("takeSnap should only be called after the map has rendered");
|
|
1010
|
-
}
|
|
1011
|
-
|
|
1012
|
-
mMap.snapshot(new MapLibreMap.SnapshotReadyCallback() {
|
|
1013
|
-
@Override
|
|
1014
|
-
public void onSnapshotReady(Bitmap snapshot) {
|
|
1015
|
-
WritableMap payload = new WritableNativeMap();
|
|
1016
|
-
String uri = writeToDisk ? BitmapUtils.createTempFile(mContext, snapshot)
|
|
1017
|
-
: BitmapUtils.createBase64(snapshot);
|
|
1018
|
-
payload.putString("uri", uri);
|
|
1019
|
-
|
|
1020
|
-
AndroidCallbackEvent event = new AndroidCallbackEvent(MLRNMapView.this, callbackID, payload);
|
|
1021
|
-
mManager.handleEvent(event);
|
|
1022
|
-
}
|
|
1023
|
-
});
|
|
1024
|
-
}
|
|
1025
|
-
|
|
1026
|
-
public void getCenter(String callbackID) {
|
|
1027
|
-
LatLng center = mMap.getCameraPosition().target;
|
|
1028
|
-
|
|
1029
|
-
WritableArray array = new WritableNativeArray();
|
|
1030
|
-
array.pushDouble(center.getLongitude());
|
|
1031
|
-
array.pushDouble(center.getLatitude());
|
|
1032
|
-
WritableMap payload = new WritableNativeMap();
|
|
1033
|
-
payload.putArray("center", array);
|
|
1034
|
-
|
|
1035
|
-
AndroidCallbackEvent event = new AndroidCallbackEvent(this, callbackID, payload);
|
|
1036
|
-
mManager.handleEvent(event);
|
|
1037
|
-
}
|
|
1038
|
-
|
|
1039
|
-
public void showAttribution() {
|
|
1040
|
-
AttributionDialogManager manager = new AttributionDialogManager(mContext, mMap);
|
|
1041
|
-
manager.onClick(this);
|
|
1042
|
-
}
|
|
1043
|
-
|
|
1044
|
-
public void setSourceVisibility(final boolean visible, @NonNull final String sourceId,
|
|
1045
|
-
@Nullable final String sourceLayerId) {
|
|
1046
|
-
if (mMap == null) {
|
|
1047
|
-
return;
|
|
1048
|
-
}
|
|
1049
|
-
mMap.getStyle(new Style.OnStyleLoaded() {
|
|
1050
|
-
@Override
|
|
1051
|
-
public void onStyleLoaded(@NonNull Style style) {
|
|
1052
|
-
List<Layer> layers = style.getLayers();
|
|
1053
|
-
for (Layer layer : layers) {
|
|
1054
|
-
LayerSourceInfo layerSourceInfo = new LayerSourceInfo(layer);
|
|
1055
|
-
if (layerSourceInfo.sourceId.equals(sourceId) && (sourceLayerId == null
|
|
1056
|
-
|| sourceLayerId.equals(layerSourceInfo.sourceLayerId))) {
|
|
1057
|
-
layer.setProperties(visibility(visible ? Property.VISIBLE : Property.NONE));
|
|
1058
|
-
}
|
|
1059
|
-
}
|
|
1060
|
-
}
|
|
1061
|
-
});
|
|
1062
|
-
}
|
|
1063
|
-
|
|
1064
|
-
public void init() {
|
|
1065
|
-
// Required for rendering properly in Android Oreo
|
|
1066
|
-
getViewTreeObserver().dispatchOnGlobalLayout();
|
|
1067
|
-
}
|
|
1068
|
-
|
|
1069
|
-
public boolean isDestroyed() {
|
|
1070
|
-
return mDestroyed;
|
|
1071
|
-
}
|
|
1072
|
-
|
|
1073
|
-
public void getStyle(Style.OnStyleLoaded onStyleLoaded) {
|
|
1074
|
-
if (mMap == null) {
|
|
1075
|
-
return;
|
|
1076
|
-
}
|
|
1077
|
-
|
|
1078
|
-
mMap.getStyle(onStyleLoaded);
|
|
1079
|
-
}
|
|
1080
|
-
|
|
1081
|
-
private void updateUISettings() {
|
|
1082
|
-
if (mMap == null) {
|
|
1083
|
-
return;
|
|
1084
|
-
}
|
|
1085
|
-
|
|
1086
|
-
UiSettings uiSettings = mMap.getUiSettings();
|
|
1087
|
-
|
|
1088
|
-
if (mScrollEnabled != null && uiSettings.isScrollGesturesEnabled() != mScrollEnabled) {
|
|
1089
|
-
uiSettings.setScrollGesturesEnabled(mScrollEnabled);
|
|
1090
|
-
if (!mScrollEnabled) {
|
|
1091
|
-
mMap.getGesturesManager().getMoveGestureDetector().interrupt();
|
|
1092
|
-
}
|
|
1093
|
-
}
|
|
1094
|
-
|
|
1095
|
-
if (mPitchEnabled != null && uiSettings.isTiltGesturesEnabled() != mPitchEnabled) {
|
|
1096
|
-
uiSettings.setTiltGesturesEnabled(mPitchEnabled);
|
|
1097
|
-
}
|
|
1098
|
-
|
|
1099
|
-
if (mRotateEnabled != null && uiSettings.isRotateGesturesEnabled() != mRotateEnabled) {
|
|
1100
|
-
uiSettings.setRotateGesturesEnabled(mRotateEnabled);
|
|
1101
|
-
if (!mRotateEnabled) {
|
|
1102
|
-
mMap.getGesturesManager().getRotateGestureDetector().interrupt();
|
|
1103
|
-
}
|
|
1104
|
-
}
|
|
1105
|
-
|
|
1106
|
-
if (mAttributionEnabled != null && uiSettings.isAttributionEnabled() != mAttributionEnabled) {
|
|
1107
|
-
uiSettings.setAttributionEnabled(mAttributionEnabled);
|
|
1108
|
-
}
|
|
1109
|
-
|
|
1110
|
-
if (mAttributionGravity != null && uiSettings.getAttributionGravity() != mAttributionGravity) {
|
|
1111
|
-
uiSettings.setAttributionGravity(mAttributionGravity);
|
|
1112
|
-
}
|
|
1113
|
-
|
|
1114
|
-
if (mAttributionMargin != null &&
|
|
1115
|
-
(uiSettings.getAttributionMarginLeft() != mAttributionMargin[0] ||
|
|
1116
|
-
uiSettings.getAttributionMarginTop() != mAttributionMargin[1] ||
|
|
1117
|
-
uiSettings.getAttributionMarginRight() != mAttributionMargin[2] ||
|
|
1118
|
-
uiSettings.getAttributionMarginBottom() != mAttributionMargin[3])) {
|
|
1119
|
-
uiSettings.setAttributionMargins(
|
|
1120
|
-
mAttributionMargin[0],
|
|
1121
|
-
mAttributionMargin[1],
|
|
1122
|
-
mAttributionMargin[2],
|
|
1123
|
-
mAttributionMargin[3]);
|
|
1124
|
-
}
|
|
1125
|
-
|
|
1126
|
-
if (mTintColor != null) {
|
|
1127
|
-
uiSettings.setAttributionTintColor(mTintColor);
|
|
1128
|
-
}
|
|
1129
|
-
|
|
1130
|
-
if (mLogoEnabled != null && uiSettings.isLogoEnabled() != mLogoEnabled) {
|
|
1131
|
-
uiSettings.setLogoEnabled(mLogoEnabled);
|
|
1132
|
-
}
|
|
1133
|
-
|
|
1134
|
-
if (mLogoGravity != null && uiSettings.getLogoGravity() != mLogoGravity) {
|
|
1135
|
-
uiSettings.setLogoGravity(mLogoGravity);
|
|
1136
|
-
}
|
|
1137
|
-
|
|
1138
|
-
if (mLogoMargins != null &&
|
|
1139
|
-
(uiSettings.getLogoMarginLeft() != mLogoMargins[0] ||
|
|
1140
|
-
uiSettings.getLogoMarginTop() != mLogoMargins[1] ||
|
|
1141
|
-
uiSettings.getLogoMarginRight() != mLogoMargins[2] ||
|
|
1142
|
-
uiSettings.getLogoMarginBottom() != mLogoMargins[3])) {
|
|
1143
|
-
uiSettings.setLogoMargins(
|
|
1144
|
-
mLogoMargins[0],
|
|
1145
|
-
mLogoMargins[1],
|
|
1146
|
-
mLogoMargins[2],
|
|
1147
|
-
mLogoMargins[3]);
|
|
1148
|
-
}
|
|
1149
|
-
|
|
1150
|
-
if (mCompassEnabled != null && uiSettings.isCompassEnabled() != mCompassEnabled) {
|
|
1151
|
-
uiSettings.setCompassEnabled(mCompassEnabled);
|
|
1152
|
-
}
|
|
1153
|
-
|
|
1154
|
-
if (mCompassViewPosition != -1 && uiSettings.isCompassEnabled()) {
|
|
1155
|
-
switch (mCompassViewPosition) {
|
|
1156
|
-
case 0:
|
|
1157
|
-
uiSettings.setCompassGravity(Gravity.TOP | Gravity.START);
|
|
1158
|
-
break;
|
|
1159
|
-
case 1:
|
|
1160
|
-
uiSettings.setCompassGravity(Gravity.TOP | Gravity.END);
|
|
1161
|
-
break;
|
|
1162
|
-
case 2:
|
|
1163
|
-
uiSettings.setCompassGravity(Gravity.BOTTOM | Gravity.START);
|
|
1164
|
-
break;
|
|
1165
|
-
case 3:
|
|
1166
|
-
uiSettings.setCompassGravity(Gravity.BOTTOM | Gravity.END);
|
|
1167
|
-
break;
|
|
1168
|
-
}
|
|
1169
|
-
}
|
|
1170
|
-
|
|
1171
|
-
if (mCompassViewMargins != null && uiSettings.isCompassEnabled()) {
|
|
1172
|
-
float pixelDensity = getResources().getDisplayMetrics().density;
|
|
1173
|
-
|
|
1174
|
-
int x = Math.round(mCompassViewMargins.getInt("x") * pixelDensity);
|
|
1175
|
-
int y = Math.round(mCompassViewMargins.getInt("y") * pixelDensity);
|
|
1176
|
-
|
|
1177
|
-
switch (uiSettings.getCompassGravity()) {
|
|
1178
|
-
case Gravity.TOP | Gravity.START:
|
|
1179
|
-
uiSettings.setCompassMargins(x, y, 0, 0);
|
|
1180
|
-
break;
|
|
1181
|
-
default:
|
|
1182
|
-
case Gravity.TOP | Gravity.END:
|
|
1183
|
-
uiSettings.setCompassMargins(0, y, x, 0);
|
|
1184
|
-
break;
|
|
1185
|
-
case Gravity.BOTTOM | Gravity.START:
|
|
1186
|
-
uiSettings.setCompassMargins(x, 0, 0, y);
|
|
1187
|
-
break;
|
|
1188
|
-
case Gravity.BOTTOM | Gravity.END:
|
|
1189
|
-
uiSettings.setCompassMargins(0, 0, x, y);
|
|
1190
|
-
break;
|
|
1191
|
-
}
|
|
1192
|
-
}
|
|
1193
|
-
|
|
1194
|
-
if (mZoomEnabled != null && uiSettings.isZoomGesturesEnabled() != mZoomEnabled) {
|
|
1195
|
-
uiSettings.setZoomGesturesEnabled(mZoomEnabled);
|
|
1196
|
-
if (!mZoomEnabled) {
|
|
1197
|
-
mMap.getGesturesManager().getStandardScaleGestureDetector().interrupt();
|
|
1198
|
-
}
|
|
1199
|
-
}
|
|
1200
|
-
}
|
|
1201
|
-
|
|
1202
|
-
private void updatePreferredFramesPerSecond() {
|
|
1203
|
-
if (mPreferredFramesPerSecond == null) {
|
|
1204
|
-
return;
|
|
1205
|
-
}
|
|
1206
|
-
setMaximumFps(mPreferredFramesPerSecond);
|
|
1207
|
-
}
|
|
1208
|
-
|
|
1209
|
-
public double[] getContentInset() {
|
|
1210
|
-
if (mInsets == null) {
|
|
1211
|
-
double[] result = { 0, 0, 0, 0 };
|
|
1212
|
-
|
|
1213
|
-
return result;
|
|
1214
|
-
}
|
|
1215
|
-
double top = 0, right = 0, bottom = 0, left = 0;
|
|
1216
|
-
|
|
1217
|
-
if (mInsets.size() == 4) {
|
|
1218
|
-
top = mInsets.getInt(0);
|
|
1219
|
-
right = mInsets.getInt(1);
|
|
1220
|
-
bottom = mInsets.getInt(2);
|
|
1221
|
-
left = mInsets.getInt(3);
|
|
1222
|
-
} else if (mInsets.size() == 2) {
|
|
1223
|
-
top = mInsets.getInt(0);
|
|
1224
|
-
right = mInsets.getInt(1);
|
|
1225
|
-
bottom = top;
|
|
1226
|
-
left = right;
|
|
1227
|
-
} else if (mInsets.size() == 1) {
|
|
1228
|
-
top = mInsets.getInt(0);
|
|
1229
|
-
right = top;
|
|
1230
|
-
bottom = top;
|
|
1231
|
-
left = top;
|
|
1232
|
-
}
|
|
1233
|
-
|
|
1234
|
-
final DisplayMetrics metrics = mContext.getResources().getDisplayMetrics();
|
|
1235
|
-
|
|
1236
|
-
double[] result = { left * metrics.scaledDensity, top * metrics.scaledDensity, right * metrics.scaledDensity,
|
|
1237
|
-
bottom * metrics.scaledDensity };
|
|
1238
|
-
return result;
|
|
1239
|
-
}
|
|
1240
|
-
|
|
1241
|
-
private void updateInsets() {
|
|
1242
|
-
if (mMap == null || mInsets == null) {
|
|
1243
|
-
return;
|
|
1244
|
-
}
|
|
1245
|
-
|
|
1246
|
-
double padding[] = getContentInset();
|
|
1247
|
-
double top = padding[1], right = padding[2], bottom = padding[3], left = padding[0];
|
|
1248
|
-
|
|
1249
|
-
mMap.setPadding(Double.valueOf(left).intValue(),
|
|
1250
|
-
Double.valueOf(top).intValue(),
|
|
1251
|
-
Double.valueOf(right).intValue(),
|
|
1252
|
-
Double.valueOf(bottom).intValue());
|
|
1253
|
-
}
|
|
1254
|
-
|
|
1255
|
-
private void setLifecycleListeners() {
|
|
1256
|
-
final ReactContext reactContext = (ReactContext) mContext;
|
|
1257
|
-
|
|
1258
|
-
mLifeCycleListener = new LifecycleEventListener() {
|
|
1259
|
-
@Override
|
|
1260
|
-
public void onHostResume() {
|
|
1261
|
-
onResume();
|
|
1262
|
-
}
|
|
1263
|
-
|
|
1264
|
-
@Override
|
|
1265
|
-
public void onHostPause() {
|
|
1266
|
-
onPause();
|
|
1267
|
-
}
|
|
1268
|
-
|
|
1269
|
-
@Override
|
|
1270
|
-
public void onHostDestroy() {
|
|
1271
|
-
dispose();
|
|
1272
|
-
}
|
|
1273
|
-
};
|
|
1274
|
-
|
|
1275
|
-
reactContext.addLifecycleEventListener(mLifeCycleListener);
|
|
1276
|
-
}
|
|
1277
|
-
|
|
1278
|
-
private WritableMap makeRegionPayload(Boolean isAnimated) {
|
|
1279
|
-
CameraPosition position = mMap.getCameraPosition();
|
|
1280
|
-
if (position == null || position.target == null) {
|
|
1281
|
-
return new WritableNativeMap();
|
|
1282
|
-
}
|
|
1283
|
-
LatLng latLng = new LatLng(position.target.getLatitude(), position.target.getLongitude());
|
|
1284
|
-
|
|
1285
|
-
WritableMap properties = new WritableNativeMap();
|
|
1286
|
-
|
|
1287
|
-
properties.putDouble("zoomLevel", position.zoom);
|
|
1288
|
-
properties.putDouble("heading", position.bearing);
|
|
1289
|
-
properties.putDouble("pitch", position.tilt);
|
|
1290
|
-
properties.putBoolean("animated",
|
|
1291
|
-
(null == isAnimated) ? mCameraChangeTracker.isAnimated() : isAnimated.booleanValue());
|
|
1292
|
-
properties.putBoolean("isUserInteraction", mCameraChangeTracker.isUserInteraction());
|
|
1293
|
-
|
|
1294
|
-
try {
|
|
1295
|
-
VisibleRegion visibleRegion = mMap.getProjection().getVisibleRegion();
|
|
1296
|
-
properties.putArray("visibleBounds", GeoJSONUtils.fromLatLngBounds(visibleRegion.latLngBounds));
|
|
1297
|
-
} catch (Exception ex) {
|
|
1298
|
-
Logger.e(LOG_TAG,
|
|
1299
|
-
String.format("An error occurred while attempting to make the region: %s", ex.getMessage()));
|
|
1300
|
-
}
|
|
1301
|
-
|
|
1302
|
-
return GeoJSONUtils.toPointFeature(latLng, properties);
|
|
1303
|
-
}
|
|
1304
|
-
|
|
1305
|
-
public void sendRegionChangeEvent(boolean isAnimated) {
|
|
1306
|
-
IEvent event = new MapChangeEvent(this, EventTypes.REGION_DID_CHANGE,
|
|
1307
|
-
makeRegionPayload(new Boolean(isAnimated)));
|
|
1308
|
-
|
|
1309
|
-
mManager.handleEvent(event);
|
|
1310
|
-
mCameraChangeTracker.setReason(CameraChangeTracker.EMPTY);
|
|
1311
|
-
}
|
|
1312
|
-
|
|
1313
|
-
private void removeAllSourcesFromMap() {
|
|
1314
|
-
if (mSources.size() == 0) {
|
|
1315
|
-
return;
|
|
1316
|
-
}
|
|
1317
|
-
for (String key : mSources.keySet()) {
|
|
1318
|
-
MLRNSource source = mSources.get(key);
|
|
1319
|
-
source.removeFromMap(this);
|
|
1320
|
-
}
|
|
1321
|
-
}
|
|
1322
|
-
|
|
1323
|
-
private void addAllSourcesToMap() {
|
|
1324
|
-
if (mSources.size() == 0) {
|
|
1325
|
-
return;
|
|
1326
|
-
}
|
|
1327
|
-
for (String key : mSources.keySet()) {
|
|
1328
|
-
MLRNSource source = mSources.get(key);
|
|
1329
|
-
source.addToMap(this);
|
|
1330
|
-
}
|
|
1331
|
-
}
|
|
1332
|
-
|
|
1333
|
-
private List<MLRNSource> getAllTouchableSources() {
|
|
1334
|
-
List<MLRNSource> sources = new ArrayList<>();
|
|
1335
|
-
|
|
1336
|
-
for (String key : mSources.keySet()) {
|
|
1337
|
-
MLRNSource source = mSources.get(key);
|
|
1338
|
-
if (source != null && source.hasPressListener()) {
|
|
1339
|
-
sources.add(source);
|
|
1340
|
-
}
|
|
1341
|
-
}
|
|
1342
|
-
|
|
1343
|
-
return sources;
|
|
1344
|
-
}
|
|
1345
|
-
|
|
1346
|
-
private List<MLRNShapeSource> getAllShapeSources() {
|
|
1347
|
-
List<MLRNShapeSource> shapeSources = new ArrayList<>();
|
|
1348
|
-
|
|
1349
|
-
for (String key : mSources.keySet()) {
|
|
1350
|
-
MLRNSource source = mSources.get(key);
|
|
1351
|
-
|
|
1352
|
-
if (source instanceof MLRNShapeSource) {
|
|
1353
|
-
shapeSources.add((MLRNShapeSource) source);
|
|
1354
|
-
}
|
|
1355
|
-
}
|
|
1356
|
-
|
|
1357
|
-
return shapeSources;
|
|
1358
|
-
}
|
|
1359
|
-
|
|
1360
|
-
private MLRNSource getTouchableSourceWithHighestZIndex(List<MLRNSource> sources) {
|
|
1361
|
-
if (sources == null || sources.size() == 0) {
|
|
1362
|
-
return null;
|
|
1363
|
-
}
|
|
1364
|
-
|
|
1365
|
-
if (sources.size() == 1) {
|
|
1366
|
-
return sources.get(0);
|
|
1367
|
-
}
|
|
1368
|
-
|
|
1369
|
-
Map<String, MLRNSource> layerToSourceMap = new HashMap<>();
|
|
1370
|
-
for (MLRNSource source : sources) {
|
|
1371
|
-
String[] layerIDs = source.getLayerIDs();
|
|
1372
|
-
|
|
1373
|
-
for (String layerID : layerIDs) {
|
|
1374
|
-
layerToSourceMap.put(layerID, source);
|
|
1375
|
-
}
|
|
1376
|
-
}
|
|
1377
|
-
|
|
1378
|
-
List<Layer> mapboxLayers = mMap.getStyle().getLayers();
|
|
1379
|
-
for (int i = mapboxLayers.size() - 1; i >= 0; i--) {
|
|
1380
|
-
Layer mapboxLayer = mapboxLayers.get(i);
|
|
1381
|
-
|
|
1382
|
-
String layerID = mapboxLayer.getId();
|
|
1383
|
-
if (layerToSourceMap.containsKey(layerID)) {
|
|
1384
|
-
return layerToSourceMap.get(layerID);
|
|
1385
|
-
}
|
|
1386
|
-
}
|
|
1387
|
-
|
|
1388
|
-
return null;
|
|
1389
|
-
}
|
|
1390
|
-
|
|
1391
|
-
private boolean hasSetCenterCoordinate() {
|
|
1392
|
-
CameraPosition cameraPosition = mMap.getCameraPosition();
|
|
1393
|
-
LatLng center = cameraPosition.target;
|
|
1394
|
-
return center.getLatitude() != 0.0 && center.getLongitude() != 0.0;
|
|
1395
|
-
}
|
|
1396
|
-
|
|
1397
|
-
private double getMapRotation() {
|
|
1398
|
-
CameraPosition cameraPosition = mMap.getCameraPosition();
|
|
1399
|
-
return cameraPosition.bearing;
|
|
1400
|
-
}
|
|
1401
|
-
|
|
1402
|
-
public void sendRegionDidChangeEvent() {
|
|
1403
|
-
|
|
1404
|
-
handleMapChangedEvent(EventTypes.REGION_DID_CHANGE);
|
|
1405
|
-
mCameraChangeTracker.setReason(mCameraChangeTracker.EMPTY);
|
|
1406
|
-
}
|
|
1407
|
-
|
|
1408
|
-
private void handleMapChangedEvent(String eventType) {
|
|
1409
|
-
if (!canHandleEvent(eventType))
|
|
1410
|
-
return;
|
|
1411
|
-
|
|
1412
|
-
IEvent event;
|
|
1413
|
-
|
|
1414
|
-
switch (eventType) {
|
|
1415
|
-
case EventTypes.REGION_WILL_CHANGE:
|
|
1416
|
-
case EventTypes.REGION_DID_CHANGE:
|
|
1417
|
-
case EventTypes.REGION_IS_CHANGING:
|
|
1418
|
-
event = new MapChangeEvent(this, eventType, makeRegionPayload(null));
|
|
1419
|
-
break;
|
|
1420
|
-
default:
|
|
1421
|
-
event = new MapChangeEvent(this, eventType);
|
|
1422
|
-
}
|
|
1423
|
-
|
|
1424
|
-
mManager.handleEvent(event);
|
|
1425
|
-
}
|
|
1426
|
-
|
|
1427
|
-
private boolean canHandleEvent(String event) {
|
|
1428
|
-
return mHandledMapChangedEvents == null || mHandledMapChangedEvents.contains(event);
|
|
1429
|
-
}
|
|
1430
|
-
|
|
1431
|
-
public void setHandledMapChangedEvents(ArrayList<String> eventsWhiteList) {
|
|
1432
|
-
this.mHandledMapChangedEvents = new HashSet<>(eventsWhiteList);
|
|
1433
|
-
}
|
|
1434
|
-
|
|
1435
|
-
private void sendUserLocationUpdateEvent(Location location) {
|
|
1436
|
-
if (location == null) {
|
|
1437
|
-
return;
|
|
1438
|
-
}
|
|
1439
|
-
IEvent event = new MapChangeEvent(this, EventTypes.USER_LOCATION_UPDATED, makeLocationChangePayload(location));
|
|
1440
|
-
mManager.handleEvent(event);
|
|
1441
|
-
}
|
|
1442
|
-
|
|
1443
|
-
private WritableMap makeLocationChangePayload(Location location) {
|
|
1444
|
-
|
|
1445
|
-
WritableMap positionProperties = new WritableNativeMap();
|
|
1446
|
-
WritableMap coords = new WritableNativeMap();
|
|
1447
|
-
|
|
1448
|
-
coords.putDouble("longitude", location.getLongitude());
|
|
1449
|
-
coords.putDouble("latitude", location.getLatitude());
|
|
1450
|
-
coords.putDouble("altitude", location.getAltitude());
|
|
1451
|
-
coords.putDouble("accuracy", location.getAccuracy());
|
|
1452
|
-
// A better solution will be to pull the heading from the compass engine,
|
|
1453
|
-
// unfortunately the api is not publicly available in the mapbox sdk
|
|
1454
|
-
coords.putDouble("heading", location.getBearing());
|
|
1455
|
-
coords.putDouble("course", location.getBearing());
|
|
1456
|
-
coords.putDouble("speed", location.getSpeed());
|
|
1457
|
-
|
|
1458
|
-
positionProperties.putMap("coords", coords);
|
|
1459
|
-
positionProperties.putDouble("timestamp", location.getTime());
|
|
1460
|
-
return positionProperties;
|
|
1461
|
-
}
|
|
1462
|
-
|
|
1463
|
-
/**
|
|
1464
|
-
* Adds the marker image to the map for use as a SymbolLayer icon
|
|
1465
|
-
*/
|
|
1466
|
-
private void setUpImage(@NonNull Style loadedStyle) {
|
|
1467
|
-
loadedStyle.addImage("MARKER_IMAGE_ID", BitmapFactory.decodeResource(
|
|
1468
|
-
this.getResources(), R.drawable.red_marker));
|
|
1469
|
-
}
|
|
1470
|
-
|
|
1471
|
-
/**
|
|
1472
|
-
* PointAnnotations are rendered to a canvas, but react native Image component
|
|
1473
|
-
* is
|
|
1474
|
-
* implemented on top of Fresco, and fresco will not load images when their view
|
|
1475
|
-
* is
|
|
1476
|
-
* not attached to the window. So we'll have an offscreen view where we add
|
|
1477
|
-
* those views
|
|
1478
|
-
* so they can rendered full to canvas.
|
|
1479
|
-
*/
|
|
1480
|
-
public ViewGroup offscreenAnnotationViewContainer() {
|
|
1481
|
-
if (mOffscreenAnnotationViewContainer == null) {
|
|
1482
|
-
mOffscreenAnnotationViewContainer = new FrameLayout(getContext());
|
|
1483
|
-
FrameLayout.LayoutParams flParams = new FrameLayout.LayoutParams(0, 0);
|
|
1484
|
-
flParams.setMargins(-10000, -10000, -10000, -10000);
|
|
1485
|
-
mOffscreenAnnotationViewContainer.setLayoutParams(flParams);
|
|
1486
|
-
addView(mOffscreenAnnotationViewContainer);
|
|
1487
|
-
}
|
|
1488
|
-
return mOffscreenAnnotationViewContainer;
|
|
1489
|
-
}
|
|
1490
|
-
|
|
1491
|
-
public MarkerViewManager getMarkerViewManager(MapLibreMap map) {
|
|
1492
|
-
if (markerViewManager == null) {
|
|
1493
|
-
if (map == null) {
|
|
1494
|
-
throw new Error("makerViewManager should be called one the map has loaded");
|
|
1495
|
-
}
|
|
1496
|
-
markerViewManager = new MarkerViewManager(this, map);
|
|
1497
|
-
}
|
|
1498
|
-
return markerViewManager;
|
|
1499
|
-
}
|
|
1500
|
-
|
|
1501
|
-
public LocationComponentManager getLocationComponentManager() {
|
|
1502
|
-
if (mLocationComponentManager == null) {
|
|
1503
|
-
mLocationComponentManager = new LocationComponentManager(this, mContext);
|
|
1504
|
-
}
|
|
1505
|
-
return mLocationComponentManager;
|
|
1506
|
-
}
|
|
1507
|
-
|
|
1508
|
-
public @Nullable Integer getTintColor() {
|
|
1509
|
-
return mTintColor;
|
|
1510
|
-
}
|
|
1511
|
-
|
|
1512
|
-
public void setTintColor(@Nullable Integer tintColor) {
|
|
1513
|
-
if (mTintColor == tintColor)
|
|
1514
|
-
return;
|
|
1515
|
-
mTintColor = tintColor;
|
|
1516
|
-
updateUISettings();
|
|
1517
|
-
if (mLocationComponentManager == null)
|
|
1518
|
-
return;
|
|
1519
|
-
mLocationComponentManager.update(getMapboxMap().getStyle());
|
|
1520
|
-
}
|
|
1521
|
-
}
|