@gugell/nitro-ui-maps-maplibre 0.0.0-stage → 0.3.0
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/CHANGELOG.md +43 -0
- package/LICENSE +21 -0
- package/Package.swift +106 -0
- package/README.md +97 -2
- package/android/build.gradle +5 -0
- package/android/src/main/java/com/margelo/nitro/maplibre/CameraPositionMapCamera.kt +9 -0
- package/android/src/main/java/com/margelo/nitro/maplibre/CurrentLocation.kt +24 -0
- package/android/src/main/java/com/margelo/nitro/maplibre/HybridNativeMapView.kt +247 -0
- package/android/src/main/java/com/margelo/nitro/maplibre/LocationPermission.kt +30 -0
- package/android/src/main/java/com/margelo/nitro/maplibre/MapCameraIsClose.kt +19 -0
- package/android/src/main/java/com/margelo/nitro/maplibre/MapLifecycle.kt +17 -0
- package/android/src/main/java/com/margelo/nitro/maplibre/MapMarkerImageBitmap.kt +56 -0
- package/android/src/main/java/com/margelo/nitro/maplibre/MapTapHandler.kt +53 -0
- package/android/src/main/java/com/margelo/nitro/maplibre/MarkerImageSync.kt +58 -0
- package/android/src/main/java/com/margelo/nitro/maplibre/PendingLocate.kt +6 -0
- package/android/src/main/java/com/margelo/nitro/maplibre/Rgba.kt +7 -0
- package/android/src/main/java/com/margelo/nitro/maplibre/StyleSync.kt +59 -0
- package/ios/HybridNativeMapView.swift +177 -0
- package/ios/LayerFilterSync.swift +21 -0
- package/ios/LocationAuthorizer.swift +41 -0
- package/ios/MLNCameraChangeReason+isGesture.swift +12 -0
- package/ios/MLNMapView+currentCamera.swift +9 -0
- package/ios/MapCamera+isClose.swift +14 -0
- package/ios/MapMarkerImage+render.swift +32 -0
- package/ios/MapStyleFile.swift +26 -0
- package/ios/MapTapHandler.swift +50 -0
- package/ios/MapViewDelegateProxy.swift +29 -0
- package/ios/MarkerImageSync.swift +48 -0
- package/ios/PendingLocate.swift +7 -0
- package/ios/ShapeSourceSync.swift +42 -0
- package/nitro.json +13 -0
- package/nitrogen/generated/.gitattributes +1 -0
- package/nitrogen/generated/android/NitroMapLibre+autolinking.cmake +38 -0
- package/nitrogen/generated/android/NitroMapLibre+autolinking.gradle +10 -0
- package/nitrogen/generated/android/NitroMapLibreOnLoad.cpp +24 -0
- package/nitrogen/generated/android/c++/JCallback_void_MapCamera_bool.cpp +57 -0
- package/nitrogen/generated/android/c++/JCallback_void_MapCoordinate.cpp +55 -0
- package/nitrogen/generated/android/c++/JCallback_void_std__string.cpp +56 -0
- package/nitrogen/generated/android/c++/JHybridNativeMapViewSpec.cpp +263 -0
- package/nitrogen/generated/android/c++/JMapCamera.cpp +39 -0
- package/nitrogen/generated/android/c++/JMapCoordinate.cpp +35 -0
- package/nitrogen/generated/android/c++/JMapInsets.cpp +37 -0
- package/nitrogen/generated/android/c++/JMapLayerFilter.cpp +35 -0
- package/nitrogen/generated/android/c++/JMapLocateResult.cpp +55 -0
- package/nitrogen/generated/android/c++/JMapMarkerImage.cpp +47 -0
- package/nitrogen/generated/android/c++/JMapMarkerShape.cpp +52 -0
- package/nitrogen/generated/android/c++/JMapSourceData.cpp +35 -0
- package/nitrogen/generated/android/c++/include/NitroMapLibre/private/JCallback_void_MapCamera_bool.hpp +56 -0
- package/nitrogen/generated/android/c++/include/NitroMapLibre/private/JCallback_void_MapCoordinate.hpp +54 -0
- package/nitrogen/generated/android/c++/include/NitroMapLibre/private/JCallback_void_std__string.hpp +55 -0
- package/nitrogen/generated/android/c++/include/NitroMapLibre/private/JHybridNativeMapViewSpec.hpp +139 -0
- package/nitrogen/generated/android/c++/include/NitroMapLibre/private/JHybridNativeMapViewSpecJavaPart.hpp +27 -0
- package/nitrogen/generated/android/c++/include/NitroMapLibre/private/JMapCamera.hpp +66 -0
- package/nitrogen/generated/android/c++/include/NitroMapLibre/private/JMapCoordinate.hpp +54 -0
- package/nitrogen/generated/android/c++/include/NitroMapLibre/private/JMapInsets.hpp +64 -0
- package/nitrogen/generated/android/c++/include/NitroMapLibre/private/JMapLayerFilter.hpp +54 -0
- package/nitrogen/generated/android/c++/include/NitroMapLibre/private/JMapLocateResult.hpp +77 -0
- package/nitrogen/generated/android/c++/include/NitroMapLibre/private/JMapMarkerImage.hpp +94 -0
- package/nitrogen/generated/android/c++/include/NitroMapLibre/private/JMapMarkerShape.hpp +72 -0
- package/nitrogen/generated/android/c++/include/NitroMapLibre/private/JMapSourceData.hpp +54 -0
- package/nitrogen/generated/android/include/NitroMapLibre/private/NitroMapLibreOnLoad.hpp +13 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/maplibre/Callback_void_MapCamera_bool.kt +69 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/maplibre/Callback_void_MapCoordinate.kt +69 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/maplibre/Callback_void_std__string.kt +69 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/maplibre/HybridNativeMapViewSpec.kt +187 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/maplibre/MapCamera.kt +62 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/maplibre/MapCoordinate.kt +52 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/maplibre/MapInsets.kt +62 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/maplibre/MapLayerFilter.kt +52 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/maplibre/MapLocateResult.kt +49 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/maplibre/MapMarkerImage.kt +87 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/maplibre/MapMarkerShape.kt +46 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/maplibre/MapSourceData.kt +52 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/maplibre/NitroMapLibreOnLoad.kt +22 -0
- package/nitrogen/generated/apple/NitroMapLibre-Swift-Cxx-Bridge.cpp +161 -0
- package/nitrogen/generated/apple/NitroMapLibreAppleCxx/NitroMapLibreAppleCxx.cpp +9 -0
- package/nitrogen/generated/apple/NitroMapLibreAppleCxx/include/NitroMapLibreAppleCxx/NitroMapLibreAppleCxx.h +126 -0
- package/nitrogen/generated/apple/NitroMapLibreAutolinking.cpp +20 -0
- package/nitrogen/generated/apple/NitroMapLibreAutolinking.mm +24 -0
- package/nitrogen/generated/apple/c++/HybridNativeMapViewSpecSwift.cpp +204 -0
- package/nitrogen/generated/apple/c++/HybridNativeMapViewSpec_cxx-Swift.cpp +28 -0
- package/nitrogen/generated/apple/c++/MapCamera-Swift.cpp +35 -0
- package/nitrogen/generated/apple/c++/MapCoordinate-Swift.cpp +33 -0
- package/nitrogen/generated/apple/c++/MapInsets-Swift.cpp +35 -0
- package/nitrogen/generated/apple/c++/MapLayerFilter-Swift.cpp +33 -0
- package/nitrogen/generated/apple/c++/MapLocateResult-Swift.cpp +49 -0
- package/nitrogen/generated/apple/c++/MapMarkerImage-Swift.cpp +40 -0
- package/nitrogen/generated/apple/c++/MapMarkerShape-Swift.cpp +46 -0
- package/nitrogen/generated/apple/c++/MapSourceData-Swift.cpp +33 -0
- package/nitrogen/generated/apple/c++/include/NitroMapLibre/NitroMapLibreAutolinking.hpp +13 -0
- package/nitrogen/generated/apple/c++/include/NitroMapLibre/private/HybridNativeMapViewSpecSwift.hpp +107 -0
- package/nitrogen/generated/apple/c++/include/NitroMapLibre/private/HybridNativeMapViewSpec_cxx-Swift.hpp +23 -0
- package/nitrogen/generated/apple/c++/include/NitroMapLibre/private/MapCamera-Swift.hpp +23 -0
- package/nitrogen/generated/apple/c++/include/NitroMapLibre/private/MapCoordinate-Swift.hpp +23 -0
- package/nitrogen/generated/apple/c++/include/NitroMapLibre/private/MapInsets-Swift.hpp +23 -0
- package/nitrogen/generated/apple/c++/include/NitroMapLibre/private/MapLayerFilter-Swift.hpp +23 -0
- package/nitrogen/generated/apple/c++/include/NitroMapLibre/private/MapLocateResult-Swift.hpp +23 -0
- package/nitrogen/generated/apple/c++/include/NitroMapLibre/private/MapMarkerImage-Swift.hpp +23 -0
- package/nitrogen/generated/apple/c++/include/NitroMapLibre/private/MapMarkerShape-Swift.hpp +23 -0
- package/nitrogen/generated/apple/c++/include/NitroMapLibre/private/MapSourceData-Swift.hpp +23 -0
- package/nitrogen/generated/apple/c++/include/NitroMapLibre/private/NitroMapLibre-Swift-Cxx-Umbrella.hpp +63 -0
- package/nitrogen/generated/apple/c++/include/module.modulemap +12 -0
- package/nitrogen/generated/apple/swift/Callback_void___NitroMapLibre__MapCamera_bool.swift +66 -0
- package/nitrogen/generated/apple/swift/Callback_void___NitroMapLibre__MapCoordinate.swift +66 -0
- package/nitrogen/generated/apple/swift/Callback_void_swift__String.swift +66 -0
- package/nitrogen/generated/apple/swift/HybridNativeMapViewSpec.swift +83 -0
- package/nitrogen/generated/apple/swift/HybridNativeMapViewSpec_cxx.swift +312 -0
- package/nitrogen/generated/apple/swift/MapCamera.swift +49 -0
- package/nitrogen/generated/apple/swift/MapCoordinate.swift +35 -0
- package/nitrogen/generated/apple/swift/MapInsets.swift +49 -0
- package/nitrogen/generated/apple/swift/MapLayerFilter.swift +35 -0
- package/nitrogen/generated/apple/swift/MapLocateResult.swift +59 -0
- package/nitrogen/generated/apple/swift/MapMarkerImage.swift +84 -0
- package/nitrogen/generated/apple/swift/MapMarkerShape.swift +54 -0
- package/nitrogen/generated/apple/swift/MapSourceData.swift +35 -0
- package/nitrogen/generated/apple/swift/NitroMapLibre+ForeignTypeMetadata.swift +34 -0
- package/nitrogen/generated/apple/swift/Promise___NitroMapLibre__MapLocateResult.swift +102 -0
- package/nitrogen/generated/apple/swift/Promise_void.swift +100 -0
- package/nitrogen/generated/hybrid-classes.json +19 -0
- package/nitrogen/generated/shared/c++/NitroMapLibreCxxModule.cpp +2 -0
- package/nitrogen/generated/shared/c++/include/NitroMapLibre/NitroMapLibreCxxModule.hpp +2 -0
- package/nitrogen/generated/shared/javascript/NativeMapView.cjs +19 -0
- package/nitrogen/generated/shared/javascript/NativeMapView.d.cts +9 -0
- package/package.json +68 -3
- package/src/MapLibreView.tsx +101 -0
- package/src/cssColor.ts +9 -0
- package/src/host.ts +97 -0
- package/src/index.ts +19 -0
- package/src/layers.ts +162 -0
- package/src/maplibre.ts +32 -0
- package/src/nativeImage.ts +16 -0
- package/src/paint.ts +92 -0
- package/src/specs/MapCamera.ts +10 -0
- package/src/specs/MapCoordinate.ts +5 -0
- package/src/specs/MapInsets.ts +7 -0
- package/src/specs/MapLayerFilter.ts +5 -0
- package/src/specs/MapLocateResult.ts +2 -0
- package/src/specs/MapMarkerImage.ts +19 -0
- package/src/specs/MapMarkerShape.ts +2 -0
- package/src/specs/MapSourceData.ts +5 -0
- package/src/specs/NativeMapView.nitro.ts +68 -0
- package/src/style.ts +35 -0
- package/src/style.types.ts +25 -0
- package/src/types.ts +96 -0
- package/src/useMapStyle.ts +54 -0
- package/src/useSourceUpdates.ts +41 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
## 0.3.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- [#7](https://github.com/gugell/nitro-ui-maps/pull/7) [`70d2a07`](https://github.com/gugell/nitro-ui-maps/commit/70d2a0750e457622e330f49523bcbd120a533058) Thanks [@gugell](https://github.com/gugell)! - Engines are objects you create and pass to a view, the way a camera library passes a device.
|
|
8
|
+
|
|
9
|
+
- `createMapLibreEngine(options)` replaces `maplibre(options)`; `createMapEngine(definition)` replaces `defineMapEngine`.
|
|
10
|
+
- `<MapView engine={engine} />` draws with that engine and types its own props (MapLibre's `mapStyle`, `layers`, …). `<MapProvider engine>` and `createMapView(engine)` still work.
|
|
11
|
+
- `getMapEngine(engines, { needs, glyphs })` and `useMapEngine(engines, filter)` pick the engine that best fits what a screen needs. They rank the engines and never drop one, so a list always yields an engine.
|
|
12
|
+
- `MapMarker.selectedIcon`: the icon a selected marker draws. Markers no longer have to change when the selection does, so a pick redraws only the selected marker.
|
|
13
|
+
- No casts between engine types: an engine with its own props fits wherever a `MapEngine` goes.
|
|
14
|
+
|
|
15
|
+
### Patch Changes
|
|
16
|
+
|
|
17
|
+
- [#5](https://github.com/gugell/nitro-ui-maps/pull/5) [`c54a0c4`](https://github.com/gugell/nitro-ui-maps/commit/c54a0c4d91581371ac2f9bb1d012ccd55649e96b) Thanks [@gugell](https://github.com/gugell)! - Published on npm (with provenance) instead of GitHub Packages: install with no registry setup or token.
|
|
18
|
+
- Updated dependencies [[`70d2a07`](https://github.com/gugell/nitro-ui-maps/commit/70d2a0750e457622e330f49523bcbd120a533058), [`c54a0c4`](https://github.com/gugell/nitro-ui-maps/commit/c54a0c4d91581371ac2f9bb1d012ccd55649e96b)]:
|
|
19
|
+
- @gugell/nitro-ui-maps@0.3.0
|
|
20
|
+
|
|
21
|
+
## 0.2.1
|
|
22
|
+
|
|
23
|
+
### Patch Changes
|
|
24
|
+
|
|
25
|
+
- [#2](https://github.com/gugell/nitro-ui-maps/pull/2) [`0ec81a2`](https://github.com/gugell/nitro-ui-maps/commit/0ec81a27b3b38f59389aa26e857e39d46a28a75f) Thanks [@gugell](https://github.com/gugell)! - Faster updates. Picking a marker now changes a layer filter and the one-marker source instead of
|
|
26
|
+
re-sending every marker; marker features are serialized once per marker object; only sources whose
|
|
27
|
+
data changed reach native, and native parses them off the main thread. Marker icons are drawn off
|
|
28
|
+
the main thread and only when new or changed, and icons no longer in use are removed. Inline
|
|
29
|
+
options (camera, gestures, clustering, …) and inline callbacks no longer rebuild the style or
|
|
30
|
+
re-send props each render. The selected marker now stays counted in its cluster.
|
|
31
|
+
- Updated dependencies [[`0ec81a2`](https://github.com/gugell/nitro-ui-maps/commit/0ec81a27b3b38f59389aa26e857e39d46a28a75f)]:
|
|
32
|
+
- @gugell/nitro-ui-maps@0.2.1
|
|
33
|
+
|
|
34
|
+
## 0.2.0
|
|
35
|
+
|
|
36
|
+
- First release as the MapLibre Native engine of `@gugell/nitro-ui-maps` (the native view of 0.1.0,
|
|
37
|
+
moved here): `maplibre(options)` makes the engine; views take `mapStyle`.
|
|
38
|
+
- Engine options: `defaultStyle`, `fallbackStyle`, `fetchStyle`, `onStyleError`, `textFont`, and
|
|
39
|
+
`layers` to merge MapLibre paint and layout over the built marker layers.
|
|
40
|
+
- Android draws marker glyphs from the app's drawables (`glyph.androidDrawable`), tinted.
|
|
41
|
+
- The native module is `NitroMapLibre` (host view `NitroMapLibreView`), so other engines can be
|
|
42
|
+
installed next to it.
|
|
43
|
+
- Peers: `nitro-ui-renderer` 0.3 or 0.4.
|
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 IAUTI LABS
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
|
9
|
+
of the Software, and to permit persons to whom the Software is furnished to do
|
|
10
|
+
so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/Package.swift
ADDED
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
// swift-tools-version: 6.4
|
|
2
|
+
|
|
3
|
+
import Foundation
|
|
4
|
+
import PackageDescription
|
|
5
|
+
|
|
6
|
+
let name = "NitroMapLibre"
|
|
7
|
+
let generated = "nitrogen/generated"
|
|
8
|
+
let nitroDependencies: [Target.Dependency] = [
|
|
9
|
+
.product(name: "NitroModules", package: "nitro-core"),
|
|
10
|
+
.product(name: "NitroUIRenderer", package: "nitro-ui-renderer"),
|
|
11
|
+
]
|
|
12
|
+
// MapLibre Native, the version @maplibre/maplibre-react-native 11.3.4 runs.
|
|
13
|
+
let mapLibre: Target.Dependency = .product(name: "MapLibre", package: "maplibre-gl-native-distribution")
|
|
14
|
+
let cxxSettings: [CXXSetting] = [
|
|
15
|
+
.define("DEBUG", .when(configuration: .debug)),
|
|
16
|
+
.define("NDEBUG", .when(configuration: .release)),
|
|
17
|
+
.disableWarning("nullability-extension"),
|
|
18
|
+
]
|
|
19
|
+
let swiftSources = ["ios", "\(generated)/apple/swift"]
|
|
20
|
+
let bridgeSources = ["c++", "NitroMapLibre-Swift-Cxx-Bridge.cpp", "NitroMapLibreAutolinking.cpp"]
|
|
21
|
+
|
|
22
|
+
// The maplibre engine of @gugell/nitro-ui-maps, as a bare-host Nitro module. Nitrogen generates the
|
|
23
|
+
// bindings (`pnpm specs`); this manifest owns the targets.
|
|
24
|
+
let package = Package(
|
|
25
|
+
name: name,
|
|
26
|
+
platforms: [.iOS(.v16), .macOS(.v13)],
|
|
27
|
+
products: [
|
|
28
|
+
.library(name: name, targets: ["\(name)Cxx", name, "\(name)SwiftBridge"])
|
|
29
|
+
],
|
|
30
|
+
dependencies: [
|
|
31
|
+
.package(path: "../nitro-core"),
|
|
32
|
+
.package(path: "../nitro-ui-renderer"),
|
|
33
|
+
.package(url: "https://github.com/maplibre/maplibre-gl-native-distribution", exact: "6.26.0"),
|
|
34
|
+
],
|
|
35
|
+
targets: [
|
|
36
|
+
.target(
|
|
37
|
+
name: "\(name)Cxx",
|
|
38
|
+
dependencies: nitroDependencies,
|
|
39
|
+
path: "\(generated)/shared/c++",
|
|
40
|
+
exclude: ["include"],
|
|
41
|
+
publicHeadersPath: "include",
|
|
42
|
+
cxxSettings: cxxSettings
|
|
43
|
+
),
|
|
44
|
+
.target(
|
|
45
|
+
name: "\(name)AppleCxx",
|
|
46
|
+
dependencies: [.target(name: "\(name)Cxx")] + nitroDependencies,
|
|
47
|
+
path: "\(generated)/apple/\(name)AppleCxx",
|
|
48
|
+
cxxSettings: cxxSettings
|
|
49
|
+
),
|
|
50
|
+
.target(
|
|
51
|
+
name: name,
|
|
52
|
+
dependencies: [.target(name: "\(name)AppleCxx"), mapLibre] + nitroDependencies,
|
|
53
|
+
path: ".",
|
|
54
|
+
exclude: excludes(in: ".", keeping: swiftSources),
|
|
55
|
+
sources: swiftSources,
|
|
56
|
+
cxxSettings: cxxSettings,
|
|
57
|
+
swiftSettings: [
|
|
58
|
+
// UIKit implementations run synchronously on the host's main thread.
|
|
59
|
+
.swiftLanguageMode(.v5),
|
|
60
|
+
.unsafeFlags(["-strict-concurrency=minimal"]),
|
|
61
|
+
.enableUpcomingFeature("InternalImportsByDefault"),
|
|
62
|
+
.enableUpcomingFeature("MemberImportVisibility"),
|
|
63
|
+
.interoperabilityMode(.Cxx),
|
|
64
|
+
.unsafeFlags(["-Xfrontend", "-clang-header-expose-decls=has-expose-attr-or-stdlib"]),
|
|
65
|
+
.unsafeFlags([
|
|
66
|
+
"-Xfrontend", "-clang-header-expose-module",
|
|
67
|
+
"-Xfrontend", "NitroModules=NitroModules-Swift.h",
|
|
68
|
+
]),
|
|
69
|
+
]
|
|
70
|
+
),
|
|
71
|
+
.target(
|
|
72
|
+
name: "\(name)SwiftBridge",
|
|
73
|
+
dependencies: [.target(name: name), .target(name: "\(name)AppleCxx")] + nitroDependencies,
|
|
74
|
+
path: "\(generated)/apple",
|
|
75
|
+
exclude: excludes(in: "\(generated)/apple", keeping: bridgeSources) + ["c++/include"],
|
|
76
|
+
sources: bridgeSources,
|
|
77
|
+
publicHeadersPath: "c++/include",
|
|
78
|
+
cxxSettings: cxxSettings + [
|
|
79
|
+
.unsafeFlags(["-I${GENERATED_MODULEMAP_DIR}", "-fno-modules"])
|
|
80
|
+
]
|
|
81
|
+
),
|
|
82
|
+
],
|
|
83
|
+
cxxLanguageStandard: .cxx20
|
|
84
|
+
)
|
|
85
|
+
|
|
86
|
+
func excludes(in path: String, keeping sources: [String]) -> [String] {
|
|
87
|
+
var parents: Set<String> = [""]
|
|
88
|
+
for source in sources {
|
|
89
|
+
var components = source.split(separator: "/").dropLast()
|
|
90
|
+
while !components.isEmpty {
|
|
91
|
+
parents.insert(components.joined(separator: "/"))
|
|
92
|
+
components = components.dropLast()
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
let root = URL(fileURLWithPath: Context.packageDirectory).appendingPathComponent(path)
|
|
96
|
+
return parents.sorted().flatMap { parent in
|
|
97
|
+
let entries =
|
|
98
|
+
(try? FileManager.default.contentsOfDirectory(
|
|
99
|
+
atPath: root.appendingPathComponent(parent).path)) ?? []
|
|
100
|
+
return entries.sorted().compactMap { entry in
|
|
101
|
+
let entryPath = parent.isEmpty ? entry : "\(parent)/\(entry)"
|
|
102
|
+
return entry.hasPrefix(".") || sources.contains(entryPath) || parents.contains(entryPath)
|
|
103
|
+
? nil : entryPath
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
}
|
package/README.md
CHANGED
|
@@ -1,3 +1,98 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @gugell/nitro-ui-maps-maplibre
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
The **MapLibre Native** engine for [`@gugell/nitro-ui-maps`](../core/README.md), on iOS and
|
|
4
|
+
Android. The platform map owns every gesture (pan with inertia, pinch, double-tap and two-finger-tap
|
|
5
|
+
zoom, rotate, pitch). Markers are GeoJSON points drawn by style layers, so thousands of them cost
|
|
6
|
+
one source update, not thousands of views. No API key needed: by default it shows OpenStreetMap's
|
|
7
|
+
raster tiles.
|
|
8
|
+
|
|
9
|
+
| | |
|
|
10
|
+
| ------------- | ------------------------------------------------------------------------ |
|
|
11
|
+
| iOS | MapLibre Native 6.26.0 (Swift Package `maplibre-gl-native-distribution`) |
|
|
12
|
+
| Android | `org.maplibre.gl:android-sdk-opengl:13.2.0` (Maven Central) |
|
|
13
|
+
| NitroUI | `nitro-ui-renderer` 0.3 or 0.4, `nitro-core` (the version your app pins) |
|
|
14
|
+
| Native module | `NitroMapLibre`, host view `NitroMapLibreView` |
|
|
15
|
+
|
|
16
|
+
## Install
|
|
17
|
+
|
|
18
|
+
From npm:
|
|
19
|
+
|
|
20
|
+
```bash
|
|
21
|
+
pnpm add @gugell/nitro-ui-maps @gugell/nitro-ui-maps-maplibre
|
|
22
|
+
bun run nitro-ui prepare
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
`nitro-ui prepare` finds the module through its `nitro.json`. A module installed through a symlink
|
|
26
|
+
(a monorepo link) can be listed in the app's `app.json`:
|
|
27
|
+
`"modules": ["node_modules/@gugell/nitro-ui-maps-maplibre"]`.
|
|
28
|
+
|
|
29
|
+
## Permissions
|
|
30
|
+
|
|
31
|
+
The map never asks for the location by itself; `locateUser()` asks the first time.
|
|
32
|
+
|
|
33
|
+
- **iOS**: `NSLocationWhenInUseUsageDescription` in `Info.plist`.
|
|
34
|
+
- **Android**: `ACCESS_COARSE_LOCATION` and `ACCESS_FINE_LOCATION` in `AndroidManifest.xml`.
|
|
35
|
+
|
|
36
|
+
## Use
|
|
37
|
+
|
|
38
|
+
Documentation: [MapLibre Native](https://gugell.github.io/nitro-ui-maps/engines/maplibre)
|
|
39
|
+
|
|
40
|
+
```tsx
|
|
41
|
+
import { MapView } from '@gugell/nitro-ui-maps'
|
|
42
|
+
import { OSM_RASTER_STYLE, createMapLibreEngine } from '@gugell/nitro-ui-maps-maplibre'
|
|
43
|
+
|
|
44
|
+
// Module scope: each call makes a new view component.
|
|
45
|
+
const engine = createMapLibreEngine({
|
|
46
|
+
fallbackStyle: OSM_RASTER_STYLE,
|
|
47
|
+
onStyleError: (error) => console.warn(error.message),
|
|
48
|
+
layers: { clusterCount: { paint: { 'text-halo-color': 'rgba(0,0,0,0.15)', 'text-halo-width': 1 } } },
|
|
49
|
+
})
|
|
50
|
+
|
|
51
|
+
<MapView
|
|
52
|
+
engine={engine}
|
|
53
|
+
layout={{ flex: 1 }}
|
|
54
|
+
mapStyle={styleUrl}
|
|
55
|
+
camera={camera}
|
|
56
|
+
onCameraChange={setCamera}
|
|
57
|
+
markers={markers}
|
|
58
|
+
markerIcons={[{ name: 'bar', shape: 'circle', size: 24, fillColor: '#7C3AED', glyph: { sfSymbol: 'wineglass', androidDrawable: 'ic_bar' } }]}
|
|
59
|
+
clustering
|
|
60
|
+
userLocation
|
|
61
|
+
/>
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
### Engine options (`createMapLibreEngine(options)`)
|
|
65
|
+
|
|
66
|
+
| Option | What it does |
|
|
67
|
+
| ---------------------------- | ----------------------------------------------------------------------------------------------- |
|
|
68
|
+
| `defaultStyle` | The style a view draws without `mapStyle`. Default `OSM_RASTER_STYLE`. |
|
|
69
|
+
| `fallbackStyle` | Drawn when a style URL can't be read. Default `OSM_RASTER_STYLE`. |
|
|
70
|
+
| `fetchStyle`, `onStyleError` | How style URLs are read (default `fetch`), and the failure report. |
|
|
71
|
+
| `textFont` | The font stack of cluster counts; the style must serve it. Default `['Noto Sans Regular']`. |
|
|
72
|
+
| `layers` | MapLibre `paint` / `layout` merged over the built `point`, `cluster` and `clusterCount` layers. |
|
|
73
|
+
|
|
74
|
+
### View props
|
|
75
|
+
|
|
76
|
+
| Prop | What it does |
|
|
77
|
+
| ---------- | ------------------------------------------------------------------------------------------- |
|
|
78
|
+
| `mapStyle` | A MapLibre style object, or a style URL (read in JS so the marker layers can be merged in). |
|
|
79
|
+
|
|
80
|
+
Plus every shared option of the core's `MapView`.
|
|
81
|
+
|
|
82
|
+
### Styles and keys
|
|
83
|
+
|
|
84
|
+
`OSM_RASTER_STYLE` uses `tile.openstreetmap.org`: fine for development and light use under the
|
|
85
|
+
[OSM tile usage policy](https://operations.osmfoundation.org/policies/tiles/). For production,
|
|
86
|
+
pass a vector style URL from a tile provider. A provider's **public client key** in a style URL
|
|
87
|
+
ships to every device anyway; restrict it to your app in the provider's dashboard. Never put a
|
|
88
|
+
secret key there.
|
|
89
|
+
|
|
90
|
+
### Lower-level helpers
|
|
91
|
+
|
|
92
|
+
`markersGeoJSON`, `markerLayers`, `withMarkerLayers`, `markerLayerPaints`, `clusterLayerPaints`,
|
|
93
|
+
`pointLayerPaint`, `cssColor`, `loadStyle` and `useMapStyle`: what the view builds, for tests or a
|
|
94
|
+
custom view.
|
|
95
|
+
|
|
96
|
+
## License
|
|
97
|
+
|
|
98
|
+
MIT
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
package com.margelo.nitro.maplibre
|
|
2
|
+
|
|
3
|
+
import org.maplibre.android.camera.CameraPosition
|
|
4
|
+
|
|
5
|
+
/** The map's camera as the spec's, or null before the map has a target. */
|
|
6
|
+
internal fun CameraPosition.toMapCamera(): MapCamera? {
|
|
7
|
+
val target = target ?: return null
|
|
8
|
+
return MapCamera(latitude = target.latitude, longitude = target.longitude, zoom = zoom, heading = bearing)
|
|
9
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
package com.margelo.nitro.maplibre
|
|
2
|
+
|
|
3
|
+
import android.annotation.SuppressLint
|
|
4
|
+
import android.content.Context
|
|
5
|
+
import android.location.Location
|
|
6
|
+
import android.location.LocationManager
|
|
7
|
+
import android.os.CancellationSignal
|
|
8
|
+
import androidx.core.content.ContextCompat
|
|
9
|
+
import androidx.core.location.LocationManagerCompat
|
|
10
|
+
import androidx.core.util.Consumer
|
|
11
|
+
|
|
12
|
+
/** One fresh location fix from the best enabled provider, or null when none answers. */
|
|
13
|
+
internal object CurrentLocation {
|
|
14
|
+
@SuppressLint("MissingPermission")
|
|
15
|
+
fun fetch(context: Context, completion: (Location?) -> Unit) {
|
|
16
|
+
val manager = ContextCompat.getSystemService(context, LocationManager::class.java) ?: return completion(null)
|
|
17
|
+
val provider = listOf(LocationManager.FUSED_PROVIDER, LocationManager.GPS_PROVIDER, LocationManager.NETWORK_PROVIDER)
|
|
18
|
+
.firstOrNull { runCatching { manager.isProviderEnabled(it) }.getOrDefault(false) }
|
|
19
|
+
?: return completion(null)
|
|
20
|
+
LocationManagerCompat.getCurrentLocation(manager, provider, null as CancellationSignal?, ContextCompat.getMainExecutor(context), Consumer<Location?> { location ->
|
|
21
|
+
completion(location ?: runCatching { manager.getLastKnownLocation(provider) }.getOrNull())
|
|
22
|
+
})
|
|
23
|
+
}
|
|
24
|
+
}
|
|
@@ -0,0 +1,247 @@
|
|
|
1
|
+
package com.margelo.nitro.maplibre
|
|
2
|
+
|
|
3
|
+
import android.annotation.SuppressLint
|
|
4
|
+
import com.margelo.nitro.core.Callback
|
|
5
|
+
import com.margelo.nitro.core.Promise
|
|
6
|
+
import com.margelo.nitro.core.invoke
|
|
7
|
+
import com.margelo.nitro.renderer.AndroidHost
|
|
8
|
+
import com.margelo.nitro.renderer.NativeView
|
|
9
|
+
import com.margelo.nitro.renderer.ViewOperations
|
|
10
|
+
import com.margelo.nitro.renderer.ViewState
|
|
11
|
+
import org.maplibre.android.MapLibre
|
|
12
|
+
import org.maplibre.android.camera.CameraPosition
|
|
13
|
+
import org.maplibre.android.camera.CameraUpdateFactory
|
|
14
|
+
import org.maplibre.android.geometry.LatLng
|
|
15
|
+
import org.maplibre.android.location.LocationComponentActivationOptions
|
|
16
|
+
import org.maplibre.android.location.LocationComponentOptions
|
|
17
|
+
import org.maplibre.android.maps.MapLibreMap
|
|
18
|
+
import org.maplibre.android.maps.MapView
|
|
19
|
+
import org.maplibre.android.maps.Style
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* MapLibre Native's MapView as a NitroUI view. The map owns its gestures; this class applies the
|
|
23
|
+
* props and reports camera settles and taps. Props that arrive before the map (or its style) is
|
|
24
|
+
* ready are kept and applied when it is.
|
|
25
|
+
*/
|
|
26
|
+
class HybridNativeMapView private constructor(
|
|
27
|
+
override val nativeState: ViewState,
|
|
28
|
+
private val mapView: MapView,
|
|
29
|
+
) : HybridNativeMapViewSpec(), NativeView, ViewOperations by nativeState {
|
|
30
|
+
private val density = mapView.resources.displayMetrics.density
|
|
31
|
+
private var map: MapLibreMap? = null
|
|
32
|
+
private var loadedStyle: Style? = null
|
|
33
|
+
private var placedCamera = false
|
|
34
|
+
private var gestureMove = false
|
|
35
|
+
private var pendingLocate: PendingLocate? = null
|
|
36
|
+
|
|
37
|
+
init {
|
|
38
|
+
nativeState.bind(this)
|
|
39
|
+
mapView.onCreate(null)
|
|
40
|
+
mapView.addOnAttachStateChangeListener(MapLifecycle(mapView))
|
|
41
|
+
mapView.getMapAsync { map -> mapReady(map) }
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
private fun mapReady(map: MapLibreMap) {
|
|
45
|
+
this.map = map
|
|
46
|
+
map.addOnCameraMoveStartedListener { reason -> gestureMove = reason == MapLibreMap.OnCameraMoveStartedListener.REASON_API_GESTURE }
|
|
47
|
+
map.addOnCameraIdleListener { cameraDidSettle() }
|
|
48
|
+
MapTapHandler(density, { pressableLayerIds }, { id -> onMarkerPress?.invoke(id) }, { latLng ->
|
|
49
|
+
onMapPress?.invoke(MapCoordinate(latitude = latLng.latitude, longitude = latLng.longitude))
|
|
50
|
+
}).attach(map)
|
|
51
|
+
applyGestures()
|
|
52
|
+
applyAttribution()
|
|
53
|
+
applyInsets()
|
|
54
|
+
applyCamera(animated = false)
|
|
55
|
+
loadStyle()
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
// Style and data
|
|
59
|
+
|
|
60
|
+
override var styleJSON: String = ""
|
|
61
|
+
set(value) {
|
|
62
|
+
if (value == field) return
|
|
63
|
+
field = value
|
|
64
|
+
loadStyle()
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
private val imageSync by lazy { MarkerImageSync(mapView.context, density) }
|
|
68
|
+
private val sourceSync = GeoJsonSourceSync()
|
|
69
|
+
private val filterSync = LayerFilterSync()
|
|
70
|
+
|
|
71
|
+
override var sources: Array<MapSourceData> = emptyArray()
|
|
72
|
+
set(value) {
|
|
73
|
+
field = value
|
|
74
|
+
sourceSync.update(value, loadedStyle)
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
override var images: Array<MapMarkerImage> = emptyArray()
|
|
78
|
+
set(value) {
|
|
79
|
+
field = value
|
|
80
|
+
loadedStyle?.let { imageSync.sync(value, it) }
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
override var layerFilters: Array<MapLayerFilter> = emptyArray()
|
|
84
|
+
set(value) {
|
|
85
|
+
field = value
|
|
86
|
+
loadedStyle?.let { filterSync.sync(value, it) }
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
override var pressableLayerIds: Array<String> = emptyArray()
|
|
90
|
+
|
|
91
|
+
private fun loadStyle() {
|
|
92
|
+
val map = map ?: return
|
|
93
|
+
if (styleJSON.isEmpty()) return
|
|
94
|
+
loadedStyle = null
|
|
95
|
+
map.setStyle(Style.Builder().fromJson(styleJSON)) { style ->
|
|
96
|
+
loadedStyle = style
|
|
97
|
+
imageSync.reset()
|
|
98
|
+
filterSync.reset()
|
|
99
|
+
imageSync.sync(images, style)
|
|
100
|
+
sourceSync.styleDidLoad(style)
|
|
101
|
+
filterSync.sync(layerFilters, style)
|
|
102
|
+
applyUserLocation()
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
// Camera
|
|
107
|
+
|
|
108
|
+
override var camera: MapCamera? = null
|
|
109
|
+
set(value) {
|
|
110
|
+
field = value
|
|
111
|
+
applyCamera(animated = placedCamera)
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
override var insets: MapInsets = MapInsets(top = 0.0, right = 0.0, bottom = 0.0, left = 0.0)
|
|
115
|
+
set(value) {
|
|
116
|
+
if (value == field) return
|
|
117
|
+
field = value
|
|
118
|
+
applyInsets()
|
|
119
|
+
// The camera centres in the room the insets leave: put it back where the app wants it.
|
|
120
|
+
applyCamera(animated = false, force = true)
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
private fun applyCamera(animated: Boolean, force: Boolean = false) {
|
|
124
|
+
val map = map ?: return
|
|
125
|
+
val camera = camera ?: return
|
|
126
|
+
if (!force && placedCamera && camera.isClose(map.cameraPosition)) return
|
|
127
|
+
val position = CameraPosition.Builder()
|
|
128
|
+
.target(LatLng(camera.latitude, camera.longitude))
|
|
129
|
+
.zoom(camera.zoom)
|
|
130
|
+
.bearing(camera.heading ?: map.cameraPosition.bearing)
|
|
131
|
+
.build()
|
|
132
|
+
val update = CameraUpdateFactory.newCameraPosition(position)
|
|
133
|
+
if (animated) map.animateCamera(update) else map.moveCamera(update)
|
|
134
|
+
placedCamera = true
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
private fun applyInsets() {
|
|
138
|
+
val map = map ?: return
|
|
139
|
+
map.moveCamera(
|
|
140
|
+
CameraUpdateFactory.paddingTo(
|
|
141
|
+
insets.left * density,
|
|
142
|
+
insets.top * density,
|
|
143
|
+
insets.right * density,
|
|
144
|
+
insets.bottom * density,
|
|
145
|
+
),
|
|
146
|
+
)
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
private fun cameraDidSettle() {
|
|
150
|
+
val camera = map?.cameraPosition?.toMapCamera() ?: return
|
|
151
|
+
val userInitiated = gestureMove
|
|
152
|
+
gestureMove = false
|
|
153
|
+
onCameraChange?.invoke(camera, userInitiated)
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
// Gestures and chrome
|
|
157
|
+
|
|
158
|
+
override var scrollEnabled: Boolean = true
|
|
159
|
+
set(value) { field = value; applyGestures() }
|
|
160
|
+
override var zoomEnabled: Boolean = true
|
|
161
|
+
set(value) { field = value; applyGestures() }
|
|
162
|
+
override var rotateEnabled: Boolean = true
|
|
163
|
+
set(value) { field = value; applyGestures() }
|
|
164
|
+
override var pitchEnabled: Boolean = false
|
|
165
|
+
set(value) { field = value; applyGestures() }
|
|
166
|
+
override var attributionVisible: Boolean = true
|
|
167
|
+
set(value) { field = value; applyAttribution() }
|
|
168
|
+
|
|
169
|
+
private fun applyGestures() {
|
|
170
|
+
val settings = map?.uiSettings ?: return
|
|
171
|
+
settings.isScrollGesturesEnabled = scrollEnabled
|
|
172
|
+
settings.isZoomGesturesEnabled = zoomEnabled
|
|
173
|
+
settings.isRotateGesturesEnabled = rotateEnabled
|
|
174
|
+
settings.isTiltGesturesEnabled = pitchEnabled
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
private fun applyAttribution() {
|
|
178
|
+
val settings = map?.uiSettings ?: return
|
|
179
|
+
settings.isAttributionEnabled = attributionVisible
|
|
180
|
+
settings.isLogoEnabled = attributionVisible
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
override var onCameraChange: Callback<(camera: MapCamera, userInitiated: Boolean) -> Unit>? = null
|
|
184
|
+
override var onMarkerPress: Callback<(markerId: String) -> Unit>? = null
|
|
185
|
+
override var onMapPress: Callback<(coordinate: MapCoordinate) -> Unit>? = null
|
|
186
|
+
|
|
187
|
+
// User location
|
|
188
|
+
|
|
189
|
+
override var showsUserLocation: Boolean = false
|
|
190
|
+
set(value) { field = value; applyUserLocation() }
|
|
191
|
+
|
|
192
|
+
override var userLocationColor: Double? = null
|
|
193
|
+
set(value) { field = value; applyUserLocation() }
|
|
194
|
+
|
|
195
|
+
@SuppressLint("MissingPermission")
|
|
196
|
+
private fun applyUserLocation(forceOn: Boolean = false) {
|
|
197
|
+
val map = map ?: return
|
|
198
|
+
val style = loadedStyle ?: return
|
|
199
|
+
val wanted = (showsUserLocation || forceOn) && LocationPermission.isGranted(mapView.context)
|
|
200
|
+
val component = map.locationComponent
|
|
201
|
+
if (!wanted) {
|
|
202
|
+
if (component.isLocationComponentActivated) component.isLocationComponentEnabled = false
|
|
203
|
+
return
|
|
204
|
+
}
|
|
205
|
+
val options = LocationComponentOptions.builder(mapView.context)
|
|
206
|
+
userLocationColor?.let { options.foregroundTintColor(rgbaToArgb(it)).accuracyColor(rgbaToArgb(it)) }
|
|
207
|
+
component.activateLocationComponent(
|
|
208
|
+
LocationComponentActivationOptions.builder(mapView.context, style)
|
|
209
|
+
.locationComponentOptions(options.build())
|
|
210
|
+
.useDefaultLocationEngine(true)
|
|
211
|
+
.build(),
|
|
212
|
+
)
|
|
213
|
+
component.isLocationComponentEnabled = true
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
override fun locateUser(zoom: Double?): Promise<MapLocateResult> {
|
|
217
|
+
val promise = Promise<MapLocateResult>()
|
|
218
|
+
mapView.post {
|
|
219
|
+
LocationPermission.request { granted ->
|
|
220
|
+
if (!granted) return@request promise.resolve(MapLocateResult.DENIED)
|
|
221
|
+
pendingLocate?.promise?.resolve(MapLocateResult.UNAVAILABLE)
|
|
222
|
+
val pending = PendingLocate(promise, zoom)
|
|
223
|
+
pendingLocate = pending
|
|
224
|
+
applyUserLocation(forceOn = true)
|
|
225
|
+
CurrentLocation.fetch(mapView.context) { location ->
|
|
226
|
+
if (pendingLocate !== pending) return@fetch
|
|
227
|
+
pendingLocate = null
|
|
228
|
+
val map = map
|
|
229
|
+
if (location == null || map == null) return@fetch pending.promise.resolve(MapLocateResult.UNAVAILABLE)
|
|
230
|
+
val target = LatLng(location.latitude, location.longitude)
|
|
231
|
+
map.animateCamera(CameraUpdateFactory.newLatLngZoom(target, pending.zoom ?: map.cameraPosition.zoom))
|
|
232
|
+
pending.promise.resolve(MapLocateResult.LOCATED)
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
return promise
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
companion object : HybridNativeMapViewSpec.Companion {
|
|
240
|
+
override fun constructor(): HybridNativeMapView {
|
|
241
|
+
val context = AndroidHost.context
|
|
242
|
+
MapLibre.getInstance(context)
|
|
243
|
+
val mapView = MapView(context)
|
|
244
|
+
return HybridNativeMapView(ViewState(mapView), mapView)
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
package com.margelo.nitro.maplibre
|
|
2
|
+
|
|
3
|
+
import android.Manifest
|
|
4
|
+
import android.content.Context
|
|
5
|
+
import android.content.pm.PackageManager
|
|
6
|
+
import androidx.activity.result.ActivityResultLauncher
|
|
7
|
+
import androidx.activity.result.contract.ActivityResultContracts
|
|
8
|
+
import androidx.core.content.ContextCompat
|
|
9
|
+
import com.margelo.nitro.renderer.AndroidHost
|
|
10
|
+
import java.util.UUID
|
|
11
|
+
|
|
12
|
+
/** Asks for the location permission (fine or coarse) when the app asks to locate the user. */
|
|
13
|
+
internal object LocationPermission {
|
|
14
|
+
private val permissions = arrayOf(Manifest.permission.ACCESS_FINE_LOCATION, Manifest.permission.ACCESS_COARSE_LOCATION)
|
|
15
|
+
|
|
16
|
+
fun isGranted(context: Context): Boolean =
|
|
17
|
+
permissions.any { ContextCompat.checkSelfPermission(context, it) == PackageManager.PERMISSION_GRANTED }
|
|
18
|
+
|
|
19
|
+
fun request(completion: (Boolean) -> Unit) {
|
|
20
|
+
val activity = AndroidHost.activity
|
|
21
|
+
if (isGranted(activity)) return completion(true)
|
|
22
|
+
val key = "nitro-ui-maps-location-${UUID.randomUUID()}"
|
|
23
|
+
var launcher: ActivityResultLauncher<Array<String>>? = null
|
|
24
|
+
launcher = activity.activityResultRegistry.register(key, ActivityResultContracts.RequestMultiplePermissions()) { results ->
|
|
25
|
+
launcher?.unregister()
|
|
26
|
+
completion(results.values.any { it })
|
|
27
|
+
}
|
|
28
|
+
launcher.launch(permissions)
|
|
29
|
+
}
|
|
30
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
package com.margelo.nitro.maplibre
|
|
2
|
+
|
|
3
|
+
import org.maplibre.android.camera.CameraPosition
|
|
4
|
+
import kotlin.math.abs
|
|
5
|
+
import kotlin.math.pow
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Whether this camera is where the map already is: within about one screen point, a hundredth of a
|
|
9
|
+
* zoom level and half a degree. The JS side echoes settled cameras back; those are not moves.
|
|
10
|
+
*/
|
|
11
|
+
internal fun MapCamera.isClose(to: CameraPosition): Boolean {
|
|
12
|
+
val target = to.target ?: return false
|
|
13
|
+
val degreesPerPoint = 360.0 / (512.0 * 2.0.pow(to.zoom))
|
|
14
|
+
val headingDelta = heading?.let { abs(((it - to.bearing + 540.0) % 360.0) - 180.0) } ?: 0.0
|
|
15
|
+
return abs(latitude - target.latitude) < degreesPerPoint &&
|
|
16
|
+
abs(longitude - target.longitude) < degreesPerPoint &&
|
|
17
|
+
abs(zoom - to.zoom) < 0.01 &&
|
|
18
|
+
headingDelta < 0.5
|
|
19
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
package com.margelo.nitro.maplibre
|
|
2
|
+
|
|
3
|
+
import android.view.View
|
|
4
|
+
import org.maplibre.android.maps.MapView
|
|
5
|
+
|
|
6
|
+
/** MapView's lifecycle follows the view's window: started while attached, stopped when not. */
|
|
7
|
+
internal class MapLifecycle(private val mapView: MapView) : View.OnAttachStateChangeListener {
|
|
8
|
+
override fun onViewAttachedToWindow(view: View) {
|
|
9
|
+
mapView.onStart()
|
|
10
|
+
mapView.onResume()
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
override fun onViewDetachedFromWindow(view: View) {
|
|
14
|
+
mapView.onPause()
|
|
15
|
+
mapView.onStop()
|
|
16
|
+
}
|
|
17
|
+
}
|