-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
wip: Provide a way to run an navigation app to navigate to a point #994
- Loading branch information
Showing
5 changed files
with
77 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
import _ from 'lodash' | ||
import logger from 'loglevel' | ||
import config from 'config' | ||
import { Store } from '../../core/client/store.js' | ||
import { getPlatform } from '../../core/client/utils/utils.platform.js' | ||
|
||
export const Navigator = { | ||
|
||
initialize () { | ||
// Sets the available apps | ||
Store.set('navigator.apps', _.defaultsDeep(config.navigator, { | ||
waze: { | ||
label: "waze", | ||
icon: 'las la-waze', | ||
url: 'https://waze.com/ul?q=<%= lat %>,<%= lon %>' | ||
}, | ||
'google-maps': { | ||
label: "Google Maps", | ||
icon: 'las la-google', | ||
url: 'https://www.google.com/maps/dir/?api=1&destination=<%= lat %>,<%= lon %>' | ||
}, | ||
'apple-plan': { | ||
label: "Apple Plan", | ||
icon: 'las la-apple', | ||
url: 'https://maps.apple.com/place?ll=<%= lat %>,<%= lon %>' | ||
} | ||
})) | ||
// Define the default app | ||
let defaultApp = 'google-maps' | ||
const platform = getPlatform() | ||
if (platform.ios) defaultApp = 'apple-plan' | ||
if (platform.android) defaultApp = 'google-maps' | ||
Store.set('navigator.default', defaultApp) | ||
logger.debug('[KDK] Navigator initialized with configuration:', Store.get('navigator')) | ||
}, | ||
|
||
getApps () { | ||
return Store.get('navigator.apps') | ||
}, | ||
|
||
getDefault () { | ||
return Store.get('navigator.default') | ||
}, | ||
|
||
setDefault (name) { | ||
Store.set('navigator.default', name) | ||
}, | ||
|
||
navigate (lat, lon) { | ||
// Retrieve the default app | ||
const defaultApp = this.getDefault() | ||
if (_.isEmpty(defaultApp)) { | ||
logger.debug('[KDK] Default navigator is undefined') | ||
return | ||
} | ||
// Retrieve the associated url | ||
const appUrl = _.get(Store.get('navigator.apps'), `${defaultApp}.url`) | ||
if (_.isEmpty(appUrl)) { | ||
logger.debug(`[KDK] Navigator app '${defaultApp}' has an undefined url`) | ||
return | ||
} | ||
// Template the url | ||
const compiledUrl = _.template(appUrl) | ||
const interpolatedUrl = compiledUrl({ lat, lon }) | ||
// Open the interpolated url | ||
window.open(interpolatedUrl) | ||
} | ||
} |