UNPKG

@nativescript-community/ui-carto

Version:
177 lines 7.48 kB
import { mapPosVectorFromArgs, nativeProperty } from '..'; import { BaseRoutingService, RouteMatchingResult, RoutingResult } from './index.common'; import { JSVariantToNative, nativeVariantToJS } from '../utils'; const AKRoutingServiceAdditions = com.akylas.carto.additions.AKRoutingServiceAdditions; export const RoutingAction = { get HEAD_ON() { return com.carto.routing.RoutingAction.ROUTING_ACTION_HEAD_ON; }, get FINISH() { return com.carto.routing.RoutingAction.ROUTING_ACTION_FINISH; }, get NO_TURN() { return com.carto.routing.RoutingAction.ROUTING_ACTION_NO_TURN; }, get GO_STRAIGHT() { return com.carto.routing.RoutingAction.ROUTING_ACTION_GO_STRAIGHT; }, get TURN_RIGHT() { return com.carto.routing.RoutingAction.ROUTING_ACTION_TURN_RIGHT; }, get UTURN() { return com.carto.routing.RoutingAction.ROUTING_ACTION_UTURN; }, get TURN_LEFT() { return com.carto.routing.RoutingAction.ROUTING_ACTION_TURN_LEFT; }, get REACH_VIA_LOCATION() { return com.carto.routing.RoutingAction.ROUTING_ACTION_REACH_VIA_LOCATION; }, get ENTER_ROUNDABOUT() { return com.carto.routing.RoutingAction.ROUTING_ACTION_ENTER_ROUNDABOUT; }, get LEAVE_ROUNDABOUT() { return com.carto.routing.RoutingAction.ROUTING_ACTION_LEAVE_ROUNDABOUT; }, get STAY_ON_ROUNDABOUT() { return com.carto.routing.RoutingAction.ROUTING_ACTION_STAY_ON_ROUNDABOUT; }, get START_AT_END_OF_STREET() { return com.carto.routing.RoutingAction.ROUTING_ACTION_START_AT_END_OF_STREET; }, get ENTER_AGAINST_ALLOWED_DIRECTION() { return com.carto.routing.RoutingAction.ROUTING_ACTION_ENTER_AGAINST_ALLOWED_DIRECTION; }, get LEAVE_AGAINST_ALLOWED_DIRECTION() { return com.carto.routing.RoutingAction.ROUTING_ACTION_LEAVE_AGAINST_ALLOWED_DIRECTION; }, get GO_UP() { return com.carto.routing.RoutingAction.ROUTING_ACTION_GO_UP; }, get GO_DOWN() { return com.carto.routing.RoutingAction.ROUTING_ACTION_GO_DOWN; }, get WAIT() { return com.carto.routing.RoutingAction.ROUTING_ACTION_WAIT; } }; class RoutingService extends BaseRoutingService { calculateRoute(options, profile = this.profile, jsonStr = false) { return new Promise((resolve, reject) => { const nRequest = new com.carto.routing.RoutingRequest(options.projection.getNative(), mapPosVectorFromArgs(options.points)); if (options.customOptions) { Object.keys(options.customOptions).forEach((k) => { nRequest.setCustomParameter(k, JSVariantToNative(options.customOptions[k])); }); } const callback = new com.akylas.carto.additions.RoutingServiceRouteCallback({ onRoutingResult: (err, res, strRes) => (err ? reject(err) : resolve(strRes || (res ? new RoutingResult(res) : null))) }); console.log('calculateRoute', jsonStr); AKRoutingServiceAdditions.calculateRoute(this.getNative(), nRequest, profile, jsonStr, callback); }); } routingResultToJSON(routingResult) { return new Promise((resolve, reject) => { const callback = new com.akylas.carto.additions.RoutingResultToJSONCallback({ onJSON: (err, res) => (err ? reject(err) : resolve(res)) }); AKRoutingServiceAdditions.routingResultToJSON(routingResult.getNative(), callback); }); } } __decorate([ nativeProperty ], RoutingService.prototype, "profile", void 0); class ValhallaRoutingService extends RoutingService { matchRoute(options, profile = this.profile) { return new Promise((resolve, reject) => { const nRequest = new com.carto.routing.RouteMatchingRequest(options.projection.getNative(), mapPosVectorFromArgs(options.points), options.accuracy); if (options.customOptions) { Object.keys(options.customOptions).forEach((k) => { nRequest.setCustomParameter(k, JSVariantToNative(options.customOptions[k])); }); } const callback = new com.akylas.carto.additions.RoutingServiceRouteMatchingCallback({ onRouteMatchingResult: (err, res) => (err ? reject(err) : resolve(res ? new RouteMatchingResult(res) : null)) }); // TODO: passing profile directly seems to break terser :s Find out why const test = profile; AKRoutingServiceAdditions.matchRoute(this.getNative(), nRequest, test, callback); }); } setConfigurationParameter(param, value) { const native = this.getNative(); if (!(native instanceof com.carto.routing.ValhallaOnlineRoutingService)) { native.setConfigurationParameter(param, JSVariantToNative(value)); } } getConfigurationParameter(param) { const native = this.getNative(); if (!(native instanceof com.carto.routing.ValhallaOnlineRoutingService)) { return nativeVariantToJS(native.getConfigurationParameter(param)); } } addLocale(key, json) { const native = this.getNative(); if (!(native instanceof com.carto.routing.ValhallaOnlineRoutingService)) { native.addLocale(key, json); } } } export class PackageManagerRoutingService extends RoutingService { createNative(options) { return new com.carto.routing.PackageManagerRoutingService(options.packageManager.getNative()); } } export class SGREOfflineRoutingService extends RoutingService { createNative(options) { return new com.carto.routing.SGREOfflineRoutingService(options.projection.getNative(), options.features.getNative(), JSVariantToNative(options.config)); } } export class OSRMOfflineRoutingService extends RoutingService { createNative(options) { return new com.carto.routing.OSRMOfflineRoutingService(options.path); } } export class ValhallaOfflineRoutingService extends ValhallaRoutingService { createNative(options) { return new com.carto.routing.ValhallaOfflineRoutingService(options.path); } } export class MultiValhallaOfflineRoutingService extends ValhallaRoutingService { createNative(options) { return new com.carto.routing.MultiValhallaOfflineRoutingService(); } add(database) { this.getNative().add(database); } remove(database) { this.getNative().remove(database); } } export class ValhallaOnlineRoutingService extends ValhallaRoutingService { createNative(options) { if (options.apiKey) { return new com.carto.routing.ValhallaOnlineRoutingService(options.apiKey); } else { return new com.carto.routing.ValhallaOnlineRoutingService(); } } } __decorate([ nativeProperty ], ValhallaOnlineRoutingService.prototype, "profile", void 0); __decorate([ nativeProperty ], ValhallaOnlineRoutingService.prototype, "customServiceURL", void 0); export class PackageManagerValhallaRoutingService extends ValhallaRoutingService { createNative(options) { return new com.carto.routing.PackageManagerValhallaRoutingService(options.packageManager.getNative()); } } __decorate([ nativeProperty ], PackageManagerValhallaRoutingService.prototype, "profile", void 0); //# sourceMappingURL=index.android.js.map