capacitor-mapboxnav 0.0.1

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.
@@ -0,0 +1,17 @@
1
+ require 'json'
2
+
3
+ package = JSON.parse(File.read(File.join(__dir__, 'package.json')))
4
+
5
+ Pod::Spec.new do |s|
6
+ s.name = 'CapacitorMapboxnav'
7
+ s.version = package['version']
8
+ s.summary = package['description']
9
+ s.license = package['license']
10
+ s.homepage = package['repository']['url']
11
+ s.author = package['author']
12
+ s.source = { :git => package['repository']['url'], :tag => s.version.to_s }
13
+ s.source_files = 'ios/Sources/**/*.{swift,h,m,c,cc,mm,cpp}'
14
+ s.ios.deployment_target = '15.0'
15
+ s.dependency 'Capacitor'
16
+ s.swift_version = '5.1'
17
+ end
package/Package.swift ADDED
@@ -0,0 +1,28 @@
1
+ // swift-tools-version: 5.9
2
+ import PackageDescription
3
+
4
+ let package = Package(
5
+ name: "CapacitorMapboxnav",
6
+ platforms: [.iOS(.v15)],
7
+ products: [
8
+ .library(
9
+ name: "CapacitorMapboxnav",
10
+ targets: ["capacitormapboxnavPlugin"])
11
+ ],
12
+ dependencies: [
13
+ .package(url: "https://github.com/ionic-team/capacitor-swift-pm.git", from: "8.0.0")
14
+ ],
15
+ targets: [
16
+ .target(
17
+ name: "capacitormapboxnavPlugin",
18
+ dependencies: [
19
+ .product(name: "Capacitor", package: "capacitor-swift-pm"),
20
+ .product(name: "Cordova", package: "capacitor-swift-pm")
21
+ ],
22
+ path: "ios/Sources/capacitormapboxnavPlugin"),
23
+ .testTarget(
24
+ name: "capacitormapboxnavPluginTests",
25
+ dependencies: ["capacitormapboxnavPlugin"],
26
+ path: "ios/Tests/capacitormapboxnavPluginTests")
27
+ ]
28
+ )
package/README.md ADDED
@@ -0,0 +1,107 @@
1
+ # capacitor-mapboxnav
2
+
3
+ capacitor mapbox navigation ndk
4
+
5
+ ## Install
6
+
7
+ To use npm
8
+
9
+ ```bash
10
+ npm install capacitor-mapboxnav
11
+ ````
12
+
13
+ To use yarn
14
+
15
+ ```bash
16
+ yarn add capacitor-mapboxnav
17
+ ```
18
+
19
+ Sync native files
20
+
21
+ ```bash
22
+ npx cap sync
23
+ ```
24
+
25
+ ## Android Setup
26
+
27
+ Mapbox Navigation requires a secret token to download its SDK.
28
+
29
+ 1. Go to your Mapbox account's [tokens page](https://console.mapbox.com/account/access-tokens/).
30
+ 2. Create a token with the `Downloads:Read` scope.
31
+ 3. Add the following to your global `~/.gradle/gradle.properties` or to `android/gradle.properties` in your project:
32
+ ```text
33
+ MAPBOX_DOWNLOADS_TOKEN=YOUR_SECRET_MAPBOX_ACCESS_TOKEN
34
+ ```
35
+
36
+ ## API
37
+
38
+ <docgen-index>
39
+
40
+ * [`echo(...)`](#echo)
41
+ * [`initialize(...)`](#initialize)
42
+ * [`startNavigation(...)`](#startnavigation)
43
+
44
+ </docgen-index>
45
+
46
+ <docgen-api>
47
+ <!--Update the source file JSDoc comments and rerun docgen to update the docs below-->
48
+
49
+ ### echo(...)
50
+
51
+ ```typescript
52
+ echo(options: { value: string; }) => Promise<{ value: string; }>
53
+ ```
54
+
55
+ | Param | Type |
56
+ | ------------- | ------------------------------- |
57
+ | **`options`** | <code>{ value: string; }</code> |
58
+
59
+ **Returns:** <code>Promise&lt;{ value: string; }&gt;</code>
60
+
61
+ --------------------
62
+
63
+
64
+ ### initialize(...)
65
+
66
+ ```typescript
67
+ initialize(options: { accessToken: string; }) => Promise<void>
68
+ ```
69
+
70
+ | Param | Type |
71
+ | ------------- | ------------------------------------- |
72
+ | **`options`** | <code>{ accessToken: string; }</code> |
73
+
74
+ --------------------
75
+
76
+
77
+ ### startNavigation(...)
78
+
79
+ ```typescript
80
+ startNavigation(options: { origin: { latitude: number; longitude: number; }; destination: { latitude: number; longitude: number; }; simulateRoute?: boolean; }) => Promise<void>
81
+ ```
82
+
83
+ | Param | Type |
84
+ | ------------- | -------------------------------------------------------------------------------------------------------------------------------------------------- |
85
+ | **`options`** | <code>{ origin: { latitude: number; longitude: number; }; destination: { latitude: number; longitude: number; }; simulateRoute?: boolean; }</code> |
86
+
87
+ --------------------
88
+
89
+ </docgen-api>
90
+
91
+ ### Example
92
+
93
+ ```typescript
94
+ import { capacitormapboxnav } from 'capacitor-mapboxnav';
95
+
96
+ async function navigate() {
97
+ await capacitormapboxnav.initialize({
98
+ accessToken: 'YOUR_PUBLIC_MAPBOX_ACCESS_TOKEN'
99
+ });
100
+
101
+ await capacitormapboxnav.startNavigation({
102
+ origin: { latitude: 37.7749, longitude: -122.4194 },
103
+ destination: { latitude: 37.7833, longitude: -122.4167 },
104
+ simulateRoute: true
105
+ });
106
+ }
107
+ ```
@@ -0,0 +1,86 @@
1
+ ext {
2
+ junitVersion = project.hasProperty('junitVersion') ? rootProject.ext.junitVersion : '4.13.2'
3
+ androidxAppCompatVersion = project.hasProperty('androidxAppCompatVersion') ? rootProject.ext.androidxAppCompatVersion : '1.7.1'
4
+ androidxJunitVersion = project.hasProperty('androidxJunitVersion') ? rootProject.ext.androidxJunitVersion : '1.3.0'
5
+ androidxEspressoCoreVersion = project.hasProperty('androidxEspressoCoreVersion') ? rootProject.ext.androidxEspressoCoreVersion : '3.7.0'
6
+ }
7
+
8
+ buildscript {
9
+ ext.kotlin_version = project.hasProperty('kotlinVersion') ? rootProject.ext.kotlinVersion : '1.9.23'
10
+ repositories {
11
+ google()
12
+ mavenCentral()
13
+ }
14
+ dependencies {
15
+ classpath 'com.android.tools.build:gradle:8.13.0'
16
+ classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
17
+ }
18
+ }
19
+
20
+ apply plugin: 'com.android.library'
21
+ apply plugin: 'kotlin-android'
22
+
23
+ android {
24
+ namespace = "com.castelioit.capacitormapboxnav"
25
+ compileSdk = project.hasProperty('compileSdkVersion') ? rootProject.ext.compileSdkVersion : 36
26
+ defaultConfig {
27
+ minSdkVersion project.hasProperty('minSdkVersion') ? rootProject.ext.minSdkVersion : 24
28
+ targetSdkVersion project.hasProperty('targetSdkVersion') ? rootProject.ext.targetSdkVersion : 36
29
+ versionCode 1
30
+ versionName "1.0"
31
+ testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
32
+ }
33
+ buildTypes {
34
+ release {
35
+ minifyEnabled false
36
+ proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
37
+ }
38
+ }
39
+ lintOptions {
40
+ abortOnError = false
41
+ }
42
+ compileOptions {
43
+ sourceCompatibility JavaVersion.VERSION_21
44
+ targetCompatibility JavaVersion.VERSION_21
45
+ }
46
+ kotlinOptions {
47
+ jvmTarget = "21"
48
+ }
49
+ }
50
+
51
+
52
+ repositories {
53
+ google()
54
+ mavenCentral()
55
+ maven {
56
+ url = uri("https://api.mapbox.com/downloads/v2/releases/maven")
57
+ authentication {
58
+ basic(BasicAuthentication)
59
+ }
60
+ credentials {
61
+ // Do not change the username below.
62
+ // This should always be `mapbox` (not your username).
63
+ username = "mapbox"
64
+ // Use the secret token you stored in gradle.properties as the password
65
+ password = project.hasProperty("MAPBOX_DOWNLOADS_TOKEN") ? project.property("MAPBOX_DOWNLOADS_TOKEN") : ""
66
+ }
67
+ }
68
+ }
69
+
70
+
71
+ dependencies {
72
+ implementation fileTree(dir: 'libs', include: ['*.jar'])
73
+ implementation project(':capacitor-android')
74
+ implementation "androidx.appcompat:appcompat:$androidxAppCompatVersion"
75
+ implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
76
+ testImplementation "junit:junit:$junitVersion"
77
+ androidTestImplementation "androidx.test.ext:junit:$androidxJunitVersion"
78
+ androidTestImplementation "androidx.test.espresso:espresso-core:$androidxEspressoCoreVersion"
79
+
80
+ // Mapbox Navigation SDK dependencies
81
+ implementation "com.mapbox.navigationcore:android:3.21.0-rc.1"
82
+ implementation "com.mapbox.navigationcore:ui-maps:3.21.0-rc.1"
83
+ implementation "com.mapbox.navigationcore:ui-components:3.21.0-rc.1"
84
+ implementation "com.mapbox.navigationcore:tripdata:3.21.0-rc.1"
85
+ implementation "com.mapbox.navigationcore:voice:3.21.0-rc.1"
86
+ }
@@ -0,0 +1,16 @@
1
+ <manifest xmlns:android="http://schemas.android.com/apk/res/android">
2
+ <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
3
+ <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
4
+ <uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
5
+ <uses-permission android:name="android.permission.FOREGROUND_SERVICE_LOCATION" />
6
+ <uses-permission android:name="android.permission.POST_NOTIFICATIONS" />
7
+ <uses-permission android:name="android.permission.INTERNET" />
8
+ <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
9
+
10
+ <application>
11
+ <activity
12
+ android:name=".NavigationActivity"
13
+ android:theme="@style/Theme.AppCompat.NoActionBar"
14
+ android:exported="false" />
15
+ </application>
16
+ </manifest>
@@ -0,0 +1,207 @@
1
+ package com.castelioit.capacitormapboxnav
2
+
3
+ import android.Manifest
4
+ import android.annotation.SuppressLint
5
+ import android.content.pm.PackageManager
6
+ import android.os.Bundle
7
+ import android.widget.Toast
8
+ import androidx.appcompat.app.AppCompatActivity
9
+ import androidx.core.app.ActivityCompat
10
+ import com.mapbox.api.directions.v5.models.RouteOptions
11
+ import com.mapbox.common.location.Location
12
+ import com.mapbox.geojson.Point
13
+ import com.mapbox.maps.CameraOptions
14
+ import com.mapbox.maps.EdgeInsets
15
+ import com.mapbox.maps.MapInitOptions
16
+ import com.mapbox.maps.MapView
17
+ import com.mapbox.maps.plugin.LocationPuck2D
18
+ import com.mapbox.maps.plugin.animation.camera
19
+ import com.mapbox.maps.plugin.attribution.attribution
20
+ import com.mapbox.maps.plugin.compass.compass
21
+ import com.mapbox.maps.plugin.locationcomponent.createDefault2DPuck
22
+ import com.mapbox.maps.plugin.locationcomponent.location
23
+ import com.mapbox.maps.plugin.logo.logo
24
+ import com.mapbox.maps.plugin.scalebar.scalebar
25
+ import com.mapbox.navigation.base.ExperimentalPreviewMapboxNavigationAPI
26
+ import com.mapbox.navigation.base.extensions.applyDefaultNavigationOptions
27
+ import com.mapbox.navigation.base.options.NavigationOptions
28
+ import com.mapbox.navigation.base.route.NavigationRoute
29
+ import com.mapbox.navigation.base.route.NavigationRouterCallback
30
+ import com.mapbox.navigation.base.route.RouterFailure
31
+ import com.mapbox.navigation.core.MapboxNavigation
32
+ import com.mapbox.navigation.core.directions.session.RoutesObserver
33
+ import com.mapbox.navigation.core.lifecycle.MapboxNavigationApp
34
+ import com.mapbox.navigation.core.lifecycle.MapboxNavigationObserver
35
+ import com.mapbox.navigation.core.lifecycle.requireMapboxNavigation
36
+ import com.mapbox.navigation.core.replay.route.ReplayProgressObserver
37
+ import com.mapbox.navigation.core.replay.route.ReplayRouteMapper
38
+ import com.mapbox.navigation.core.trip.session.LocationMatcherResult
39
+ import com.mapbox.navigation.core.trip.session.LocationObserver
40
+ import com.mapbox.navigation.ui.maps.camera.NavigationCamera
41
+ import com.mapbox.navigation.ui.maps.camera.data.MapboxNavigationViewportDataSource
42
+ import com.mapbox.navigation.ui.maps.location.NavigationLocationProvider
43
+ import com.mapbox.navigation.ui.maps.route.line.api.MapboxRouteLineApi
44
+ import com.mapbox.navigation.ui.maps.route.line.api.MapboxRouteLineView
45
+ import com.mapbox.navigation.ui.maps.route.line.model.MapboxRouteLineApiOptions
46
+ import com.mapbox.navigation.ui.maps.route.line.model.MapboxRouteLineViewOptions
47
+
48
+ class NavigationActivity : AppCompatActivity() {
49
+ private lateinit var mapView: MapView
50
+ private lateinit var viewportDataSource: MapboxNavigationViewportDataSource
51
+ private lateinit var navigationCamera: NavigationCamera
52
+ private lateinit var routeLineApi: MapboxRouteLineApi
53
+ private lateinit var routeLineView: MapboxRouteLineView
54
+ private lateinit var replayProgressObserver: ReplayProgressObserver
55
+ private val navigationLocationProvider = NavigationLocationProvider()
56
+ private val replayRouteMapper = ReplayRouteMapper()
57
+
58
+ private var originLat: Double = 0.0
59
+ private var originLng: Double = 0.0
60
+ private var destLat: Double = 0.0
61
+ private var destLng: Double = 0.0
62
+ private var simulateRoute: Boolean = false
63
+
64
+ override fun onCreate(savedInstanceState: Bundle?) {
65
+ super.onCreate(savedInstanceState)
66
+
67
+ originLat = intent.getDoubleExtra("originLat", 0.0)
68
+ originLng = intent.getDoubleExtra("originLng", 0.0)
69
+ destLat = intent.getDoubleExtra("destLat", 0.0)
70
+ destLng = intent.getDoubleExtra("destLng", 0.0)
71
+ simulateRoute = intent.getBooleanExtra("simulateRoute", false)
72
+
73
+ if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
74
+ ActivityCompat.requestPermissions(this, arrayOf(Manifest.permission.ACCESS_FINE_LOCATION), 1)
75
+ } else {
76
+ initializeMapComponents()
77
+ }
78
+ }
79
+
80
+ override fun onRequestPermissionsResult(requestCode: Int, permissions: Array<out String>, grantResults: IntArray) {
81
+ super.onRequestPermissionsResult(requestCode, permissions, grantResults)
82
+ if (requestCode == 1 && grantResults.isNotEmpty() && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
83
+ initializeMapComponents()
84
+ } else {
85
+ Toast.makeText(this, "Permission denied", Toast.LENGTH_SHORT).show()
86
+ finish()
87
+ }
88
+ }
89
+
90
+ private fun initializeMapComponents() {
91
+ mapView = MapView(this, MapInitOptions(
92
+ this,
93
+ cameraOptions = CameraOptions.Builder()
94
+ .center(Point.fromLngLat(originLng, originLat))
95
+ .zoom(14.0)
96
+ .build(),
97
+ ))
98
+
99
+ mapView.scalebar.marginTop = 200f
100
+ mapView.compass.marginTop = 200f
101
+ mapView.logo.marginBottom = 140f
102
+ mapView.attribution.marginBottom = 140f
103
+
104
+ mapView.location.apply {
105
+ setLocationProvider(navigationLocationProvider)
106
+ locationPuck = LocationPuck2D()
107
+ enabled = true
108
+ }
109
+
110
+ setContentView(mapView)
111
+
112
+ viewportDataSource = MapboxNavigationViewportDataSource(mapView.mapboxMap)
113
+ val pixelDensity = this.resources.displayMetrics.density
114
+ viewportDataSource.followingPadding = EdgeInsets(
115
+ 180.0 * pixelDensity,
116
+ 40.0 * pixelDensity,
117
+ 150.0 * pixelDensity,
118
+ 40.0 * pixelDensity
119
+ )
120
+
121
+ navigationCamera = NavigationCamera(mapView.mapboxMap, mapView.camera, viewportDataSource)
122
+ routeLineApi = MapboxRouteLineApi(MapboxRouteLineApiOptions.Builder().build())
123
+ routeLineView = MapboxRouteLineView(MapboxRouteLineViewOptions.Builder(this).build())
124
+ }
125
+
126
+ private val routesObserver = RoutesObserver { routeUpdateResult ->
127
+ if (routeUpdateResult.navigationRoutes.isNotEmpty()) {
128
+ routeLineApi.setNavigationRoutes(routeUpdateResult.navigationRoutes) { value ->
129
+ mapView.mapboxMap.style?.apply { routeLineView.renderRouteDrawData(this, value) }
130
+ }
131
+ viewportDataSource.onRouteChanged(routeUpdateResult.navigationRoutes.first())
132
+ viewportDataSource.evaluate()
133
+ navigationCamera.requestNavigationCameraToOverview()
134
+ }
135
+ }
136
+
137
+ private val locationObserver = object : LocationObserver {
138
+ override fun onNewRawLocation(rawLocation: Location) {}
139
+ override fun onNewLocationMatcherResult(locationMatcherResult: LocationMatcherResult) {
140
+ val enhancedLocation = locationMatcherResult.enhancedLocation
141
+ navigationLocationProvider.changePosition(
142
+ location = enhancedLocation,
143
+ keyPoints = locationMatcherResult.keyPoints,
144
+ )
145
+ viewportDataSource.onLocationChanged(enhancedLocation)
146
+ viewportDataSource.evaluate()
147
+ navigationCamera.requestNavigationCameraToFollowing()
148
+ }
149
+ }
150
+
151
+ @OptIn(ExperimentalPreviewMapboxNavigationAPI::class)
152
+ private val mapboxNavigation: MapboxNavigation by requireMapboxNavigation(
153
+ onResumedObserver = object : MapboxNavigationObserver {
154
+ @SuppressLint("MissingPermission")
155
+ override fun onAttached(mapboxNavigation: MapboxNavigation) {
156
+ mapboxNavigation.registerRoutesObserver(routesObserver)
157
+ mapboxNavigation.registerLocationObserver(locationObserver)
158
+ if (simulateRoute) {
159
+ replayProgressObserver = ReplayProgressObserver(mapboxNavigation.mapboxReplayer)
160
+ mapboxNavigation.registerRouteProgressObserver(replayProgressObserver)
161
+ mapboxNavigation.startReplayTripSession()
162
+ } else {
163
+ mapboxNavigation.startTripSession()
164
+ }
165
+ }
166
+ override fun onDetached(mapboxNavigation: MapboxNavigation) {}
167
+ },
168
+ onInitialize = this::initNavigation
169
+ )
170
+
171
+ @OptIn(ExperimentalPreviewMapboxNavigationAPI::class)
172
+ private fun initNavigation() {
173
+ // MapboxNavigationApp.setup is already called in the plugin implementation
174
+
175
+ mapView.location.apply {
176
+ setLocationProvider(navigationLocationProvider)
177
+ this.locationPuck = createDefault2DPuck()
178
+ enabled = true
179
+ }
180
+
181
+ val origin = Point.fromLngLat(originLng, originLat)
182
+ val destination = Point.fromLngLat(destLng, destLat)
183
+
184
+ mapboxNavigation.requestRoutes(
185
+ RouteOptions.builder()
186
+ .applyDefaultNavigationOptions()
187
+ .coordinatesList(listOf(origin, destination))
188
+ .layersList(listOf(mapboxNavigation.getZLevel(), null))
189
+ .build(),
190
+ object : NavigationRouterCallback {
191
+ override fun onCanceled(routeOptions: RouteOptions, routerOrigin: String) {}
192
+ override fun onFailure(reasons: List<RouterFailure>, routeOptions: RouteOptions) {
193
+ Toast.makeText(this@NavigationActivity, "Route request failed", Toast.LENGTH_SHORT).show()
194
+ }
195
+ override fun onRoutesReady(routes: List<NavigationRoute>, routerOrigin: String) {
196
+ mapboxNavigation.setNavigationRoutes(routes)
197
+ if (simulateRoute) {
198
+ val replayData = replayRouteMapper.mapDirectionsRouteGeometry(routes.first().directionsRoute)
199
+ mapboxNavigation.mapboxReplayer.pushEvents(replayData)
200
+ mapboxNavigation.mapboxReplayer.seekTo(replayData[0])
201
+ mapboxNavigation.mapboxReplayer.play()
202
+ }
203
+ }
204
+ }
205
+ )
206
+ }
207
+ }
@@ -0,0 +1,35 @@
1
+ package com.castelioit.capacitormapboxnav
2
+
3
+ import android.app.Activity
4
+ import android.content.Context
5
+ import android.content.Intent
6
+ import com.getcapacitor.Logger
7
+ import com.mapbox.common.MapboxOptions
8
+ import com.mapbox.navigation.core.lifecycle.MapboxNavigationApp
9
+ import com.mapbox.navigation.base.options.NavigationOptions
10
+
11
+ class capacitormapboxnav {
12
+
13
+ fun echo(value: String): String {
14
+ Logger.info("Echo", value)
15
+ return value
16
+ }
17
+
18
+ fun initialize(context: Context, accessToken: String) {
19
+ MapboxOptions.accessToken = accessToken
20
+ if (!MapboxNavigationApp.isSetup()) {
21
+ MapboxNavigationApp.setup(NavigationOptions.Builder(context).build())
22
+ }
23
+ }
24
+
25
+ fun startNavigation(activity: Activity, originLat: Double, originLng: Double, destLat: Double, destLng: Double, simulateRoute: Boolean) {
26
+ val intent = Intent(activity, NavigationActivity::class.java).apply {
27
+ putExtra("originLat", originLat)
28
+ putExtra("originLng", originLng)
29
+ putExtra("destLat", destLat)
30
+ putExtra("destLng", destLng)
31
+ putExtra("simulateRoute", simulateRoute)
32
+ }
33
+ activity.startActivity(intent)
34
+ }
35
+ }
@@ -0,0 +1,58 @@
1
+ package com.castelioit.capacitormapboxnav;
2
+
3
+ import com.getcapacitor.JSObject;
4
+ import com.getcapacitor.Plugin;
5
+ import com.getcapacitor.PluginCall;
6
+ import com.getcapacitor.PluginMethod;
7
+ import com.getcapacitor.annotation.CapacitorPlugin;
8
+
9
+ @CapacitorPlugin(name = "capacitormapboxnav")
10
+ public class capacitormapboxnavPlugin extends Plugin {
11
+
12
+ private capacitormapboxnav implementation = new capacitormapboxnav();
13
+
14
+ @PluginMethod
15
+ public void echo(PluginCall call) {
16
+ String value = call.getString("value");
17
+
18
+ JSObject ret = new JSObject();
19
+ ret.put("value", implementation.echo(value));
20
+ call.resolve(ret);
21
+ }
22
+
23
+ @PluginMethod
24
+ public void initialize(PluginCall call) {
25
+ String accessToken = call.getString("accessToken");
26
+ if (accessToken == null) {
27
+ call.reject("AccessToken is required");
28
+ return;
29
+ }
30
+ implementation.initialize(getContext(), accessToken);
31
+ call.resolve();
32
+ }
33
+
34
+ @PluginMethod
35
+ public void startNavigation(PluginCall call) {
36
+ JSObject origin = call.getObject("origin");
37
+ JSObject destination = call.getObject("destination");
38
+ Boolean simulateRoute = call.getBoolean("simulateRoute", false);
39
+
40
+ if (origin == null || destination == null) {
41
+ call.reject("Origin and destination are required");
42
+ return;
43
+ }
44
+
45
+ Double originLat = origin.getDouble("latitude");
46
+ Double originLng = origin.getDouble("longitude");
47
+ Double destLat = destination.getDouble("latitude");
48
+ Double destLng = destination.getDouble("longitude");
49
+
50
+ if (originLat == null || originLng == null || destLat == null || destLng == null) {
51
+ call.reject("Invalid origin or destination coordinates");
52
+ return;
53
+ }
54
+
55
+ implementation.startNavigation(getActivity(), originLat, originLng, destLat, destLng, simulateRoute);
56
+ call.resolve();
57
+ }
58
+ }
File without changes
package/dist/docs.json ADDED
@@ -0,0 +1,63 @@
1
+ {
2
+ "api": {
3
+ "name": "capacitormapboxnavPlugin",
4
+ "slug": "capacitormapboxnavplugin",
5
+ "docs": "",
6
+ "tags": [],
7
+ "methods": [
8
+ {
9
+ "name": "echo",
10
+ "signature": "(options: { value: string; }) => Promise<{ value: string; }>",
11
+ "parameters": [
12
+ {
13
+ "name": "options",
14
+ "docs": "",
15
+ "type": "{ value: string; }"
16
+ }
17
+ ],
18
+ "returns": "Promise<{ value: string; }>",
19
+ "tags": [],
20
+ "docs": "",
21
+ "complexTypes": [],
22
+ "slug": "echo"
23
+ },
24
+ {
25
+ "name": "initialize",
26
+ "signature": "(options: { accessToken: string; }) => Promise<void>",
27
+ "parameters": [
28
+ {
29
+ "name": "options",
30
+ "docs": "",
31
+ "type": "{ accessToken: string; }"
32
+ }
33
+ ],
34
+ "returns": "Promise<void>",
35
+ "tags": [],
36
+ "docs": "",
37
+ "complexTypes": [],
38
+ "slug": "initialize"
39
+ },
40
+ {
41
+ "name": "startNavigation",
42
+ "signature": "(options: { origin: { latitude: number; longitude: number; }; destination: { latitude: number; longitude: number; }; simulateRoute?: boolean; }) => Promise<void>",
43
+ "parameters": [
44
+ {
45
+ "name": "options",
46
+ "docs": "",
47
+ "type": "{ origin: { latitude: number; longitude: number; }; destination: { latitude: number; longitude: number; }; simulateRoute?: boolean | undefined; }"
48
+ }
49
+ ],
50
+ "returns": "Promise<void>",
51
+ "tags": [],
52
+ "docs": "",
53
+ "complexTypes": [],
54
+ "slug": "startnavigation"
55
+ }
56
+ ],
57
+ "properties": []
58
+ },
59
+ "interfaces": [],
60
+ "enums": [],
61
+ "typeAliases": [],
62
+ "pluginConfigs": []
63
+ }
@@ -0,0 +1,21 @@
1
+ export interface capacitormapboxnavPlugin {
2
+ echo(options: {
3
+ value: string;
4
+ }): Promise<{
5
+ value: string;
6
+ }>;
7
+ initialize(options: {
8
+ accessToken: string;
9
+ }): Promise<void>;
10
+ startNavigation(options: {
11
+ origin: {
12
+ latitude: number;
13
+ longitude: number;
14
+ };
15
+ destination: {
16
+ latitude: number;
17
+ longitude: number;
18
+ };
19
+ simulateRoute?: boolean;
20
+ }): Promise<void>;
21
+ }
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=definitions.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"definitions.js","sourceRoot":"","sources":["../../src/definitions.ts"],"names":[],"mappings":"","sourcesContent":["export interface capacitormapboxnavPlugin {\n echo(options: { value: string }): Promise<{ value: string }>;\n initialize(options: { accessToken: string }): Promise<void>;\n startNavigation(options: {\n origin: { latitude: number, longitude: number };\n destination: { latitude: number, longitude: number };\n simulateRoute?: boolean;\n }): Promise<void>;\n}\n"]}
@@ -0,0 +1,4 @@
1
+ import type { capacitormapboxnavPlugin } from './definitions';
2
+ declare const capacitormapboxnav: capacitormapboxnavPlugin;
3
+ export * from './definitions';
4
+ export { capacitormapboxnav };
@@ -0,0 +1,7 @@
1
+ import { registerPlugin } from '@capacitor/core';
2
+ const capacitormapboxnav = registerPlugin('capacitormapboxnav', {
3
+ web: () => import('./web').then((m) => new m.capacitormapboxnavWeb()),
4
+ });
5
+ export * from './definitions';
6
+ export { capacitormapboxnav };
7
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AAIjD,MAAM,kBAAkB,GAAG,cAAc,CAA2B,oBAAoB,EAAE;IACxF,GAAG,EAAE,GAAG,EAAE,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,IAAI,CAAC,CAAC,qBAAqB,EAAE,CAAC;CACtE,CAAC,CAAC;AAEH,cAAc,eAAe,CAAC;AAC9B,OAAO,EAAE,kBAAkB,EAAE,CAAC","sourcesContent":["import { registerPlugin } from '@capacitor/core';\n\nimport type { capacitormapboxnavPlugin } from './definitions';\n\nconst capacitormapboxnav = registerPlugin<capacitormapboxnavPlugin>('capacitormapboxnav', {\n web: () => import('./web').then((m) => new m.capacitormapboxnavWeb()),\n});\n\nexport * from './definitions';\nexport { capacitormapboxnav };\n"]}
@@ -0,0 +1,23 @@
1
+ import { WebPlugin } from '@capacitor/core';
2
+ import type { capacitormapboxnavPlugin } from './definitions';
3
+ export declare class capacitormapboxnavWeb extends WebPlugin implements capacitormapboxnavPlugin {
4
+ echo(options: {
5
+ value: string;
6
+ }): Promise<{
7
+ value: string;
8
+ }>;
9
+ initialize(options: {
10
+ accessToken: string;
11
+ }): Promise<void>;
12
+ startNavigation(options: {
13
+ origin: {
14
+ latitude: number;
15
+ longitude: number;
16
+ };
17
+ destination: {
18
+ latitude: number;
19
+ longitude: number;
20
+ };
21
+ simulateRoute?: boolean;
22
+ }): Promise<void>;
23
+ }
@@ -0,0 +1,14 @@
1
+ import { WebPlugin } from '@capacitor/core';
2
+ export class capacitormapboxnavWeb extends WebPlugin {
3
+ async echo(options) {
4
+ console.log('ECHO', options);
5
+ return options;
6
+ }
7
+ async initialize(options) {
8
+ console.log('INITIALIZE', options);
9
+ }
10
+ async startNavigation(options) {
11
+ console.log('START_NAVIGATION', options);
12
+ }
13
+ }
14
+ //# sourceMappingURL=web.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"web.js","sourceRoot":"","sources":["../../src/web.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAI5C,MAAM,OAAO,qBAAsB,SAAQ,SAAS;IAClD,KAAK,CAAC,IAAI,CAAC,OAA0B;QACnC,OAAO,CAAC,GAAG,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;QAC7B,OAAO,OAAO,CAAC;IACjB,CAAC;IAED,KAAK,CAAC,UAAU,CAAC,OAAgC;QAC/C,OAAO,CAAC,GAAG,CAAC,YAAY,EAAE,OAAO,CAAC,CAAC;IACrC,CAAC;IAED,KAAK,CAAC,eAAe,CAAC,OAIrB;QACC,OAAO,CAAC,GAAG,CAAC,kBAAkB,EAAE,OAAO,CAAC,CAAC;IAC3C,CAAC;CACF","sourcesContent":["import { WebPlugin } from '@capacitor/core';\n\nimport type { capacitormapboxnavPlugin } from './definitions';\n\nexport class capacitormapboxnavWeb extends WebPlugin implements capacitormapboxnavPlugin {\n async echo(options: { value: string }): Promise<{ value: string }> {\n console.log('ECHO', options);\n return options;\n }\n\n async initialize(options: { accessToken: string }): Promise<void> {\n console.log('INITIALIZE', options);\n }\n\n async startNavigation(options: {\n origin: { latitude: number, longitude: number };\n destination: { latitude: number, longitude: number };\n simulateRoute?: boolean;\n }): Promise<void> {\n console.log('START_NAVIGATION', options);\n }\n}\n"]}
@@ -0,0 +1,28 @@
1
+ 'use strict';
2
+
3
+ var core = require('@capacitor/core');
4
+
5
+ const capacitormapboxnav = core.registerPlugin('capacitormapboxnav', {
6
+ web: () => Promise.resolve().then(function () { return web; }).then((m) => new m.capacitormapboxnavWeb()),
7
+ });
8
+
9
+ class capacitormapboxnavWeb extends core.WebPlugin {
10
+ async echo(options) {
11
+ console.log('ECHO', options);
12
+ return options;
13
+ }
14
+ async initialize(options) {
15
+ console.log('INITIALIZE', options);
16
+ }
17
+ async startNavigation(options) {
18
+ console.log('START_NAVIGATION', options);
19
+ }
20
+ }
21
+
22
+ var web = /*#__PURE__*/Object.freeze({
23
+ __proto__: null,
24
+ capacitormapboxnavWeb: capacitormapboxnavWeb
25
+ });
26
+
27
+ exports.capacitormapboxnav = capacitormapboxnav;
28
+ //# sourceMappingURL=plugin.cjs.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"plugin.cjs.js","sources":["esm/index.js","esm/web.js"],"sourcesContent":["import { registerPlugin } from '@capacitor/core';\nconst capacitormapboxnav = registerPlugin('capacitormapboxnav', {\n web: () => import('./web').then((m) => new m.capacitormapboxnavWeb()),\n});\nexport * from './definitions';\nexport { capacitormapboxnav };\n//# sourceMappingURL=index.js.map","import { WebPlugin } from '@capacitor/core';\nexport class capacitormapboxnavWeb extends WebPlugin {\n async echo(options) {\n console.log('ECHO', options);\n return options;\n }\n async initialize(options) {\n console.log('INITIALIZE', options);\n }\n async startNavigation(options) {\n console.log('START_NAVIGATION', options);\n }\n}\n//# sourceMappingURL=web.js.map"],"names":["registerPlugin","WebPlugin"],"mappings":";;;;AACK,MAAC,kBAAkB,GAAGA,mBAAc,CAAC,oBAAoB,EAAE;AAChE,IAAI,GAAG,EAAE,MAAM,mDAAe,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,IAAI,CAAC,CAAC,qBAAqB,EAAE,CAAC;AACzE,CAAC;;ACFM,MAAM,qBAAqB,SAASC,cAAS,CAAC;AACrD,IAAI,MAAM,IAAI,CAAC,OAAO,EAAE;AACxB,QAAQ,OAAO,CAAC,GAAG,CAAC,MAAM,EAAE,OAAO,CAAC;AACpC,QAAQ,OAAO,OAAO;AACtB,IAAI;AACJ,IAAI,MAAM,UAAU,CAAC,OAAO,EAAE;AAC9B,QAAQ,OAAO,CAAC,GAAG,CAAC,YAAY,EAAE,OAAO,CAAC;AAC1C,IAAI;AACJ,IAAI,MAAM,eAAe,CAAC,OAAO,EAAE;AACnC,QAAQ,OAAO,CAAC,GAAG,CAAC,kBAAkB,EAAE,OAAO,CAAC;AAChD,IAAI;AACJ;;;;;;;;;"}
package/dist/plugin.js ADDED
@@ -0,0 +1,31 @@
1
+ var capacitorcapacitormapboxnav = (function (exports, core) {
2
+ 'use strict';
3
+
4
+ const capacitormapboxnav = core.registerPlugin('capacitormapboxnav', {
5
+ web: () => Promise.resolve().then(function () { return web; }).then((m) => new m.capacitormapboxnavWeb()),
6
+ });
7
+
8
+ class capacitormapboxnavWeb extends core.WebPlugin {
9
+ async echo(options) {
10
+ console.log('ECHO', options);
11
+ return options;
12
+ }
13
+ async initialize(options) {
14
+ console.log('INITIALIZE', options);
15
+ }
16
+ async startNavigation(options) {
17
+ console.log('START_NAVIGATION', options);
18
+ }
19
+ }
20
+
21
+ var web = /*#__PURE__*/Object.freeze({
22
+ __proto__: null,
23
+ capacitormapboxnavWeb: capacitormapboxnavWeb
24
+ });
25
+
26
+ exports.capacitormapboxnav = capacitormapboxnav;
27
+
28
+ return exports;
29
+
30
+ })({}, capacitorExports);
31
+ //# sourceMappingURL=plugin.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"plugin.js","sources":["esm/index.js","esm/web.js"],"sourcesContent":["import { registerPlugin } from '@capacitor/core';\nconst capacitormapboxnav = registerPlugin('capacitormapboxnav', {\n web: () => import('./web').then((m) => new m.capacitormapboxnavWeb()),\n});\nexport * from './definitions';\nexport { capacitormapboxnav };\n//# sourceMappingURL=index.js.map","import { WebPlugin } from '@capacitor/core';\nexport class capacitormapboxnavWeb extends WebPlugin {\n async echo(options) {\n console.log('ECHO', options);\n return options;\n }\n async initialize(options) {\n console.log('INITIALIZE', options);\n }\n async startNavigation(options) {\n console.log('START_NAVIGATION', options);\n }\n}\n//# sourceMappingURL=web.js.map"],"names":["registerPlugin","WebPlugin"],"mappings":";;;AACK,UAAC,kBAAkB,GAAGA,mBAAc,CAAC,oBAAoB,EAAE;IAChE,IAAI,GAAG,EAAE,MAAM,mDAAe,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,IAAI,CAAC,CAAC,qBAAqB,EAAE,CAAC;IACzE,CAAC;;ICFM,MAAM,qBAAqB,SAASC,cAAS,CAAC;IACrD,IAAI,MAAM,IAAI,CAAC,OAAO,EAAE;IACxB,QAAQ,OAAO,CAAC,GAAG,CAAC,MAAM,EAAE,OAAO,CAAC;IACpC,QAAQ,OAAO,OAAO;IACtB,IAAI;IACJ,IAAI,MAAM,UAAU,CAAC,OAAO,EAAE;IAC9B,QAAQ,OAAO,CAAC,GAAG,CAAC,YAAY,EAAE,OAAO,CAAC;IAC1C,IAAI;IACJ,IAAI,MAAM,eAAe,CAAC,OAAO,EAAE;IACnC,QAAQ,OAAO,CAAC,GAAG,CAAC,kBAAkB,EAAE,OAAO,CAAC;IAChD,IAAI;IACJ;;;;;;;;;;;;;;;"}
@@ -0,0 +1,8 @@
1
+ import Foundation
2
+
3
+ @objc public class capacitormapboxnav: NSObject {
4
+ @objc public func echo(_ value: String) -> String {
5
+ print(value)
6
+ return value
7
+ }
8
+ }
@@ -0,0 +1,33 @@
1
+ import Foundation
2
+ import Capacitor
3
+
4
+ /**
5
+ * Please read the Capacitor iOS Plugin Development Guide
6
+ * here: https://capacitorjs.com/docs/plugins/ios
7
+ */
8
+ @objc(capacitormapboxnavPlugin)
9
+ public class capacitormapboxnavPlugin: CAPPlugin, CAPBridgedPlugin {
10
+ public let identifier = "capacitormapboxnavPlugin"
11
+ public let jsName = "capacitormapboxnav"
12
+ public let pluginMethods: [CAPPluginMethod] = [
13
+ CAPPluginMethod(name: "echo", returnType: CAPPluginReturnPromise),
14
+ CAPPluginMethod(name: "initialize", returnType: CAPPluginReturnPromise),
15
+ CAPPluginMethod(name: "startNavigation", returnType: CAPPluginReturnPromise)
16
+ ]
17
+ private let implementation = capacitormapboxnav()
18
+
19
+ @objc func echo(_ call: CAPPluginCall) {
20
+ let value = call.getString("value") ?? ""
21
+ call.resolve([
22
+ "value": implementation.echo(value)
23
+ ])
24
+ }
25
+
26
+ @objc func initialize(_ call: CAPPluginCall) {
27
+ call.reject("Not implemented on iOS yet")
28
+ }
29
+
30
+ @objc func startNavigation(_ call: CAPPluginCall) {
31
+ call.reject("Not implemented on iOS yet")
32
+ }
33
+ }
@@ -0,0 +1,15 @@
1
+ import XCTest
2
+ @testable import capacitormapboxnavPlugin
3
+
4
+ class capacitormapboxnavTests: XCTestCase {
5
+ func testEcho() {
6
+ // This is an example of a functional test case for a plugin.
7
+ // Use XCTAssert and related functions to verify your tests produce the correct results.
8
+
9
+ let implementation = capacitormapboxnav()
10
+ let value = "Hello, World!"
11
+ let result = implementation.echo(value)
12
+
13
+ XCTAssertEqual(value, result)
14
+ }
15
+ }
package/package.json ADDED
@@ -0,0 +1,80 @@
1
+ {
2
+ "name": "capacitor-mapboxnav",
3
+ "version": "0.0.1",
4
+ "description": "capacitor mapbox navigation ndk",
5
+ "main": "dist/plugin.cjs.js",
6
+ "module": "dist/esm/index.js",
7
+ "types": "dist/esm/index.d.ts",
8
+ "unpkg": "dist/plugin.js",
9
+ "files": [
10
+ "android/src/main/",
11
+ "android/build.gradle",
12
+ "dist/",
13
+ "ios/Sources",
14
+ "ios/Tests",
15
+ "Package.swift",
16
+ "CapacitorMapboxnav.podspec"
17
+ ],
18
+ "author": "castelioit",
19
+ "license": "MIT",
20
+ "repository": {
21
+ "type": "git",
22
+ "url": "git+https://github.com/castelioit/capacitor-mapboxnav.git"
23
+ },
24
+ "bugs": {
25
+ "url": "https://github.com/castelioit/capacitor-mapboxnav/issues"
26
+ },
27
+ "keywords": [
28
+ "capacitor",
29
+ "plugin",
30
+ "native"
31
+ ],
32
+ "scripts": {
33
+ "verify": "npm run verify:ios && npm run verify:android && npm run verify:web",
34
+ "verify:ios": "xcodebuild -scheme CapacitorMapboxnav -destination generic/platform=iOS",
35
+ "verify:android": "cd android && ./gradlew clean build test && cd ..",
36
+ "verify:web": "npm run build",
37
+ "lint": "npm run eslint && npm run prettier -- --check && npm run swiftlint -- lint",
38
+ "fmt": "npm run eslint -- --fix && npm run prettier -- --write && npm run swiftlint -- --fix --format",
39
+ "eslint": "eslint . --ext ts",
40
+ "prettier": "prettier \"**/*.{css,html,ts,js,java}\" --plugin=prettier-plugin-java",
41
+ "swiftlint": "node-swiftlint",
42
+ "docgen": "docgen --api capacitormapboxnavPlugin --output-readme README.md --output-json dist/docs.json",
43
+ "build": "npm run clean && npm run docgen && tsc && rollup -c rollup.config.mjs",
44
+ "clean": "rimraf ./dist",
45
+ "watch": "tsc --watch",
46
+ "prepublishOnly": "npm run build"
47
+ },
48
+ "devDependencies": {
49
+ "@capacitor/android": "^8.0.0",
50
+ "@capacitor/core": "^8.0.0",
51
+ "@capacitor/docgen": "^0.3.1",
52
+ "@capacitor/ios": "^8.0.0",
53
+ "@ionic/eslint-config": "^0.4.0",
54
+ "@ionic/prettier-config": "^4.0.0",
55
+ "@ionic/swiftlint-config": "^2.0.0",
56
+ "eslint": "^8.57.1",
57
+ "prettier": "^3.6.2",
58
+ "prettier-plugin-java": "^2.7.7",
59
+ "rimraf": "^6.1.0",
60
+ "rollup": "^4.53.2",
61
+ "swiftlint": "^2.0.0",
62
+ "typescript": "^5.9.3"
63
+ },
64
+ "peerDependencies": {
65
+ "@capacitor/core": ">=8.0.0"
66
+ },
67
+ "prettier": "@ionic/prettier-config",
68
+ "swiftlint": "@ionic/swiftlint-config",
69
+ "eslintConfig": {
70
+ "extends": "@ionic/eslint-config/recommended"
71
+ },
72
+ "capacitor": {
73
+ "ios": {
74
+ "src": "ios"
75
+ },
76
+ "android": {
77
+ "src": "android"
78
+ }
79
+ }
80
+ }