@maplibre/maplibre-react-native 11.0.0-alpha.8 → 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/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
|
@@ -0,0 +1,1338 @@
|
|
|
1
|
+
package org.maplibre.reactnative.components.mapview
|
|
2
|
+
|
|
3
|
+
import android.annotation.SuppressLint
|
|
4
|
+
import android.content.Context
|
|
5
|
+
import android.graphics.BitmapFactory
|
|
6
|
+
import android.graphics.PointF
|
|
7
|
+
import android.graphics.RectF
|
|
8
|
+
import android.os.Handler
|
|
9
|
+
import android.os.Looper
|
|
10
|
+
import android.util.AttributeSet
|
|
11
|
+
import android.view.Gravity
|
|
12
|
+
import android.view.MotionEvent
|
|
13
|
+
import android.view.View
|
|
14
|
+
import android.view.ViewGroup
|
|
15
|
+
import android.widget.FrameLayout
|
|
16
|
+
import com.facebook.react.bridge.LifecycleEventListener
|
|
17
|
+
import com.facebook.react.bridge.ReactContext
|
|
18
|
+
import com.facebook.react.bridge.ReadableArray
|
|
19
|
+
import com.facebook.react.bridge.ReadableMap
|
|
20
|
+
import com.facebook.react.bridge.WritableArray
|
|
21
|
+
import com.facebook.react.bridge.WritableMap
|
|
22
|
+
import com.facebook.react.bridge.WritableNativeArray
|
|
23
|
+
import com.facebook.react.bridge.WritableNativeMap
|
|
24
|
+
import com.facebook.react.uimanager.UIManagerHelper
|
|
25
|
+
import com.facebook.react.uimanager.events.EventDispatcher
|
|
26
|
+
import com.google.gson.JsonObject
|
|
27
|
+
import org.json.JSONException
|
|
28
|
+
import org.json.JSONObject
|
|
29
|
+
import org.maplibre.android.camera.CameraPosition
|
|
30
|
+
import org.maplibre.android.camera.CameraUpdate
|
|
31
|
+
import org.maplibre.android.geometry.LatLng
|
|
32
|
+
import org.maplibre.android.geometry.LatLngBounds
|
|
33
|
+
import org.maplibre.android.gestures.MoveGestureDetector
|
|
34
|
+
import org.maplibre.android.log.Logger
|
|
35
|
+
import org.maplibre.android.maps.AttributionDialogManager
|
|
36
|
+
import org.maplibre.android.maps.MapLibreMap
|
|
37
|
+
import org.maplibre.android.maps.MapLibreMapOptions
|
|
38
|
+
import org.maplibre.android.maps.MapView
|
|
39
|
+
import org.maplibre.android.maps.OnMapReadyCallback
|
|
40
|
+
import org.maplibre.android.maps.Style
|
|
41
|
+
import org.maplibre.android.maps.Style.OnStyleLoaded
|
|
42
|
+
import org.maplibre.android.plugins.annotation.OnSymbolClickListener
|
|
43
|
+
import org.maplibre.android.plugins.annotation.OnSymbolDragListener
|
|
44
|
+
import org.maplibre.android.plugins.annotation.Symbol
|
|
45
|
+
import org.maplibre.android.plugins.annotation.SymbolManager
|
|
46
|
+
import org.maplibre.android.style.expressions.Expression
|
|
47
|
+
import org.maplibre.android.style.layers.Layer
|
|
48
|
+
import org.maplibre.android.style.layers.Property
|
|
49
|
+
import org.maplibre.android.style.layers.PropertyFactory
|
|
50
|
+
import org.maplibre.geojson.Feature
|
|
51
|
+
import org.maplibre.geojson.FeatureCollection
|
|
52
|
+
import org.maplibre.reactnative.R
|
|
53
|
+
import org.maplibre.reactnative.components.AbstractMapFeature
|
|
54
|
+
import org.maplibre.reactnative.components.annotation.MLRNMarkerView
|
|
55
|
+
import org.maplibre.reactnative.components.annotation.MLRNPointAnnotation
|
|
56
|
+
import org.maplibre.reactnative.components.annotation.MarkerViewManager
|
|
57
|
+
import org.maplibre.reactnative.components.camera.MLRNCamera
|
|
58
|
+
import org.maplibre.reactnative.components.images.MLRNImages
|
|
59
|
+
import org.maplibre.reactnative.components.location.LocationComponentManager
|
|
60
|
+
import org.maplibre.reactnative.components.location.MLRNNativeUserLocation
|
|
61
|
+
import org.maplibre.reactnative.components.mapview.helpers.CameraChangeTracker
|
|
62
|
+
import org.maplibre.reactnative.components.mapview.helpers.LayerSourceInfo
|
|
63
|
+
import org.maplibre.reactnative.components.styles.layers.MLRNLayer
|
|
64
|
+
import org.maplibre.reactnative.components.styles.light.MLRNLight
|
|
65
|
+
import org.maplibre.reactnative.components.styles.sources.MLRNSource
|
|
66
|
+
import org.maplibre.reactnative.components.styles.sources.MLRNSource.OnPressEvent
|
|
67
|
+
import org.maplibre.reactnative.events.MapChangeEvent
|
|
68
|
+
import org.maplibre.reactnative.events.MapPressEvent
|
|
69
|
+
import org.maplibre.reactnative.modules.MLRNModule
|
|
70
|
+
import org.maplibre.reactnative.utils.BitmapUtils
|
|
71
|
+
import org.maplibre.reactnative.utils.ConvertUtils
|
|
72
|
+
import org.maplibre.reactnative.utils.GeoJSONUtils
|
|
73
|
+
import kotlin.math.roundToInt
|
|
74
|
+
|
|
75
|
+
sealed class MapChild {
|
|
76
|
+
data class FeatureChild(val feature: AbstractMapFeature) : MapChild()
|
|
77
|
+
data class ViewChild(val view: View) : MapChild()
|
|
78
|
+
|
|
79
|
+
fun toView(): View? = when (this) {
|
|
80
|
+
is FeatureChild -> feature
|
|
81
|
+
is ViewChild -> view
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
open class MLRNMapView(
|
|
86
|
+
context: Context, options: MapLibreMapOptions?
|
|
87
|
+
) : MapView(
|
|
88
|
+
context, options
|
|
89
|
+
), OnMapReadyCallback, MapLibreMap.OnMapClickListener, MapLibreMap.OnMapLongClickListener,
|
|
90
|
+
MapView.OnCameraIsChangingListener, MapView.OnCameraDidChangeListener,
|
|
91
|
+
MapView.OnWillStartLoadingMapListener, MapView.OnDidFailLoadingMapListener,
|
|
92
|
+
MapView.OnDidFinishLoadingMapListener, MapView.OnWillStartRenderingFrameListener,
|
|
93
|
+
MapView.OnWillStartRenderingMapListener, MapView.OnDidFinishRenderingFrameListener,
|
|
94
|
+
MapView.OnDidFinishRenderingMapListener, MapView.OnDidFinishLoadingStyleListener,
|
|
95
|
+
MapView.OnStyleImageMissingListener {
|
|
96
|
+
constructor(context: Context) : this(context, options = null)
|
|
97
|
+
|
|
98
|
+
@Suppress("UNUSED_PARAMETER")
|
|
99
|
+
constructor(context: Context, attrs: AttributeSet?) : this(context, options = null)
|
|
100
|
+
|
|
101
|
+
@Suppress("UNUSED_PARAMETER")
|
|
102
|
+
constructor(context: Context, attrs: AttributeSet?, defStyleAttr: Int) : this(
|
|
103
|
+
context, options = null
|
|
104
|
+
)
|
|
105
|
+
|
|
106
|
+
private val handler: Handler
|
|
107
|
+
private var lifeCycleListener: LifecycleEventListener? = null
|
|
108
|
+
private var paused = false
|
|
109
|
+
private var destroyed = false
|
|
110
|
+
|
|
111
|
+
private var camera: MLRNCamera? = null
|
|
112
|
+
private val children: MutableList<MapChild>
|
|
113
|
+
private var queuedChildren: MutableList<MapChild>?
|
|
114
|
+
private val pointAnnotations: MutableMap<String?, MLRNPointAnnotation?>
|
|
115
|
+
private val sources: MutableMap<String?, MLRNSource<*>?>
|
|
116
|
+
private val images: MutableList<MLRNImages>
|
|
117
|
+
|
|
118
|
+
private val cameraChangeTracker = CameraChangeTracker()
|
|
119
|
+
|
|
120
|
+
var mapLibreMap: MapLibreMap? = null
|
|
121
|
+
private set
|
|
122
|
+
|
|
123
|
+
private var mapStyle: String
|
|
124
|
+
private var insets: ReadableArray? = null
|
|
125
|
+
private var preferredFramesPerSecond: Int? = null
|
|
126
|
+
|
|
127
|
+
private var scrollEnabled: Boolean? = null
|
|
128
|
+
private var zoomEnabled: Boolean? = null
|
|
129
|
+
private var rotateEnabled: Boolean? = null
|
|
130
|
+
private var pitchEnabled: Boolean? = null
|
|
131
|
+
|
|
132
|
+
var tintColor: Int? = null
|
|
133
|
+
|
|
134
|
+
private var attributionEnabled: Boolean? = null
|
|
135
|
+
private var attributionGravity: Int? = null
|
|
136
|
+
private var attributionMargin: IntArray? = null
|
|
137
|
+
|
|
138
|
+
private var logoEnabled: Boolean? = null
|
|
139
|
+
private var logoGravity: Int? = null
|
|
140
|
+
private var logoMargins: IntArray? = null
|
|
141
|
+
|
|
142
|
+
private var compassEnabled: Boolean? = null
|
|
143
|
+
private var compassGravity: Int? = null
|
|
144
|
+
private var compassMargins: IntArray? = null
|
|
145
|
+
|
|
146
|
+
|
|
147
|
+
private var symbolManager: SymbolManager? = null
|
|
148
|
+
|
|
149
|
+
private var activeMarkerID: Long = -1
|
|
150
|
+
|
|
151
|
+
private var markerViewManager: MarkerViewManager? = null
|
|
152
|
+
private var offscreenAnnotationViewContainer: ViewGroup? = null
|
|
153
|
+
|
|
154
|
+
private var annotationClicked = false
|
|
155
|
+
|
|
156
|
+
val locationComponentManager: LocationComponentManager by lazy {
|
|
157
|
+
LocationComponentManager(this, context)
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
val eventDispatcher: EventDispatcher?
|
|
161
|
+
get() {
|
|
162
|
+
val reactContext = context as ReactContext
|
|
163
|
+
|
|
164
|
+
return UIManagerHelper.getEventDispatcherForReactTag(reactContext, id)
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
val surfaceId: Int
|
|
168
|
+
get() {
|
|
169
|
+
val reactContext = context as ReactContext
|
|
170
|
+
|
|
171
|
+
return UIManagerHelper.getSurfaceId(reactContext)
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
override fun onResume() {
|
|
175
|
+
super.onResume()
|
|
176
|
+
paused = false
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
override fun onPause() {
|
|
180
|
+
super.onPause()
|
|
181
|
+
paused = true
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
override fun onDestroy() {
|
|
185
|
+
super.onDestroy()
|
|
186
|
+
destroyed = true
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
fun addFeature(childView: View?, childPosition: Int) {
|
|
190
|
+
val child: MapChild? = when (childView) {
|
|
191
|
+
|
|
192
|
+
is MLRNCamera -> {
|
|
193
|
+
camera = childView
|
|
194
|
+
MapChild.FeatureChild(childView)
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
is MLRNSource<*> -> {
|
|
198
|
+
sources.put(childView.getID(), childView)
|
|
199
|
+
MapChild.FeatureChild(childView)
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
is MLRNPointAnnotation -> {
|
|
203
|
+
pointAnnotations.put(childView.getID(), childView)
|
|
204
|
+
MapChild.FeatureChild(childView)
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
is MLRNImages -> {
|
|
208
|
+
images.add(childView)
|
|
209
|
+
MapChild.FeatureChild(childView)
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
is MLRNLight, is MLRNNativeUserLocation, is MLRNMarkerView, is MLRNLayer<*> -> {
|
|
213
|
+
MapChild.FeatureChild(childView)
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
is ViewGroup -> {
|
|
217
|
+
MapChild.ViewChild(childView)
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
else -> null
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
if (child != null) {
|
|
224
|
+
if (queuedChildren == null) {
|
|
225
|
+
when (child) {
|
|
226
|
+
is MapChild.FeatureChild -> {
|
|
227
|
+
child.feature.addToMap(this)
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
is MapChild.ViewChild -> {
|
|
231
|
+
addView(child.view)
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
children.add(childPosition, child)
|
|
236
|
+
} else {
|
|
237
|
+
queuedChildren!!.add(childPosition, child)
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
fun removeFeature(childPosition: Int) {
|
|
243
|
+
val child = children()[childPosition]
|
|
244
|
+
|
|
245
|
+
when (child) {
|
|
246
|
+
is MapChild.FeatureChild -> {
|
|
247
|
+
when (child.feature) {
|
|
248
|
+
is MLRNSource<*> -> {
|
|
249
|
+
sources.remove(child.feature.getID())
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
is MLRNPointAnnotation -> {
|
|
253
|
+
if (child.feature.mapboxID == activeMarkerID) {
|
|
254
|
+
activeMarkerID = -1
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
pointAnnotations.remove(child.feature.getID())
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
is MLRNImages -> {
|
|
261
|
+
images.remove(child.feature)
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
child.feature.removeFromMap(this)
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
is MapChild.ViewChild -> {
|
|
269
|
+
removeView(child.view)
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
children().remove(child)
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
private fun children() =
|
|
277
|
+
queuedChildren?.takeIf { it.isNotEmpty() } ?: children
|
|
278
|
+
|
|
279
|
+
val featureCount: Int get() = children().size
|
|
280
|
+
|
|
281
|
+
fun getFeatureAt(i: Int): MapChild {
|
|
282
|
+
return children()[i]
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
@Synchronized
|
|
286
|
+
fun dispose() {
|
|
287
|
+
if (destroyed) {
|
|
288
|
+
return
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
if (!layerWaiters.isEmpty()) {
|
|
292
|
+
layerWaiters.clear()
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
val reactContext = context as ReactContext
|
|
296
|
+
reactContext.removeLifecycleEventListener(lifeCycleListener)
|
|
297
|
+
|
|
298
|
+
if (!paused) {
|
|
299
|
+
onPause()
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
onStop()
|
|
303
|
+
onDestroy()
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
val cameraPosition: CameraPosition
|
|
307
|
+
get() = mapLibreMap!!.cameraPosition
|
|
308
|
+
|
|
309
|
+
fun moveCamera(cameraUpdate: CameraUpdate, callback: MapLibreMap.CancelableCallback?) {
|
|
310
|
+
mapLibreMap!!.moveCamera(cameraUpdate, callback)
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
fun getPointAnnotationByMarkerID(markerID: Long): MLRNPointAnnotation? {
|
|
314
|
+
for (key in pointAnnotations.keys) {
|
|
315
|
+
val annotation = pointAnnotations[key]
|
|
316
|
+
|
|
317
|
+
if (annotation != null && markerID == annotation.mapboxID) {
|
|
318
|
+
return annotation
|
|
319
|
+
}
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
return null
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
fun getSymbolManager(): SymbolManager {
|
|
326
|
+
return symbolManager!!
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
interface FoundLayerCallback {
|
|
330
|
+
fun found(layer: Layer?)
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
private val layerWaiters: MutableMap<String?, MutableList<FoundLayerCallback>> =
|
|
334
|
+
HashMap<String?, MutableList<FoundLayerCallback>>()
|
|
335
|
+
|
|
336
|
+
init {
|
|
337
|
+
onCreate(null)
|
|
338
|
+
onStart()
|
|
339
|
+
onResume()
|
|
340
|
+
getMapAsync(this)
|
|
341
|
+
|
|
342
|
+
sources = HashMap()
|
|
343
|
+
images = ArrayList()
|
|
344
|
+
pointAnnotations = HashMap()
|
|
345
|
+
children = ArrayList()
|
|
346
|
+
queuedChildren = ArrayList()
|
|
347
|
+
|
|
348
|
+
handler = Handler(Looper.getMainLooper())
|
|
349
|
+
|
|
350
|
+
mapStyle = MLRNModule.DEFAULT_STYLE_URL
|
|
351
|
+
|
|
352
|
+
setLifecycleListeners()
|
|
353
|
+
|
|
354
|
+
addOnCameraIsChangingListener(this)
|
|
355
|
+
addOnCameraDidChangeListener(this)
|
|
356
|
+
addOnDidFailLoadingMapListener(this)
|
|
357
|
+
addOnDidFinishLoadingMapListener(this)
|
|
358
|
+
addOnStyleImageMissingListener(this)
|
|
359
|
+
|
|
360
|
+
addOnWillStartRenderingFrameListener(this)
|
|
361
|
+
addOnDidFinishRenderingFrameListener(this)
|
|
362
|
+
addOnWillStartRenderingMapListener(this)
|
|
363
|
+
addOnDidFinishRenderingMapListener(this)
|
|
364
|
+
addOnDidFinishLoadingStyleListener(this)
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
fun layerAdded(layer: Layer) {
|
|
368
|
+
val layerId = layer.getId()
|
|
369
|
+
|
|
370
|
+
val callbacks = layerWaiters[layerId]
|
|
371
|
+
if (callbacks != null) {
|
|
372
|
+
for (callback in callbacks) {
|
|
373
|
+
callback.found(layer)
|
|
374
|
+
}
|
|
375
|
+
}
|
|
376
|
+
layerWaiters.remove(layerId)
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
fun waitForLayer(layerID: String, callback: FoundLayerCallback) {
|
|
380
|
+
val layer = mapLibreMap!!.style!!.getLayer(layerID)
|
|
381
|
+
if (layer != null) {
|
|
382
|
+
callback.found(layer)
|
|
383
|
+
} else {
|
|
384
|
+
val waiters = layerWaiters.computeIfAbsent(layerID) { k: String? -> ArrayList() }
|
|
385
|
+
waiters.add(callback)
|
|
386
|
+
}
|
|
387
|
+
}
|
|
388
|
+
|
|
389
|
+
fun isJSONValid(test: String): Boolean {
|
|
390
|
+
try {
|
|
391
|
+
JSONObject(test)
|
|
392
|
+
} catch (_: JSONException) {
|
|
393
|
+
return false
|
|
394
|
+
}
|
|
395
|
+
return true
|
|
396
|
+
}
|
|
397
|
+
|
|
398
|
+
override fun onMapReady(mapLibreMap: MapLibreMap) {
|
|
399
|
+
this.mapLibreMap = mapLibreMap
|
|
400
|
+
|
|
401
|
+
if (isJSONValid(mapStyle)) {
|
|
402
|
+
mapLibreMap.setStyle(Style.Builder().fromJson(mapStyle))
|
|
403
|
+
} else {
|
|
404
|
+
mapLibreMap.setStyle(Style.Builder().fromUri(mapStyle))
|
|
405
|
+
}
|
|
406
|
+
|
|
407
|
+
reflow()
|
|
408
|
+
|
|
409
|
+
mapLibreMap.getStyle { style ->
|
|
410
|
+
createSymbolManager(style)
|
|
411
|
+
setUpImage(style)
|
|
412
|
+
addQueuedFeatures()
|
|
413
|
+
}
|
|
414
|
+
|
|
415
|
+
updatePreferredFramesPerSecond()
|
|
416
|
+
updateInsets()
|
|
417
|
+
updateUISettings()
|
|
418
|
+
|
|
419
|
+
mapLibreMap.addOnCameraMoveStartedListener { reason ->
|
|
420
|
+
cameraChangeTracker.setReason(reason)
|
|
421
|
+
handleMapChangedEvent("onRegionWillChange", true)
|
|
422
|
+
}
|
|
423
|
+
|
|
424
|
+
mapLibreMap.addOnCameraMoveListener {
|
|
425
|
+
if (markerViewManager != null) {
|
|
426
|
+
markerViewManager!!.updateMarkers()
|
|
427
|
+
}
|
|
428
|
+
}
|
|
429
|
+
|
|
430
|
+
mapLibreMap.addOnMoveListener(object : MapLibreMap.OnMoveListener {
|
|
431
|
+
override fun onMoveBegin(detector: MoveGestureDetector) {
|
|
432
|
+
cameraChangeTracker.setReason(CameraChangeTracker.USER_GESTURE)
|
|
433
|
+
handleMapChangedEvent("onRegionWillChange", true)
|
|
434
|
+
}
|
|
435
|
+
|
|
436
|
+
override fun onMove(detector: MoveGestureDetector) {
|
|
437
|
+
cameraChangeTracker.setReason(CameraChangeTracker.USER_GESTURE)
|
|
438
|
+
handleMapChangedEvent("onRegionIsChanging")
|
|
439
|
+
}
|
|
440
|
+
|
|
441
|
+
override fun onMoveEnd(detector: MoveGestureDetector) {
|
|
442
|
+
}
|
|
443
|
+
})
|
|
444
|
+
|
|
445
|
+
mapLibreMap.addOnCameraIdleListener { sendRegionDidChangeEvent() }
|
|
446
|
+
}
|
|
447
|
+
|
|
448
|
+
fun reflow() {
|
|
449
|
+
handler.post {
|
|
450
|
+
measure(
|
|
451
|
+
MeasureSpec.makeMeasureSpec(measuredWidth, MeasureSpec.EXACTLY),
|
|
452
|
+
MeasureSpec.makeMeasureSpec(measuredHeight, MeasureSpec.EXACTLY)
|
|
453
|
+
)
|
|
454
|
+
layout(left, top, right, bottom)
|
|
455
|
+
}
|
|
456
|
+
}
|
|
457
|
+
|
|
458
|
+
fun createSymbolManager(style: Style) {
|
|
459
|
+
symbolManager = SymbolManager(this, this.mapLibreMap!!, style)
|
|
460
|
+
symbolManager!!.setIconAllowOverlap(true)
|
|
461
|
+
symbolManager!!.addClickListener(object : OnSymbolClickListener {
|
|
462
|
+
override fun onAnnotationClick(symbol: Symbol): Boolean {
|
|
463
|
+
onMarkerClick(symbol)
|
|
464
|
+
return true
|
|
465
|
+
}
|
|
466
|
+
})
|
|
467
|
+
symbolManager!!.addDragListener(object : OnSymbolDragListener {
|
|
468
|
+
override fun onAnnotationDragStarted(symbol: Symbol) {
|
|
469
|
+
annotationClicked = true
|
|
470
|
+
val selectedMarkerID = symbol.id
|
|
471
|
+
val annotation = getPointAnnotationByMarkerID(selectedMarkerID)
|
|
472
|
+
annotation?.onDragStart()
|
|
473
|
+
}
|
|
474
|
+
|
|
475
|
+
override fun onAnnotationDrag(symbol: Symbol) {
|
|
476
|
+
val selectedMarkerID = symbol.id
|
|
477
|
+
val annotation = getPointAnnotationByMarkerID(selectedMarkerID)
|
|
478
|
+
annotation?.onDrag()
|
|
479
|
+
}
|
|
480
|
+
|
|
481
|
+
override fun onAnnotationDragFinished(symbol: Symbol) {
|
|
482
|
+
annotationClicked = false
|
|
483
|
+
val selectedMarkerID = symbol.id
|
|
484
|
+
val annotation = getPointAnnotationByMarkerID(selectedMarkerID)
|
|
485
|
+
annotation?.onDragEnd()
|
|
486
|
+
}
|
|
487
|
+
})
|
|
488
|
+
mapLibreMap!!.addOnMapClickListener(this)
|
|
489
|
+
mapLibreMap!!.addOnMapLongClickListener(this)
|
|
490
|
+
}
|
|
491
|
+
|
|
492
|
+
fun addQueuedFeatures() {
|
|
493
|
+
if (queuedChildren != null && !queuedChildren!!.isEmpty()) {
|
|
494
|
+
for (i in queuedChildren!!.indices) {
|
|
495
|
+
val child = queuedChildren!![i]
|
|
496
|
+
|
|
497
|
+
when (child) {
|
|
498
|
+
is MapChild.FeatureChild -> {
|
|
499
|
+
child.feature.addToMap(this)
|
|
500
|
+
}
|
|
501
|
+
|
|
502
|
+
is MapChild.ViewChild -> {
|
|
503
|
+
addView(child.view)
|
|
504
|
+
}
|
|
505
|
+
}
|
|
506
|
+
|
|
507
|
+
children.add(child)
|
|
508
|
+
}
|
|
509
|
+
|
|
510
|
+
queuedChildren = null
|
|
511
|
+
}
|
|
512
|
+
}
|
|
513
|
+
|
|
514
|
+
@SuppressLint("ClickableViewAccessibility")
|
|
515
|
+
override fun onTouchEvent(ev: MotionEvent?): Boolean {
|
|
516
|
+
val result = super.onTouchEvent(ev)
|
|
517
|
+
|
|
518
|
+
if (result && scrollEnabled == true) {
|
|
519
|
+
requestDisallowInterceptTouchEvent(true)
|
|
520
|
+
}
|
|
521
|
+
|
|
522
|
+
return result
|
|
523
|
+
}
|
|
524
|
+
|
|
525
|
+
override fun onLayout(changed: Boolean, left: Int, top: Int, right: Int, bottom: Int) {
|
|
526
|
+
if (!paused) {
|
|
527
|
+
if (markerViewManager != null) {
|
|
528
|
+
markerViewManager!!.removeViews()
|
|
529
|
+
}
|
|
530
|
+
super.onLayout(changed, left, top, right, bottom)
|
|
531
|
+
if (markerViewManager != null) {
|
|
532
|
+
markerViewManager!!.restoreViews()
|
|
533
|
+
}
|
|
534
|
+
}
|
|
535
|
+
}
|
|
536
|
+
|
|
537
|
+
|
|
538
|
+
override fun onMapClick(latLng: LatLng): Boolean {
|
|
539
|
+
if (annotationClicked) {
|
|
540
|
+
annotationClicked = false
|
|
541
|
+
return true
|
|
542
|
+
}
|
|
543
|
+
|
|
544
|
+
val screenPoint = mapLibreMap!!.projection.toScreenLocation(latLng)
|
|
545
|
+
val touchableSources = this.allTouchableSources
|
|
546
|
+
|
|
547
|
+
val hits: MutableMap<String?, MutableList<Feature?>?> = HashMap()
|
|
548
|
+
val hitTouchableSources: MutableList<MLRNSource<*>> = ArrayList()
|
|
549
|
+
for (touchableSource in touchableSources) {
|
|
550
|
+
val hitbox = touchableSource.getTouchHitbox()
|
|
551
|
+
if (hitbox == null) {
|
|
552
|
+
continue
|
|
553
|
+
}
|
|
554
|
+
|
|
555
|
+
val halfWidth = hitbox["width"]!!.toFloat() / 2.0f
|
|
556
|
+
val halfHeight = hitbox["height"]!!.toFloat() / 2.0f
|
|
557
|
+
|
|
558
|
+
val hitboxF = RectF()
|
|
559
|
+
hitboxF.set(
|
|
560
|
+
screenPoint.x - halfWidth,
|
|
561
|
+
screenPoint.y - halfHeight,
|
|
562
|
+
screenPoint.x + halfWidth,
|
|
563
|
+
screenPoint.y + halfHeight
|
|
564
|
+
)
|
|
565
|
+
|
|
566
|
+
val features =
|
|
567
|
+
mapLibreMap!!.queryRenderedFeatures(hitboxF, *touchableSource.getLayerIDs())
|
|
568
|
+
if (features.isNotEmpty()) {
|
|
569
|
+
hits.put(touchableSource.getID(), features)
|
|
570
|
+
hitTouchableSources.add(touchableSource)
|
|
571
|
+
}
|
|
572
|
+
}
|
|
573
|
+
|
|
574
|
+
if (hits.isNotEmpty()) {
|
|
575
|
+
val source = getTouchableSourceWithHighestZIndex(hitTouchableSources)
|
|
576
|
+
if (source != null && source.hasPressListener()) {
|
|
577
|
+
source.onPress(
|
|
578
|
+
OnPressEvent(
|
|
579
|
+
hits[source.getID()]!!, latLng, screenPoint
|
|
580
|
+
)
|
|
581
|
+
)
|
|
582
|
+
return true
|
|
583
|
+
}
|
|
584
|
+
}
|
|
585
|
+
|
|
586
|
+
val event = MapPressEvent(surfaceId, id, "onPress", latLng, screenPoint)
|
|
587
|
+
eventDispatcher?.dispatchEvent(event)
|
|
588
|
+
|
|
589
|
+
return false
|
|
590
|
+
}
|
|
591
|
+
|
|
592
|
+
override fun onMapLongClick(latLng: LatLng): Boolean {
|
|
593
|
+
if (annotationClicked) {
|
|
594
|
+
annotationClicked = false
|
|
595
|
+
return true
|
|
596
|
+
}
|
|
597
|
+
val screenPoint = mapLibreMap!!.projection.toScreenLocation(latLng)
|
|
598
|
+
|
|
599
|
+
val event = MapPressEvent(surfaceId, id, "onLongPress", latLng, screenPoint)
|
|
600
|
+
eventDispatcher?.dispatchEvent(event)
|
|
601
|
+
|
|
602
|
+
return false
|
|
603
|
+
}
|
|
604
|
+
|
|
605
|
+
fun onMarkerClick(symbol: Symbol) {
|
|
606
|
+
annotationClicked = true
|
|
607
|
+
val selectedMarkerID = symbol.id
|
|
608
|
+
|
|
609
|
+
var activeAnnotation: MLRNPointAnnotation? = null
|
|
610
|
+
var nextActiveAnnotation: MLRNPointAnnotation? = null
|
|
611
|
+
|
|
612
|
+
for (key in pointAnnotations.keys) {
|
|
613
|
+
val annotation = pointAnnotations[key]
|
|
614
|
+
val curMarkerID = annotation!!.mapboxID
|
|
615
|
+
if (activeMarkerID == curMarkerID) {
|
|
616
|
+
activeAnnotation = annotation
|
|
617
|
+
}
|
|
618
|
+
if (selectedMarkerID == curMarkerID && activeMarkerID != curMarkerID) {
|
|
619
|
+
nextActiveAnnotation = annotation
|
|
620
|
+
}
|
|
621
|
+
}
|
|
622
|
+
|
|
623
|
+
if (activeAnnotation != null) {
|
|
624
|
+
deselectAnnotation(activeAnnotation)
|
|
625
|
+
}
|
|
626
|
+
|
|
627
|
+
if (nextActiveAnnotation != null) {
|
|
628
|
+
selectAnnotation(nextActiveAnnotation)
|
|
629
|
+
}
|
|
630
|
+
}
|
|
631
|
+
|
|
632
|
+
fun selectAnnotation(annotation: MLRNPointAnnotation) {
|
|
633
|
+
activeMarkerID = annotation.mapboxID
|
|
634
|
+
annotation.onSelect(true)
|
|
635
|
+
}
|
|
636
|
+
|
|
637
|
+
fun deselectAnnotation(annotation: MLRNPointAnnotation) {
|
|
638
|
+
activeMarkerID = -1
|
|
639
|
+
annotation.onDeselect()
|
|
640
|
+
}
|
|
641
|
+
|
|
642
|
+
override fun onCameraDidChange(animated: Boolean) {
|
|
643
|
+
cameraChangeTracker.isAnimating = animated
|
|
644
|
+
}
|
|
645
|
+
|
|
646
|
+
override fun onCameraIsChanging() {
|
|
647
|
+
handleMapChangedEvent("onRegionIsChanging")
|
|
648
|
+
}
|
|
649
|
+
|
|
650
|
+
override fun onWillStartLoadingMap() {
|
|
651
|
+
handleMapChangedEvent("onWillStartLoadingMap")
|
|
652
|
+
}
|
|
653
|
+
|
|
654
|
+
override fun onDidFinishLoadingMap() {
|
|
655
|
+
handleMapChangedEvent("onDidFinishLoadingMap")
|
|
656
|
+
}
|
|
657
|
+
|
|
658
|
+
override fun onDidFailLoadingMap(errorMessage: String?) {
|
|
659
|
+
handleMapChangedEvent("onDidFailLoadingMap")
|
|
660
|
+
}
|
|
661
|
+
|
|
662
|
+
|
|
663
|
+
override fun onWillStartRenderingFrame() {
|
|
664
|
+
handleMapChangedEvent("onWillStartRenderingFrame")
|
|
665
|
+
}
|
|
666
|
+
|
|
667
|
+
override fun onDidFinishRenderingFrame(
|
|
668
|
+
fully: Boolean, frameEncodingTime: Double, frameRenderingTime: Double
|
|
669
|
+
) {
|
|
670
|
+
if (fully) {
|
|
671
|
+
handleMapChangedEvent("onDidFinishRenderingFrameFully")
|
|
672
|
+
} else {
|
|
673
|
+
handleMapChangedEvent("onDidFinishRenderingFrame")
|
|
674
|
+
}
|
|
675
|
+
}
|
|
676
|
+
|
|
677
|
+
override fun onWillStartRenderingMap() {
|
|
678
|
+
handleMapChangedEvent("onWillStartRenderingMap")
|
|
679
|
+
}
|
|
680
|
+
|
|
681
|
+
override fun onDidFinishRenderingMap(fully: Boolean) {
|
|
682
|
+
if (fully) {
|
|
683
|
+
handleMapChangedEvent("onDidFinishRenderingMapFully")
|
|
684
|
+
} else {
|
|
685
|
+
handleMapChangedEvent("onDidFinishRenderingMap")
|
|
686
|
+
}
|
|
687
|
+
}
|
|
688
|
+
|
|
689
|
+
override fun onDidFinishLoadingStyle() {
|
|
690
|
+
handleMapChangedEvent("onDidFinishLoadingStyle")
|
|
691
|
+
}
|
|
692
|
+
|
|
693
|
+
override fun onStyleImageMissing(id: String) {
|
|
694
|
+
for (images in images) {
|
|
695
|
+
if (images.addMissingImageToStyle(id, this.mapLibreMap!!)) {
|
|
696
|
+
return
|
|
697
|
+
}
|
|
698
|
+
}
|
|
699
|
+
for (images in images) {
|
|
700
|
+
images.sendImageMissingEvent(id, this.mapLibreMap!!)
|
|
701
|
+
}
|
|
702
|
+
}
|
|
703
|
+
|
|
704
|
+
private val displayDensity: Float
|
|
705
|
+
get() = context.resources.displayMetrics.density
|
|
706
|
+
|
|
707
|
+
fun setReactMapStyle(value: String?) {
|
|
708
|
+
if (value != null) {
|
|
709
|
+
mapStyle = value
|
|
710
|
+
|
|
711
|
+
if (mapLibreMap != null) {
|
|
712
|
+
removeAllSourcesFromMap()
|
|
713
|
+
|
|
714
|
+
if (isJSONValid(mapStyle)) {
|
|
715
|
+
mapLibreMap!!.setStyle(
|
|
716
|
+
Style.Builder().fromJson(mapStyle)
|
|
717
|
+
) { addAllSourcesToMap() }
|
|
718
|
+
} else {
|
|
719
|
+
mapLibreMap!!.setStyle(value) { addAllSourcesToMap() }
|
|
720
|
+
}
|
|
721
|
+
}
|
|
722
|
+
}
|
|
723
|
+
}
|
|
724
|
+
|
|
725
|
+
fun setReactContentInset(value: ReadableMap?) {
|
|
726
|
+
if (value != null) {
|
|
727
|
+
val arr = WritableNativeArray()
|
|
728
|
+
arr.pushDouble(value.getDouble("top"))
|
|
729
|
+
arr.pushDouble(value.getDouble("right"))
|
|
730
|
+
arr.pushDouble(value.getDouble("bottom"))
|
|
731
|
+
arr.pushDouble(value.getDouble("left"))
|
|
732
|
+
insets = arr
|
|
733
|
+
} else {
|
|
734
|
+
insets = null
|
|
735
|
+
}
|
|
736
|
+
updateInsets()
|
|
737
|
+
}
|
|
738
|
+
|
|
739
|
+
fun setReactPreferredFramesPerSecond(preferredFramesPerSecond: Int?) {
|
|
740
|
+
this.preferredFramesPerSecond = preferredFramesPerSecond
|
|
741
|
+
updatePreferredFramesPerSecond()
|
|
742
|
+
}
|
|
743
|
+
|
|
744
|
+
fun setReactScrollEnabled(scrollEnabled: Boolean) {
|
|
745
|
+
this.scrollEnabled = scrollEnabled
|
|
746
|
+
updateUISettings()
|
|
747
|
+
}
|
|
748
|
+
|
|
749
|
+
fun setReactZoomEnabled(zoomEnabled: Boolean) {
|
|
750
|
+
this.zoomEnabled = zoomEnabled
|
|
751
|
+
updateUISettings()
|
|
752
|
+
}
|
|
753
|
+
|
|
754
|
+
fun setReactRotateEnabled(rotateEnabled: Boolean) {
|
|
755
|
+
this.rotateEnabled = rotateEnabled
|
|
756
|
+
updateUISettings()
|
|
757
|
+
}
|
|
758
|
+
|
|
759
|
+
fun setReactPitchEnabled(pitchEnabled: Boolean) {
|
|
760
|
+
this.pitchEnabled = pitchEnabled
|
|
761
|
+
updateUISettings()
|
|
762
|
+
}
|
|
763
|
+
|
|
764
|
+
fun setReactTintColor(value: Int?) {
|
|
765
|
+
tintColor = value
|
|
766
|
+
updateUISettings()
|
|
767
|
+
if (mapLibreMap?.style != null) {
|
|
768
|
+
locationComponentManager.update(mapLibreMap!!.style!!)
|
|
769
|
+
}
|
|
770
|
+
}
|
|
771
|
+
|
|
772
|
+
private fun setOrnamentPosition(
|
|
773
|
+
position: ReadableMap?,
|
|
774
|
+
defaultGravityKey: (MapLibreMapOptions) -> Int,
|
|
775
|
+
defaultMarginsKey: (MapLibreMapOptions) -> IntArray,
|
|
776
|
+
setGravity: (Int) -> Unit,
|
|
777
|
+
setMargins: (IntArray) -> Unit
|
|
778
|
+
) {
|
|
779
|
+
if (position == null) {
|
|
780
|
+
val defaults = MapLibreMapOptions.createFromAttributes(context)
|
|
781
|
+
setGravity(defaultGravityKey(defaults))
|
|
782
|
+
setMargins(defaultMarginsKey(defaults).copyOf(4))
|
|
783
|
+
} else {
|
|
784
|
+
var gravity = Gravity.NO_GRAVITY
|
|
785
|
+
if (position.hasKey("left")) gravity = gravity or Gravity.START
|
|
786
|
+
if (position.hasKey("right")) gravity = gravity or Gravity.END
|
|
787
|
+
if (position.hasKey("top")) gravity = gravity or Gravity.TOP
|
|
788
|
+
if (position.hasKey("bottom")) gravity = gravity or Gravity.BOTTOM
|
|
789
|
+
val density = this.displayDensity
|
|
790
|
+
val margins = intArrayOf(
|
|
791
|
+
if (position.hasKey("left")) (density * position.getInt("left")).roundToInt() else 0,
|
|
792
|
+
if (position.hasKey("top")) (density * position.getInt("top")).roundToInt() else 0,
|
|
793
|
+
if (position.hasKey("right")) (density * position.getInt("right")).roundToInt() else 0,
|
|
794
|
+
if (position.hasKey("bottom")) (density * position.getInt("bottom")).roundToInt() else 0
|
|
795
|
+
)
|
|
796
|
+
setGravity(gravity)
|
|
797
|
+
setMargins(margins)
|
|
798
|
+
}
|
|
799
|
+
updateUISettings()
|
|
800
|
+
}
|
|
801
|
+
|
|
802
|
+
fun setReactAttribution(value: Boolean) {
|
|
803
|
+
attributionEnabled = value
|
|
804
|
+
updateUISettings()
|
|
805
|
+
}
|
|
806
|
+
|
|
807
|
+
fun setReactAttributionPosition(position: ReadableMap?) {
|
|
808
|
+
setOrnamentPosition(
|
|
809
|
+
position,
|
|
810
|
+
{ it.attributionGravity },
|
|
811
|
+
{ it.attributionMargins },
|
|
812
|
+
{ attributionGravity = it },
|
|
813
|
+
{ attributionMargin = it })
|
|
814
|
+
}
|
|
815
|
+
|
|
816
|
+
fun setReactLogo(value: Boolean) {
|
|
817
|
+
logoEnabled = value
|
|
818
|
+
updateUISettings()
|
|
819
|
+
}
|
|
820
|
+
|
|
821
|
+
fun setReactLogoPosition(position: ReadableMap?) {
|
|
822
|
+
setOrnamentPosition(
|
|
823
|
+
position,
|
|
824
|
+
{ it.logoGravity },
|
|
825
|
+
{ it.logoMargins },
|
|
826
|
+
{ logoGravity = it },
|
|
827
|
+
{ logoMargins = it })
|
|
828
|
+
}
|
|
829
|
+
|
|
830
|
+
fun setReactCompass(value: Boolean) {
|
|
831
|
+
compassEnabled = value
|
|
832
|
+
updateUISettings()
|
|
833
|
+
}
|
|
834
|
+
|
|
835
|
+
fun setReactCompassPosition(position: ReadableMap?) {
|
|
836
|
+
setOrnamentPosition(
|
|
837
|
+
position,
|
|
838
|
+
{ it.compassGravity },
|
|
839
|
+
{ it.compassMargins },
|
|
840
|
+
{ compassGravity = it },
|
|
841
|
+
{ compassMargins = it })
|
|
842
|
+
}
|
|
843
|
+
|
|
844
|
+
fun getCenter(): WritableMap {
|
|
845
|
+
val cameraPosition = mapLibreMap!!.cameraPosition
|
|
846
|
+
val center = cameraPosition.target!!
|
|
847
|
+
|
|
848
|
+
val payload: WritableMap = WritableNativeMap()
|
|
849
|
+
payload.putDouble("longitude", center.longitude)
|
|
850
|
+
payload.putDouble("latitude", center.latitude)
|
|
851
|
+
|
|
852
|
+
return payload
|
|
853
|
+
}
|
|
854
|
+
|
|
855
|
+
fun getZoom(): Double {
|
|
856
|
+
val cameraPosition = mapLibreMap!!.cameraPosition
|
|
857
|
+
|
|
858
|
+
return cameraPosition.zoom
|
|
859
|
+
}
|
|
860
|
+
|
|
861
|
+
fun getBearing(): Double {
|
|
862
|
+
val cameraPosition = mapLibreMap!!.cameraPosition
|
|
863
|
+
|
|
864
|
+
return cameraPosition.bearing
|
|
865
|
+
}
|
|
866
|
+
|
|
867
|
+
fun getPitch(): Double {
|
|
868
|
+
val cameraPosition = mapLibreMap!!.cameraPosition
|
|
869
|
+
|
|
870
|
+
return cameraPosition.tilt
|
|
871
|
+
}
|
|
872
|
+
|
|
873
|
+
fun getBounds(): WritableArray {
|
|
874
|
+
val visibleRegion = mapLibreMap!!.projection.visibleRegion
|
|
875
|
+
return GeoJSONUtils.fromLatLngBounds(visibleRegion.latLngBounds)
|
|
876
|
+
}
|
|
877
|
+
|
|
878
|
+
fun getViewState(): WritableMap {
|
|
879
|
+
val payload = this.getCenter()
|
|
880
|
+
payload.putDouble("zoom", getZoom())
|
|
881
|
+
payload.putDouble("bearing", getBearing())
|
|
882
|
+
payload.putDouble("pitch", getPitch())
|
|
883
|
+
payload.putArray("bounds", getBounds())
|
|
884
|
+
|
|
885
|
+
return payload
|
|
886
|
+
}
|
|
887
|
+
|
|
888
|
+
fun queryRenderedFeaturesWithCoordinate(
|
|
889
|
+
latLng: LatLng, layers: ReadableArray?, filter: Expression?,
|
|
890
|
+
): WritableMap {
|
|
891
|
+
val features =
|
|
892
|
+
mapLibreMap!!.queryRenderedFeatures(
|
|
893
|
+
mapLibreMap!!.projection.toScreenLocation(latLng),
|
|
894
|
+
filter,
|
|
895
|
+
*(layers?.let { Array(layers.size()) { layers.getString(it) } } ?: emptyArray()))
|
|
896
|
+
|
|
897
|
+
|
|
898
|
+
val featureCollection = FeatureCollection.fromFeatures(features)
|
|
899
|
+
val jsonObject: JsonObject =
|
|
900
|
+
com.google.gson.JsonParser.parseString(featureCollection.toJson()).asJsonObject
|
|
901
|
+
return ConvertUtils.toWritableMap(jsonObject)
|
|
902
|
+
}
|
|
903
|
+
|
|
904
|
+
|
|
905
|
+
fun queryRenderedFeaturesWithBounds(
|
|
906
|
+
bounds: LatLngBounds, layers: ReadableArray?, filter: Expression?,
|
|
907
|
+
): WritableMap {
|
|
908
|
+
val swPoint = mapLibreMap!!.projection.toScreenLocation(bounds.southWest)
|
|
909
|
+
val nePoint = mapLibreMap!!.projection.toScreenLocation(bounds.northEast)
|
|
910
|
+
|
|
911
|
+
val rect = RectF(
|
|
912
|
+
swPoint.x, nePoint.y, nePoint.x, swPoint.y
|
|
913
|
+
)
|
|
914
|
+
|
|
915
|
+
val features = mapLibreMap!!.queryRenderedFeatures(
|
|
916
|
+
rect,
|
|
917
|
+
filter,
|
|
918
|
+
*(layers?.let { Array(layers.size()) { layers.getString(it) } } ?: emptyArray()))
|
|
919
|
+
|
|
920
|
+
val featureCollection = FeatureCollection.fromFeatures(features)
|
|
921
|
+
val jsonObject =
|
|
922
|
+
com.google.gson.JsonParser.parseString(featureCollection.toJson()).asJsonObject
|
|
923
|
+
return ConvertUtils.toWritableMap(jsonObject)
|
|
924
|
+
}
|
|
925
|
+
|
|
926
|
+
fun project(mapCoordinate: LatLng): WritableMap {
|
|
927
|
+
val pointInView = mapLibreMap!!.projection.toScreenLocation(mapCoordinate)
|
|
928
|
+
val density = this.displayDensity
|
|
929
|
+
pointInView.x /= density
|
|
930
|
+
pointInView.y /= density
|
|
931
|
+
val payload: WritableMap = WritableNativeMap()
|
|
932
|
+
|
|
933
|
+
val array: WritableArray = WritableNativeArray()
|
|
934
|
+
array.pushDouble(pointInView.x.toDouble())
|
|
935
|
+
array.pushDouble(pointInView.y.toDouble())
|
|
936
|
+
payload.putArray("pointInView", array)
|
|
937
|
+
|
|
938
|
+
return payload
|
|
939
|
+
}
|
|
940
|
+
|
|
941
|
+
fun unproject(pointInView: PointF): WritableMap {
|
|
942
|
+
val density = this.displayDensity
|
|
943
|
+
pointInView.x *= density
|
|
944
|
+
pointInView.y *= density
|
|
945
|
+
|
|
946
|
+
val mapCoordinate = mapLibreMap!!.projection.fromScreenLocation(pointInView)
|
|
947
|
+
val payload: WritableMap = WritableNativeMap()
|
|
948
|
+
|
|
949
|
+
val array: WritableArray = WritableNativeArray()
|
|
950
|
+
array.pushDouble(mapCoordinate.longitude)
|
|
951
|
+
array.pushDouble(mapCoordinate.latitude)
|
|
952
|
+
payload.putArray("coordinateFromView", array)
|
|
953
|
+
|
|
954
|
+
return payload
|
|
955
|
+
}
|
|
956
|
+
|
|
957
|
+
fun takeSnap(writeToDisk: Boolean, callback: (WritableMap) -> Unit) {
|
|
958
|
+
if (this.mapLibreMap == null) {
|
|
959
|
+
throw Error("takeSnap should only be called after the map has rendered")
|
|
960
|
+
}
|
|
961
|
+
|
|
962
|
+
mapLibreMap!!.snapshot { snapshot ->
|
|
963
|
+
val payload: WritableMap = WritableNativeMap()
|
|
964
|
+
val uri = if (writeToDisk) BitmapUtils.createTempFile(context, snapshot)
|
|
965
|
+
else BitmapUtils.createBase64(snapshot)
|
|
966
|
+
payload.putString("uri", uri)
|
|
967
|
+
|
|
968
|
+
callback(payload)
|
|
969
|
+
}
|
|
970
|
+
}
|
|
971
|
+
|
|
972
|
+
fun showAttribution() {
|
|
973
|
+
val manager = AttributionDialogManager(context, this.mapLibreMap!!)
|
|
974
|
+
manager.onClick(this)
|
|
975
|
+
}
|
|
976
|
+
|
|
977
|
+
fun setSourceVisibility(
|
|
978
|
+
visible: Boolean, sourceId: String, sourceLayerId: String?
|
|
979
|
+
) {
|
|
980
|
+
if (this.mapLibreMap == null) {
|
|
981
|
+
return
|
|
982
|
+
}
|
|
983
|
+
mapLibreMap!!.getStyle { style ->
|
|
984
|
+
val layers = style.layers
|
|
985
|
+
for (layer in layers) {
|
|
986
|
+
val layerSourceInfo = LayerSourceInfo(layer)
|
|
987
|
+
if (layerSourceInfo.sourceId == sourceId && (sourceLayerId == null || sourceLayerId == layerSourceInfo.sourceLayerId)) {
|
|
988
|
+
layer.setProperties(PropertyFactory.visibility(if (visible) Property.VISIBLE else Property.NONE))
|
|
989
|
+
}
|
|
990
|
+
}
|
|
991
|
+
}
|
|
992
|
+
}
|
|
993
|
+
|
|
994
|
+
fun init() {
|
|
995
|
+
// Required for rendering properly in Android Oreo
|
|
996
|
+
viewTreeObserver.dispatchOnGlobalLayout()
|
|
997
|
+
}
|
|
998
|
+
|
|
999
|
+
override fun isDestroyed(): Boolean {
|
|
1000
|
+
return destroyed
|
|
1001
|
+
}
|
|
1002
|
+
|
|
1003
|
+
fun getStyle(onStyleLoaded: OnStyleLoaded) {
|
|
1004
|
+
if (this.mapLibreMap == null) {
|
|
1005
|
+
return
|
|
1006
|
+
}
|
|
1007
|
+
|
|
1008
|
+
mapLibreMap!!.getStyle(onStyleLoaded)
|
|
1009
|
+
}
|
|
1010
|
+
|
|
1011
|
+
private fun updateUISettings() {
|
|
1012
|
+
if (mapLibreMap == null) {
|
|
1013
|
+
return
|
|
1014
|
+
}
|
|
1015
|
+
|
|
1016
|
+
val uiSettings = mapLibreMap!!.uiSettings
|
|
1017
|
+
|
|
1018
|
+
if (scrollEnabled != null && uiSettings.isScrollGesturesEnabled != scrollEnabled) {
|
|
1019
|
+
uiSettings.isScrollGesturesEnabled = scrollEnabled!!
|
|
1020
|
+
|
|
1021
|
+
if (!scrollEnabled!!) {
|
|
1022
|
+
mapLibreMap!!.gesturesManager.moveGestureDetector.interrupt()
|
|
1023
|
+
}
|
|
1024
|
+
}
|
|
1025
|
+
|
|
1026
|
+
if (zoomEnabled != null && uiSettings.isZoomGesturesEnabled != zoomEnabled) {
|
|
1027
|
+
uiSettings.isZoomGesturesEnabled = zoomEnabled!!
|
|
1028
|
+
|
|
1029
|
+
if (!zoomEnabled!!) {
|
|
1030
|
+
mapLibreMap!!.gesturesManager.standardScaleGestureDetector.interrupt()
|
|
1031
|
+
}
|
|
1032
|
+
}
|
|
1033
|
+
|
|
1034
|
+
if (rotateEnabled != null && uiSettings.isRotateGesturesEnabled != rotateEnabled) {
|
|
1035
|
+
uiSettings.isRotateGesturesEnabled = rotateEnabled!!
|
|
1036
|
+
|
|
1037
|
+
if (!rotateEnabled!!) {
|
|
1038
|
+
mapLibreMap!!.gesturesManager.rotateGestureDetector.interrupt()
|
|
1039
|
+
}
|
|
1040
|
+
}
|
|
1041
|
+
|
|
1042
|
+
if (pitchEnabled != null && uiSettings.isTiltGesturesEnabled != pitchEnabled) {
|
|
1043
|
+
uiSettings.isTiltGesturesEnabled = pitchEnabled!!
|
|
1044
|
+
}
|
|
1045
|
+
|
|
1046
|
+
if (tintColor != null) {
|
|
1047
|
+
uiSettings.setAttributionTintColor(tintColor!!)
|
|
1048
|
+
}
|
|
1049
|
+
|
|
1050
|
+
if (attributionEnabled != null && uiSettings.isAttributionEnabled != attributionEnabled) {
|
|
1051
|
+
uiSettings.isAttributionEnabled = attributionEnabled!!
|
|
1052
|
+
}
|
|
1053
|
+
|
|
1054
|
+
if (attributionGravity != null && uiSettings.attributionGravity != attributionGravity) {
|
|
1055
|
+
uiSettings.attributionGravity = attributionGravity!!
|
|
1056
|
+
}
|
|
1057
|
+
|
|
1058
|
+
if (attributionMargin != null && (uiSettings.attributionMarginLeft != attributionMargin!![0] || uiSettings.attributionMarginTop != attributionMargin!![1] || uiSettings.attributionMarginRight != attributionMargin!![2] || uiSettings.attributionMarginBottom != attributionMargin!![3])) {
|
|
1059
|
+
uiSettings.setAttributionMargins(
|
|
1060
|
+
attributionMargin!![0],
|
|
1061
|
+
attributionMargin!![1],
|
|
1062
|
+
attributionMargin!![2],
|
|
1063
|
+
attributionMargin!![3]
|
|
1064
|
+
)
|
|
1065
|
+
}
|
|
1066
|
+
|
|
1067
|
+
if (logoEnabled != null && uiSettings.isLogoEnabled != logoEnabled) {
|
|
1068
|
+
uiSettings.setLogoEnabled(logoEnabled!!)
|
|
1069
|
+
}
|
|
1070
|
+
|
|
1071
|
+
if (logoGravity != null && uiSettings.logoGravity != logoGravity) {
|
|
1072
|
+
uiSettings.logoGravity = logoGravity!!
|
|
1073
|
+
}
|
|
1074
|
+
|
|
1075
|
+
if (logoMargins != null && (uiSettings.logoMarginLeft != logoMargins!![0] || uiSettings.logoMarginTop != logoMargins!![1] || uiSettings.logoMarginRight != logoMargins!![2] || uiSettings.logoMarginBottom != logoMargins!![3])) {
|
|
1076
|
+
uiSettings.setLogoMargins(
|
|
1077
|
+
logoMargins!![0], logoMargins!![1], logoMargins!![2], logoMargins!![3]
|
|
1078
|
+
)
|
|
1079
|
+
}
|
|
1080
|
+
|
|
1081
|
+
if (compassEnabled != null && uiSettings.isCompassEnabled != compassEnabled) {
|
|
1082
|
+
uiSettings.setCompassEnabled(compassEnabled!!)
|
|
1083
|
+
}
|
|
1084
|
+
|
|
1085
|
+
if (compassGravity != null && uiSettings.compassGravity != compassGravity) {
|
|
1086
|
+
uiSettings.compassGravity = compassGravity!!
|
|
1087
|
+
}
|
|
1088
|
+
|
|
1089
|
+
if (compassMargins != null && (uiSettings.compassMarginLeft != compassMargins!![0] || uiSettings.compassMarginTop != compassMargins!![1] || uiSettings.compassMarginRight != compassMargins!![2] || uiSettings.compassMarginBottom != compassMargins!![3])) {
|
|
1090
|
+
uiSettings.setCompassMargins(
|
|
1091
|
+
compassMargins!![0], compassMargins!![1], compassMargins!![2], compassMargins!![3]
|
|
1092
|
+
)
|
|
1093
|
+
}
|
|
1094
|
+
}
|
|
1095
|
+
|
|
1096
|
+
private fun updatePreferredFramesPerSecond() {
|
|
1097
|
+
if (preferredFramesPerSecond == null) {
|
|
1098
|
+
return
|
|
1099
|
+
}
|
|
1100
|
+
setMaximumFps(preferredFramesPerSecond!!)
|
|
1101
|
+
}
|
|
1102
|
+
|
|
1103
|
+
val contentInset: DoubleArray
|
|
1104
|
+
get() {
|
|
1105
|
+
if (insets == null) {
|
|
1106
|
+
return doubleArrayOf(0.0, 0.0, 0.0, 0.0)
|
|
1107
|
+
}
|
|
1108
|
+
var top = 0.0
|
|
1109
|
+
var right = 0.0
|
|
1110
|
+
var bottom = 0.0
|
|
1111
|
+
var left = 0.0
|
|
1112
|
+
|
|
1113
|
+
if (insets!!.size() == 4) {
|
|
1114
|
+
top = insets!!.getInt(0).toDouble()
|
|
1115
|
+
right = insets!!.getInt(1).toDouble()
|
|
1116
|
+
bottom = insets!!.getInt(2).toDouble()
|
|
1117
|
+
left = insets!!.getInt(3).toDouble()
|
|
1118
|
+
} else if (insets!!.size() == 2) {
|
|
1119
|
+
top = insets!!.getInt(0).toDouble()
|
|
1120
|
+
right = insets!!.getInt(1).toDouble()
|
|
1121
|
+
bottom = top
|
|
1122
|
+
left = right
|
|
1123
|
+
} else if (insets!!.size() == 1) {
|
|
1124
|
+
top = insets!!.getInt(0).toDouble()
|
|
1125
|
+
right = top
|
|
1126
|
+
bottom = top
|
|
1127
|
+
left = top
|
|
1128
|
+
}
|
|
1129
|
+
|
|
1130
|
+
|
|
1131
|
+
return doubleArrayOf(
|
|
1132
|
+
left * displayDensity,
|
|
1133
|
+
top * displayDensity,
|
|
1134
|
+
right * displayDensity,
|
|
1135
|
+
bottom * displayDensity
|
|
1136
|
+
)
|
|
1137
|
+
}
|
|
1138
|
+
|
|
1139
|
+
private fun updateInsets() {
|
|
1140
|
+
if (this.mapLibreMap == null || insets == null) {
|
|
1141
|
+
return
|
|
1142
|
+
}
|
|
1143
|
+
|
|
1144
|
+
val padding = this.contentInset
|
|
1145
|
+
val top = padding[1]
|
|
1146
|
+
val right = padding[2]
|
|
1147
|
+
val bottom = padding[3]
|
|
1148
|
+
val left = padding[0]
|
|
1149
|
+
|
|
1150
|
+
mapLibreMap!!.setPadding(
|
|
1151
|
+
left.toInt(), top.toInt(), right.toInt(), bottom.toInt()
|
|
1152
|
+
)
|
|
1153
|
+
}
|
|
1154
|
+
|
|
1155
|
+
private fun setLifecycleListeners() {
|
|
1156
|
+
val reactContext = context as ReactContext
|
|
1157
|
+
|
|
1158
|
+
lifeCycleListener = object : LifecycleEventListener {
|
|
1159
|
+
override fun onHostResume() {
|
|
1160
|
+
onResume()
|
|
1161
|
+
}
|
|
1162
|
+
|
|
1163
|
+
override fun onHostPause() {
|
|
1164
|
+
onPause()
|
|
1165
|
+
}
|
|
1166
|
+
|
|
1167
|
+
override fun onHostDestroy() {
|
|
1168
|
+
dispose()
|
|
1169
|
+
}
|
|
1170
|
+
}
|
|
1171
|
+
|
|
1172
|
+
reactContext.addLifecycleEventListener(lifeCycleListener)
|
|
1173
|
+
}
|
|
1174
|
+
|
|
1175
|
+
private fun makeViewState(isAnimated: Boolean?): WritableMap {
|
|
1176
|
+
val position = mapLibreMap!!.cameraPosition
|
|
1177
|
+
val viewState: WritableMap = WritableNativeMap()
|
|
1178
|
+
|
|
1179
|
+
if (position.target == null) {
|
|
1180
|
+
return viewState
|
|
1181
|
+
}
|
|
1182
|
+
|
|
1183
|
+
viewState.putDouble("longitude", position.target!!.longitude)
|
|
1184
|
+
viewState.putDouble("latitude", position.target!!.latitude)
|
|
1185
|
+
|
|
1186
|
+
viewState.putDouble("zoom", position.zoom)
|
|
1187
|
+
viewState.putDouble("bearing", position.bearing)
|
|
1188
|
+
viewState.putDouble("pitch", position.tilt)
|
|
1189
|
+
|
|
1190
|
+
try {
|
|
1191
|
+
val visibleRegion = mapLibreMap!!.projection.visibleRegion
|
|
1192
|
+
viewState.putArray(
|
|
1193
|
+
"bounds", GeoJSONUtils.fromLatLngBounds(visibleRegion.latLngBounds)
|
|
1194
|
+
)
|
|
1195
|
+
} catch (ex: Exception) {
|
|
1196
|
+
Logger.e(
|
|
1197
|
+
LOG_TAG, String.format(
|
|
1198
|
+
"An error occurred while attempting to make the region: %s", ex.message
|
|
1199
|
+
)
|
|
1200
|
+
)
|
|
1201
|
+
}
|
|
1202
|
+
|
|
1203
|
+
viewState.putBoolean(
|
|
1204
|
+
"animated", isAnimated ?: cameraChangeTracker.isAnimated
|
|
1205
|
+
)
|
|
1206
|
+
viewState.putBoolean("userInteraction", cameraChangeTracker.isUserInteraction)
|
|
1207
|
+
|
|
1208
|
+
return viewState
|
|
1209
|
+
}
|
|
1210
|
+
|
|
1211
|
+
fun sendRegionChangeEvent(isAnimated: Boolean) {
|
|
1212
|
+
val event = MapChangeEvent(
|
|
1213
|
+
surfaceId, id, "onRegionDidChange", makeViewState(isAnimated)
|
|
1214
|
+
)
|
|
1215
|
+
eventDispatcher?.dispatchEvent(event)
|
|
1216
|
+
|
|
1217
|
+
cameraChangeTracker.setReason(CameraChangeTracker.EMPTY)
|
|
1218
|
+
}
|
|
1219
|
+
|
|
1220
|
+
private fun removeAllSourcesFromMap() {
|
|
1221
|
+
if (sources.isEmpty()) {
|
|
1222
|
+
return
|
|
1223
|
+
}
|
|
1224
|
+
for (key in sources.keys) {
|
|
1225
|
+
val source = sources[key]
|
|
1226
|
+
source!!.removeFromMap(this)
|
|
1227
|
+
}
|
|
1228
|
+
}
|
|
1229
|
+
|
|
1230
|
+
private fun addAllSourcesToMap() {
|
|
1231
|
+
if (sources.isEmpty()) {
|
|
1232
|
+
return
|
|
1233
|
+
}
|
|
1234
|
+
for (key in sources.keys) {
|
|
1235
|
+
val source = sources[key]
|
|
1236
|
+
source!!.addToMap(this)
|
|
1237
|
+
}
|
|
1238
|
+
}
|
|
1239
|
+
|
|
1240
|
+
private val allTouchableSources: MutableList<MLRNSource<*>>
|
|
1241
|
+
get() {
|
|
1242
|
+
val sources: MutableList<MLRNSource<*>> = ArrayList()
|
|
1243
|
+
|
|
1244
|
+
for (key in this.sources.keys) {
|
|
1245
|
+
val source = this.sources[key]
|
|
1246
|
+
if (source != null && source.hasPressListener()) {
|
|
1247
|
+
sources.add(source)
|
|
1248
|
+
}
|
|
1249
|
+
}
|
|
1250
|
+
|
|
1251
|
+
return sources
|
|
1252
|
+
}
|
|
1253
|
+
|
|
1254
|
+
private fun getTouchableSourceWithHighestZIndex(sources: MutableList<MLRNSource<*>>?): MLRNSource<*>? {
|
|
1255
|
+
if (sources == null || sources.isEmpty()) {
|
|
1256
|
+
return null
|
|
1257
|
+
}
|
|
1258
|
+
|
|
1259
|
+
if (sources.size == 1) {
|
|
1260
|
+
return sources[0]
|
|
1261
|
+
}
|
|
1262
|
+
|
|
1263
|
+
val layerToSourceMap: MutableMap<String?, MLRNSource<*>?> = HashMap()
|
|
1264
|
+
for (source in sources) {
|
|
1265
|
+
val layerIDs = source.getLayerIDs()
|
|
1266
|
+
|
|
1267
|
+
for (layerID in layerIDs) {
|
|
1268
|
+
layerToSourceMap.put(layerID, source)
|
|
1269
|
+
}
|
|
1270
|
+
}
|
|
1271
|
+
|
|
1272
|
+
val mapboxLayers = mapLibreMap!!.style!!.getLayers()
|
|
1273
|
+
for (i in mapboxLayers.indices.reversed()) {
|
|
1274
|
+
val mapboxLayer = mapboxLayers[i]
|
|
1275
|
+
|
|
1276
|
+
val layerID = mapboxLayer.getId()
|
|
1277
|
+
if (layerToSourceMap.containsKey(layerID)) {
|
|
1278
|
+
return layerToSourceMap[layerID]
|
|
1279
|
+
}
|
|
1280
|
+
}
|
|
1281
|
+
|
|
1282
|
+
return null
|
|
1283
|
+
}
|
|
1284
|
+
|
|
1285
|
+
fun sendRegionDidChangeEvent() {
|
|
1286
|
+
handleMapChangedEvent("onRegionDidChange", true)
|
|
1287
|
+
cameraChangeTracker.setReason(CameraChangeTracker.EMPTY)
|
|
1288
|
+
}
|
|
1289
|
+
|
|
1290
|
+
private fun handleMapChangedEvent(eventName: String, withViewState: Boolean? = null) {
|
|
1291
|
+
val event = if (withViewState == true) {
|
|
1292
|
+
MapChangeEvent(surfaceId, id, eventName, makeViewState(null))
|
|
1293
|
+
} else {
|
|
1294
|
+
MapChangeEvent(surfaceId, id, eventName)
|
|
1295
|
+
}
|
|
1296
|
+
|
|
1297
|
+
eventDispatcher?.dispatchEvent(event)
|
|
1298
|
+
}
|
|
1299
|
+
|
|
1300
|
+
/**
|
|
1301
|
+
* Adds the marker image to the map for use as a SymbolLayer icon
|
|
1302
|
+
*/
|
|
1303
|
+
private fun setUpImage(loadedStyle: Style) {
|
|
1304
|
+
loadedStyle.addImage(
|
|
1305
|
+
"MARKER_IMAGE_ID", BitmapFactory.decodeResource(
|
|
1306
|
+
this.resources, R.drawable.red_marker
|
|
1307
|
+
)
|
|
1308
|
+
)
|
|
1309
|
+
}
|
|
1310
|
+
|
|
1311
|
+
/**
|
|
1312
|
+
* PointAnnotations are rendered to a canvas, but react native Image component is
|
|
1313
|
+
* implemented on top of Fresco, and fresco will not load images when their view is
|
|
1314
|
+
* not attached to the window. So we'll have an offscreen view where we add those views
|
|
1315
|
+
* so they can rendered full to canvas.
|
|
1316
|
+
*/
|
|
1317
|
+
fun offscreenAnnotationViewContainer(): ViewGroup? {
|
|
1318
|
+
if (offscreenAnnotationViewContainer == null) {
|
|
1319
|
+
offscreenAnnotationViewContainer = FrameLayout(this.context)
|
|
1320
|
+
val flParams = LayoutParams(0, 0)
|
|
1321
|
+
flParams.setMargins(-10000, -10000, -10000, -10000)
|
|
1322
|
+
offscreenAnnotationViewContainer!!.layoutParams = flParams
|
|
1323
|
+
addView(offscreenAnnotationViewContainer)
|
|
1324
|
+
}
|
|
1325
|
+
return offscreenAnnotationViewContainer
|
|
1326
|
+
}
|
|
1327
|
+
|
|
1328
|
+
fun getMarkerViewManager(map: MapLibreMap): MarkerViewManager {
|
|
1329
|
+
if (markerViewManager == null) {
|
|
1330
|
+
markerViewManager = MarkerViewManager(this, map)
|
|
1331
|
+
}
|
|
1332
|
+
return markerViewManager!!
|
|
1333
|
+
}
|
|
1334
|
+
|
|
1335
|
+
companion object {
|
|
1336
|
+
const val LOG_TAG: String = "MLRNMapView"
|
|
1337
|
+
}
|
|
1338
|
+
}
|