3.1.14 • Published 2 years ago

cordova-plugin-navitia-sdk-ui v3.1.14

Weekly downloads
16
License
GPL-3.0
Repository
github
Last release
2 years ago

Journey for Cordova

npm version License: GPL v3

Cordova plugin for using Journey. This plugin uses the native SDK Android and iOS.

Actually, it's not possible to use Journey for Cordova with a Tab Bar (iOS) or a Bottom Navigation (Android)

Requirements

This plugin uses native SDKs. Since those SDKs are private, you will need to get access credentials to our artifactory. This plugin uses Cocoapods to manage dependencies for iOS, please install it first: https://cocoapods.org.

Credentials configuration

Once you have credentials to access our artifactory, one further step is required before installing the plugin. Please follow one of these steps to configure the credentials properly. The <YOUR_ARTIFACTORY_USERNAME> and <YOUR_ARTIFACTORY_PASSWORD> should be replaced with your username and password!

Using Config.xml preferences

In the Config.xml file of your project, add these lines:

<widget>
	.
	.
	<preference name="KISIO_ARTIFACTORY_USERNAME" value="<YOUR_ARTIFACTORY_USERNAME>" />
    	<preference name="KISIO_ARTIFACTORY_PASSWORD" value="<YOUR_ARTIFACTORY_PASSWORD>" />
</widget>

Using environment variables

Define two global environment variables as follows:

KISIO_ARTIFACTORY_USERNAME=<YOUR_ARTIFACTORY_USERNAME>
KISIO_ARTIFACTORY_PASSWORD=<YOUR_ARTIFACTORY_PASSWORD>

Using global properties files (MacOS users only)

iOS

In the Home directory, open .netrc file (if not found, create a new file) and add this line:

machine kisiodigital.jfrog.io login <YOUR_ARTIFACTORY_USERNAME> password <YOUR_ARTIFACTORY_PASSWORD>
Android

In the ~/.gradle directory, open gradle.propertiesfile (if not found, create a new file) andd these lines:

kisio_artifactory_username=<YOUR_ARTIFACTORY_USERNAME>
kisio_artifactory_password=<YOUR_ARTIFACTORY_PASSWORD>

Installation

Use this command to install the plugin cordova plugin add cordova-plugin-navitia-sdk-ui

Setup for Android platform

This plugin uses Google Maps and requires a Google API key in case you're targeting the Android platform with your cordova application. You can get your own API key using this link: https://developers.google.com/maps/documentation/android-api/signup

You need to update your config.xml file as follows:

<widget ......... xmlns:android="http://schemas.android.com/apk/res/android">
    .
    .
    <platform name="android">
        .
        .
        <config-file parent="/manifest/application" target="AndroidManifest.xml">
            <meta-data android:name="com.google.android.geo.API_KEY" android:value="YOUR_API_KEY" />
        </config-file>
    </platform>
    .
    .
</widget>

Note that you have to change YOUR_API_KEY with your own API key!

Usage

Configuration - NavitiaSDKUI.init(config, success, failure)

ParametersTypeRequiredDescriptionDefault
configObjectConfiguration
config.tokenStringNavitia token (generate a token on navitia.io)
config.coverageStringName of search area
config.environmentStringNavitia environment"PROD"
config.primaryColorStringTo set the main color of the module
config.secondaryColorStringTo set the color of some componentsprimaryColor
config.originColorStringTo set the color of the origin at the roadmap departure bloc
config.originBackgroundColorStringTo set the color of the origin at the roadmap departure blocoriginColor
config.originIconColorStringTo set the color of the origin icontransparent (no color filter)
config.destinationColorStringTo set the color of the destination at the roadmap arrival bloc
config.destinationBackgroundColorStringTo set the color of the destination at the roadmap arrival blocdestinationColor
config.destinationIconColorStringTo set the color of the destination icontransparent (no color filter)
config.isFormEnabledBooleanTo set the display of search formfalse
config.isMultiNetworkEnabledBooleanTo set the display of the network name in the roadmapfalse
config.isEarlierLaterFeatureEnabledBooleanTo set the display of "Earlier" and "Later" buttonsfalse
config.isNextDeparturesFeatureEnabledBooleanTo set the display of next departuresby default false
config.maxHistoryIntTo set the maximum number of autocomplete history inputs10
config.transportModesObjectTo customize the search form
config.disruptionContributorStringTo filter traffic disruptions
config.customTitlesObjectTo set screen titles
successFunctionSuccess callback functionfunction() {}
failureFunctionFailure callback functionfunction(error) {}
Environments

For the supported environments, please check the table below:

EnvironmentValue
Prod"PROD"
Customer"CUSTOMER"
Dev"DEV"
Internal"INTERNAL"
Custom titles

You can customize the screens titles. A string ressource ID is required and should be passed within the CustomTitles Object.

ParametersTypeRequiredDescriptionExample
customTitleObjectCustomTitles
customTitle.formStringTo set the form screen title'form_screen_title'
customTitle.journeysStringTo set the journeys list screen title'journeys_screen_title'
customTitle.roadmapStringTo set the roadmap screen title'roadmap_screen_title'
customTitle.ridesharingStringTo set the ridesharing offers screen title'ridesharing_screen_title'
customTitle.autocompleteStringTo set the autocomplete screen title'autocomplete_screen_title'

Example

var config = {
    environment: 'CUSTOMER',
    token: 'my-token',
    coverage: 'my-coverage',
    backgroundColor: '#e67e22',
    originColor: '#2980b9',
    destinationColor: '#d35400',
};

NavitiaSDKUI.init(config, function() {}, function(error) {
    console.log(error);
});

Example with custom form and custom titles

ParametersTypeRequiredDescriptionExample
Transport ModeObjectConfiguration
transportMode.titleStringTo set the button titleNavitiaSDKUI.TransportModeIcon.METRO
transportMode.typeStringTo set the button type'metro'
transportMode.iconStringTo set the button icon'metro'
transportMode.selectedBooleanTo set the button is selected by defaultfalse
transportMode.firstSectionModeStringTo set mode to use at the begining by the buttonNavitiaSDKUI.SectionMode.WALKING
transportMode.lastSectionModeStringTo set mode to use at the end by the buttonNavitiaSDKUI.SectionMode.WALKING
transportMode.physicalModeStringTo set physical modes use by the button'physical_mode:Metro'
transportMode.realTimeBooleanTo set the display of the availability in real timetrue
var transportModes = [{
      title: 'Metro',
      type: 'metro',
      icon: NavitiaSDKUI.TransportModeIcon.METRO,
      selected: true,
      firstSectionMode: [ NavitiaSDKUI.SectionMode.WALKING ],
      lastSectionMode: [ NavitiaSDKUI.SectionMode.WALKING ],
      physicalMode: ['physical_mode:Metro'],
    },{
      title: 'Bus',
      type: 'bus',
      icon: NavitiaSDKUI.TransportModeIcon.BUS,
      selected: true,
      firstSectionMode: [ NavitiaSDKUI.SectionMode.WALKING ],
      lastSectionMode: [ NavitiaSDKUI.SectionMode.WALKING ],
      physicalMode: ['physical_mode:Bus'],
    },{
      title: 'Train',
      type: 'train',
      icon: NavitiaSDKUI.TransportModeIcon.TRAIN,
      selected: true,
      firstSectionMode: [ NavitiaSDKUI.SectionMode.WALKING ],
      lastSectionMode: [ NavitiaSDKUI.SectionMode.WALKING ],
      physicalMode: ['physical_mode:RapidTransit', 'physical_mode:LocalTrain', 'physical_mode:Train', 'physical_mode:Shuttle'],
    },{
      title: 'Bike',
      type: 'bike',
      icon: NavitiaSDKUI.TransportModeIcon.BIKE,
      selected: false,
      firstSectionMode: [ NavitiaSDKUI.SectionMode.BIKE ],
      lastSectionMode: [ NavitiaSDKUI.SectionMode.BIKE ],
      physicalMode: ['physical_mode:Bike'],
    },{
      title: 'BSS',
      type: 'bss',
      icon: NavitiaSDKUI.TransportModeIcon.BSS,
      selected: false,
      firstSectionMode: [ NavitiaSDKUI.SectionMode.BSS ],
      lastSectionMode: [ NavitiaSDKUI.SectionMode.BSS ],
      physicalMode: ['physical_mode:Bss'],
      realTime: true,
    },{
      title: 'Car',
      type: 'car',
      icon: NavitiaSDKUI.TransportModeIcon.CAR,
      selected: false,
      firstSectionMode: [ NavitiaSDKUI.SectionMode.CAR ],
      lastSectionMode: [ NavitiaSDKUI.SectionMode.CAR ],
      physicalMode: ['physical_mode:Car'],
      realTime: true,
    }];
    
var customTitles = {
     form: "form_screen_title",
     journeys: "journeys_screen_title",
     roadmap: "roadmap_screen_title",
     ridesharing: "ridesharing_screen_title",
     autocomplete: "autocomplete_screen_title"
};

var config = {
    token: 'my-token',
    primaryColor: '#e67e22',
    secondaryColor: '#2980b9',
    destinationColor: '#d35400',
    transportModes: transportModes,
    customTitles: customTitles
};

NavitiaSDKUI.init(config, function() {}, function(error) {
    console.log(error);
});

Journeys request - NavitiaSDKUI.invokeJourneyResults(params, success, failure)

ParametersTypeRequiredDescriptionExample
paramsObjectParameters of the screen
params.originIdStringOrigin coordinates, following the format lon;lat"2.3665844;48.8465337"
params.destinationIdStringDestination coordinates, following the format lon;lat"2.2979169;48.8848719"
params.originLabelStringOrigin label, if not set the address will be displayed"Home"
params.destinationLabelStringDestination label, if not set the address will be displayed"Work"
params.datetimeStringRequested date and time (in UTC Timezone) for journey resultsnew Date().toISOString()
params.datetimeRepresentsStringCan be NavitiaSDKUI.DatetimeRepresents.DEPARTURE (journeys after datetime) or NavitiaSDKUI.DatetimeRepresents.ARRIVAL (journeys before datetime).NavitiaSDKUI.DatetimeRepresents.DEPARTURE
params.travelerTypeStringCan be NavitiaSDKUI.TravelerType.FAST (fast walker), NavitiaSDKUI.TravelerType.STANDARD (standard walker), NavitiaSDKUI.TravelerType.SLOW (slow walker), NavitiaSDKUI.TravelerType.LUGGAGE (traveler with luggage) or NavitiaSDKUI.TravelerType.WHEELCHAIR (traveler on wheelchair).NavitiaSDKUI.TravelerType.STANDARD
params.forbiddenUrisStringUsed to avoid lines, modes, networks, etc in the Journey search (List of navitia uris)'commercial_mode:Bus', 'line:1'
params.allowedIdStringIf you want to use only a small subset of the public transport objects in the Journey search (List of navitia uris)'commercial_mode:Bus', 'line:1'
params.firstSectionModesStringList of modes to use at the begining of the journeyNavitiaSDKUI.SectionMode.CAR, NavitiaSDKUI.SectionMode.RIDESHARING
params.lastSectionModesStringList of modes to use at the end of the journeyNavitiaSDKUI.SectionMode.BIKE, NavitiaSDKUI.SectionMode.BSS
params.countIntegerThe number of journeys that will be displayed3
params.minNbJourneysIntegerThe minimum number of journeys that will be displayed3
params.maxNbJourneysIntegerThe maximum number of journeys that will be displayed10
params.addPoiInfosStringAllow the display of the availability in real time for bike share and car park'bss_stands', 'car_park'
params.directPathStringTo indicate if the journey is direct"only"
params.travelerTypeStringTo indicate the traveler type"slow_walker" or "standard" or "fast_walker" or "luggage" or "wheelchair"
successFunctionSuccess callback functionfunction() {}
failureFunctionFailure callback functionfunction(error) {}

Example

var journeyParams = {
    originId: '2.3665844;48.8465337',
    destinationId: '2.2979169;48.8848719',
    originLabel: 'My Home',
    firstSectionModes: [NavitiaSDKUI.SectionMode.WALKING, NavitiaSDKUI.SectionMode.CAR, NavitiaSDKUI.SectionMode.BIKE, NavitiaSDKUI.SectionMode.BSS, NavitiaSDKUI.SectionMode.RIDESHARING],
    addPoiInfos: ['bss_stand', 'car_park'],
    count: 5,
};

NavitiaSDKUI.invokeJourneyResults(journeyParams, function() {}, function(error) {
    console.log(error);
});
Public transport
var journeyParams = {
    originId: '2.3665844;48.8465337',
    destinationId: '2.2979169;48.8848719',
};
Bike
var journeyParams = {
    originId: '2.3665844;48.8465337',
    destinationId: '2.2979169;48.8848719',
    forbiddenUris: ['physical_mode:Bus', ‘physical_mode:Tramway’, ‘physical_mode:Metro’]
    firstSectionModes: [NavitiaSDKUI.SectionMode.BIKE],
    lastSectionModes: [NavitiaSDKUI.SectionMode.BIKE],
};
BSS
var journeyParams = {
    originId: '2.3665844;48.8465337',
    destinationId: '2.2979169;48.8848719',
    forbiddenUris: ['physical_mode:Bus', ‘physical_mode:Tramway’, ‘physical_mode:Metro’]
    firstSectionModes: [NavitiaSDKUI.SectionMode.BSS],
    lastSectionModes: [NavitiaSDKUI.SectionMode.BSS],
    addPoiInfos: ['bss_stand'],
};
Car
var journeyParams = {
    originId: '2.3665844;48.8465337',
    destinationId: '2.2979169;48.8848719',
    firstSectionModes: [NavitiaSDKUI.SectionMode.CAR],
    addPoiInfos: ['car_park'],
};
Ridesharing
var journeyParams = {
    originId: '2.3665844;48.8465337',
    destinationId: '2.2979169;48.8848719',
    firstSectionModes: [NavitiaSDKUI.SectionMode.RIDESHARING],
    lastSectionModes: [NavitiaSDKUI.SectionMode.RIDESHARING],
};

Colors configuration

Actually, three color parameters can be customized for the SDK. These parameters must be added to the "config" object as indicated in the table above.

Customize icons

Some module icons can be customized using a JSON configuration. Please note that all ressources should be added to the platform main assets/bundle folder.

Transport

Lines
ObjectTypeRequiredDescription
codeStringNavitia line code
icon_resStringIcon ressource name
commercialCommercialNavitia commercial mode
Modes
ObjectTypeRequiredDescription
icon_resStringIcon ressource name
commercialCommercialNavitia commercial mode
Commercial
ObjectTypeRequiredDescription
nameStringCommercial mode name
idStringCommercial mode ID
Providers
ObjectTypeRequiredDescription
idStringNavitia provider ID
icon_resStringIcon ressource name
Example
var transportConfiguration = `{
    "lines": [
      {
        "code": "6",
        "icon_res": "ic_metro_6",
        "commercial": {
          "name": "Métro",
          "id": "commercial_mode:Metro"
        }
      }
    ],
    "modes": [
      {
        "icon_res": "ic_metro",
        "commercial": {
          "name": "Métro",
          "id": "commercial_mode:Metro"
        }
      }
    ],
    "providers": [
        {
          "id": "ridesharing_provider",
          "icon_res": "ic_ridesharing"
        }
    ]
}`

var config = {
    token: 'my-token',
    primaryColor: '#e67e22',
    secondaryColor: '#2980b9',
    destinationColor: '#d35400',
    transportConfiguration: transportConfiguration
};

NavitiaSDKUI.init(config, function() {}, function(error) {
    console.log(error);
});

Troubleshooting

Force gradle wrapper version before build

In terminal, before building :

export CORDOVA_ANDROID_GRADLE_DISTRIBUTION_URL=https://services.gradle.org/distributions/gradle-6.0.1-all.zip

Specific android tools version : 29

In case you are having problems building and getting this kind of problems :

platforms/android/build/intermediates/res/merged/debug/values-v24/values-v24.xml:3: AAPT: Error retrieving parent for item: No resource found that matches the given name ...

You may try to override your android compiler environment variables :

export ORG_GRADLE_PROJECT_cdvCompileSdkVersion=android-28
export ORG_GRADLE_PROJECT_cdvBuildToolsVersion=29.0.0

More information on Cordova website

Manifest merger issue

This usually happens if you change the API key in the config.xml file. The build fails and you're getting this kind of error:

Element meta-data#com.google.android.geo.API_KEY at AndroidManifest.xml:xx:xx-xx duplicated with element declared at AndroidManifest.xml:xx:xx-xx

You may try to remove the Android platform and add it back again.

Android building problem : Cannot read property ‘replace’ of undefined

In the file /platforms/android/cordova/lib/emulator.js, replace :

var num = target.split(’(API level ‘)[1].replace(’)’, ‘’);

By :

var num = target.match(/\d+/)[0];

License

Check out the Cordova plugin License here.

3.1.14

2 years ago

3.1.13

2 years ago

3.1.12

2 years ago

3.1.11

2 years ago

3.1.10

2 years ago

3.1.9

2 years ago

3.1.8

2 years ago

3.1.7

2 years ago

3.1.6

2 years ago

3.1.5

2 years ago

3.1.4

2 years ago

3.1.3

2 years ago

3.1.2

2 years ago

3.1.1

3 years ago

3.1.0

3 years ago

3.0.0

3 years ago

2.8.2

3 years ago

2.8.1

3 years ago

2.8.0

3 years ago

2.7.0

3 years ago

2.6.3

3 years ago

2.6.2

3 years ago

2.6.1

4 years ago

2.6.0

4 years ago

2.4.0

4 years ago

2.3.0

4 years ago

2.2.3

4 years ago

2.2.2

4 years ago

2.2.1

4 years ago

2.2.0

4 years ago

2.1.1

5 years ago

2.1.0

5 years ago

2.0.1

5 years ago

2.0.0

5 years ago

1.9.0

5 years ago

1.8.2

5 years ago

1.8.1

5 years ago

1.8.0

5 years ago

1.7.1

5 years ago

1.7.0

5 years ago

1.6.0

6 years ago

1.5.1

6 years ago

1.5.0

6 years ago

1.4.0

6 years ago

1.3.1

6 years ago

1.3.0

6 years ago

1.2.1

6 years ago

1.2.0

6 years ago