capacitor-mapboxnav 0.0.2 → 1.0.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.
@@ -1,17 +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
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 CHANGED
@@ -1,28 +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
- ]
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
28
  )
package/README.md CHANGED
@@ -1,48 +1,48 @@
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
-
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 bun
14
+
15
+ ```bash
16
+ bun 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
38
  <docgen-index>
39
39
 
40
40
  * [`echo(...)`](#echo)
41
41
  * [`initialize(...)`](#initialize)
42
42
  * [`startNavigation(...)`](#startnavigation)
43
43
 
44
- </docgen-index>
45
-
44
+ </docgen-index>
45
+
46
46
  <docgen-api>
47
47
  <!--Update the source file JSDoc comments and rerun docgen to update the docs below-->
48
48
 
@@ -86,22 +86,22 @@ startNavigation(options: { origin: { latitude: number; longitude: number; }; des
86
86
 
87
87
  --------------------
88
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
- ```
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
+ ```
@@ -1,86 +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.findProperty("MAPBOX_DOWNLOADS_TOKEN") ?: System.getenv("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
- }
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.findProperty("MAPBOX_DOWNLOADS_TOKEN") ?: System.getenv("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.20.0"
82
+ implementation "com.mapbox.navigationcore:ui-maps:3.20.0"
83
+ implementation "com.mapbox.navigationcore:ui-components:3.20.0"
84
+ implementation "com.mapbox.navigationcore:tripdata:3.20.0"
85
+ implementation "com.mapbox.navigationcore:voice:3.20.0"
86
+ }
@@ -1,16 +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>
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>
@@ -70,8 +70,17 @@ class NavigationActivity : AppCompatActivity() {
70
70
  destLng = intent.getDoubleExtra("destLng", 0.0)
71
71
  simulateRoute = intent.getBooleanExtra("simulateRoute", false)
72
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)
73
+ val permissions = mutableListOf(Manifest.permission.ACCESS_FINE_LOCATION)
74
+ if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.TIRAMISU) {
75
+ permissions.add(Manifest.permission.POST_NOTIFICATIONS)
76
+ }
77
+
78
+ val missingPermissions = permissions.filter {
79
+ ActivityCompat.checkSelfPermission(this, it) != PackageManager.PERMISSION_GRANTED
80
+ }
81
+
82
+ if (missingPermissions.isNotEmpty()) {
83
+ ActivityCompat.requestPermissions(this, missingPermissions.toTypedArray(), 1)
75
84
  } else {
76
85
  initializeMapComponents()
77
86
  }
@@ -79,11 +88,14 @@ class NavigationActivity : AppCompatActivity() {
79
88
 
80
89
  override fun onRequestPermissionsResult(requestCode: Int, permissions: Array<out String>, grantResults: IntArray) {
81
90
  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()
91
+ if (requestCode == 1) {
92
+ val allGranted = grantResults.all { it == PackageManager.PERMISSION_GRANTED }
93
+ if (allGranted) {
94
+ initializeMapComponents()
95
+ } else {
96
+ Toast.makeText(this, "Permissions denied. Navigation cannot start.", Toast.LENGTH_SHORT).show()
97
+ finish()
98
+ }
87
99
  }
88
100
  }
89
101
 
@@ -123,6 +135,37 @@ class NavigationActivity : AppCompatActivity() {
123
135
  routeLineView = MapboxRouteLineView(MapboxRouteLineViewOptions.Builder(this).build())
124
136
  }
125
137
 
138
+ override fun onStart() {
139
+ super.onStart()
140
+ if (::mapView.isInitialized) {
141
+ mapView.onStart()
142
+ }
143
+ }
144
+
145
+ override fun onStop() {
146
+ super.onStop()
147
+ if (::mapView.isInitialized) {
148
+ mapView.onStop()
149
+ }
150
+ }
151
+
152
+ override fun onDestroy() {
153
+ super.onDestroy()
154
+ if (::mapView.isInitialized) {
155
+ mapView.onDestroy()
156
+ }
157
+ if (::routeLineApi.isInitialized) {
158
+ routeLineApi.cancel()
159
+ }
160
+ }
161
+
162
+ override fun onLowMemory() {
163
+ super.onLowMemory()
164
+ if (::mapView.isInitialized) {
165
+ mapView.onLowMemory()
166
+ }
167
+ }
168
+
126
169
  private val routesObserver = RoutesObserver { routeUpdateResult ->
127
170
  if (routeUpdateResult.navigationRoutes.isNotEmpty()) {
128
171
  routeLineApi.setNavigationRoutes(routeUpdateResult.navigationRoutes) { value ->
@@ -163,7 +206,16 @@ class NavigationActivity : AppCompatActivity() {
163
206
  mapboxNavigation.startTripSession()
164
207
  }
165
208
  }
166
- override fun onDetached(mapboxNavigation: MapboxNavigation) {}
209
+ override fun onDetached(mapboxNavigation: MapboxNavigation) {
210
+ mapboxNavigation.unregisterRoutesObserver(routesObserver)
211
+ mapboxNavigation.unregisterLocationObserver(locationObserver)
212
+ if (simulateRoute && ::replayProgressObserver.isInitialized) {
213
+ mapboxNavigation.unregisterRouteProgressObserver(replayProgressObserver)
214
+ mapboxNavigation.stopReplayTripSession()
215
+ } else {
216
+ mapboxNavigation.stopTripSession()
217
+ }
218
+ }
167
219
  },
168
220
  onInitialize = this::initNavigation
169
221
  )
@@ -193,6 +245,10 @@ class NavigationActivity : AppCompatActivity() {
193
245
  Toast.makeText(this@NavigationActivity, "Route request failed", Toast.LENGTH_SHORT).show()
194
246
  }
195
247
  override fun onRoutesReady(routes: List<NavigationRoute>, routerOrigin: String) {
248
+ if (routes.isEmpty()) {
249
+ Toast.makeText(this@NavigationActivity, "No routes found", Toast.LENGTH_SHORT).show()
250
+ return
251
+ }
196
252
  mapboxNavigation.setNavigationRoutes(routes)
197
253
  if (simulateRoute) {
198
254
  val replayData = replayRouteMapper.mapDirectionsRouteGeometry(routes.first().directionsRoute)
@@ -1,70 +1,85 @@
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
- getActivity().runOnUiThread(() -> {
31
- try {
32
- implementation.initialize(getContext(), accessToken);
33
- call.resolve();
34
- } catch (Exception e) {
35
- call.reject("Initialization failed: " + e.getMessage());
36
- }
37
- });
38
- }
39
-
40
- @PluginMethod
41
- public void startNavigation(PluginCall call) {
42
- JSObject origin = call.getObject("origin");
43
- JSObject destination = call.getObject("destination");
44
- Boolean simulateRoute = call.getBoolean("simulateRoute", false);
45
-
46
- if (origin == null || destination == null) {
47
- call.reject("Origin and destination are required");
48
- return;
49
- }
50
-
51
- Double originLat = origin.getDouble("latitude");
52
- Double originLng = origin.getDouble("longitude");
53
- Double destLat = destination.getDouble("latitude");
54
- Double destLng = destination.getDouble("longitude");
55
-
56
- if (originLat == null || originLng == null || destLat == null || destLng == null) {
57
- call.reject("Invalid origin or destination coordinates");
58
- return;
59
- }
60
-
61
- getActivity().runOnUiThread(() -> {
62
- try {
63
- implementation.startNavigation(getActivity(), originLat, originLng, destLat, destLng, simulateRoute);
64
- call.resolve();
65
- } catch (Exception e) {
66
- call.reject("Failed to start navigation: " + e.getMessage());
67
- }
68
- });
69
- }
70
- }
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
+ import org.json.JSONException;
9
+
10
+ @CapacitorPlugin(name = "capacitormapboxnav")
11
+ public class capacitormapboxnavPlugin extends Plugin {
12
+
13
+ private capacitormapboxnav implementation = new capacitormapboxnav();
14
+
15
+ @PluginMethod
16
+ public void echo(PluginCall call) {
17
+ String value = call.getString("value");
18
+
19
+ JSObject ret = new JSObject();
20
+ ret.put("value", implementation.echo(value));
21
+ call.resolve(ret);
22
+ }
23
+
24
+ @PluginMethod
25
+ public void initialize(PluginCall call) {
26
+ String accessToken = call.getString("accessToken");
27
+ if (accessToken == null) {
28
+ call.reject("AccessToken is required");
29
+ return;
30
+ }
31
+ getActivity().runOnUiThread(() -> {
32
+ try {
33
+ implementation.initialize(getContext(), accessToken);
34
+ call.resolve();
35
+ } catch (Exception e) {
36
+ call.reject("Initialization failed: " + e.getMessage());
37
+ }
38
+ });
39
+ }
40
+
41
+ @PluginMethod
42
+ public void startNavigation(PluginCall call) throws JSONException {
43
+ JSObject origin = call.getObject("origin");
44
+ JSObject destination = call.getObject("destination");
45
+ Boolean simulateRoute = call.getBoolean("simulateRoute", false);
46
+
47
+ if (origin == null || destination == null) {
48
+ call.reject("Origin and destination are required");
49
+ return;
50
+ }
51
+
52
+ Double originLat = origin.getDouble("latitude");
53
+ Double originLng = origin.getDouble("longitude");
54
+ Double destLat = destination.getDouble("latitude");
55
+ Double destLng = destination.getDouble("longitude");
56
+
57
+ if (originLat == null || originLng == null || destLat == null || destLng == null) {
58
+ call.reject("Invalid origin or destination coordinates");
59
+ return;
60
+ }
61
+
62
+ if (
63
+ originLat < -90 ||
64
+ originLat > 90 ||
65
+ originLng < -180 ||
66
+ originLng > 180 ||
67
+ destLat < -90 ||
68
+ destLat > 90 ||
69
+ destLng < -180 ||
70
+ destLng > 180
71
+ ) {
72
+ call.reject("Coordinates out of range");
73
+ return;
74
+ }
75
+
76
+ getActivity().runOnUiThread(() -> {
77
+ try {
78
+ implementation.startNavigation((Activity) getActivity(), originLat, originLng, destLat, destLng, simulateRoute);
79
+ call.resolve();
80
+ } catch (Exception e) {
81
+ call.reject("Failed to start navigation: " + e.getMessage());
82
+ }
83
+ });
84
+ }
85
+ }
@@ -1 +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"]}
1
+ {"version":3,"file":"definitions.js","sourceRoot":"","sources":["../../src/definitions.ts"],"names":[],"mappings":"","sourcesContent":["export interface capacitormapboxnavPlugin {\r\n echo(options: { value: string }): Promise<{ value: string }>;\r\n initialize(options: { accessToken: string }): Promise<void>;\r\n startNavigation(options: {\r\n origin: { latitude: number; longitude: number };\r\n destination: { latitude: number; longitude: number };\r\n simulateRoute?: boolean;\r\n }): Promise<void>;\r\n}\r\n"]}
@@ -1 +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"]}
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';\r\n\r\nimport type { capacitormapboxnavPlugin } from './definitions';\r\n\r\nconst capacitormapboxnav = registerPlugin<capacitormapboxnavPlugin>('capacitormapboxnav', {\r\n web: () => import('./web').then((m) => new m.capacitormapboxnavWeb()),\r\n});\r\n\r\nexport * from './definitions';\r\nexport { capacitormapboxnav };\r\n"]}
@@ -1 +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"]}
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';\r\n\r\nimport type { capacitormapboxnavPlugin } from './definitions';\r\n\r\nexport class capacitormapboxnavWeb extends WebPlugin implements capacitormapboxnavPlugin {\r\n async echo(options: { value: string }): Promise<{ value: string }> {\r\n console.log('ECHO', options);\r\n return options;\r\n }\r\n\r\n async initialize(options: { accessToken: string }): Promise<void> {\r\n console.log('INITIALIZE', options);\r\n }\r\n\r\n async startNavigation(options: {\r\n origin: { latitude: number; longitude: number };\r\n destination: { latitude: number; longitude: number };\r\n simulateRoute?: boolean;\r\n }): Promise<void> {\r\n console.log('START_NAVIGATION', options);\r\n }\r\n}\r\n"]}
@@ -1,8 +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
- }
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
+ }
@@ -1,33 +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
- }
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("initialize() is not implemented on iOS yet. Only Android is supported at this time.")
28
+ }
29
+
30
+ @objc func startNavigation(_ call: CAPPluginCall) {
31
+ call.reject("startNavigation() is not implemented on iOS yet. Only Android is supported at this time.")
32
+ }
33
+ }
@@ -1,15 +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
- }
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 CHANGED
@@ -1,80 +1,80 @@
1
- {
2
- "name": "capacitor-mapboxnav",
3
- "version": "0.0.2",
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
- }
1
+ {
2
+ "name": "capacitor-mapboxnav",
3
+ "version": "1.0.0",
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
+ }