Skip to content

Commit

Permalink
wip: Provide a way to run an navigation app to navigate to a point #994
Browse files Browse the repository at this point in the history
  • Loading branch information
cnouguier committed Nov 20, 2024
1 parent 1d9429d commit 72cf1c7
Show file tree
Hide file tree
Showing 5 changed files with 77 additions and 4 deletions.
1 change: 1 addition & 0 deletions map/client/globe.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ const mixins = Object.assign({}, commonMixins, { globe: globeMixins })

export * from './geolocation.js'
export * from './planets.js'
export * from './navigator.js'
export { hooks }
export { utils }
export { mixins }
Expand Down
1 change: 1 addition & 0 deletions map/client/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ const mixins = Object.assign({}, commonMixins, { map: mapMixins, globe: globeMix
export * from './geolocation.js'
export * from './capture.js'
export * from './planets.js'
export * from './navigator.js'
export * from './canvas-draw-context.js'
export { hooks }
export { utils }
Expand Down
10 changes: 6 additions & 4 deletions map/client/init.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { Store, Reader, utils as kCoreUtils, hooks as kCoreHooks } from '../../c
import * as kMapHooks from './hooks/index.js'
import { Geolocation } from './geolocation.js'
import { Planets } from './planets.js'
import { Navigator } from './navigator.js'
import * as readers from './readers/index.js'

function siftMatcher (originalQuery) {
Expand Down Expand Up @@ -55,8 +56,7 @@ export function setupApi (configuration) {

export default async function init () {
const api = this

logger.debug('[KDK] Initializing map module')
logger.debug('[KDK] Initializing Map module...')

// Declare the built-in services, others are optional
api.declareService('catalog')
Expand All @@ -77,10 +77,11 @@ export default async function init () {
// Initialize singletons that might be used globally first
Geolocation.initialize()
Planets.initialize()
Navigator.initialize()

// Then, create the models listened by the different components
// You must use the patch method on the store to update those models
// It is generally done by activity based componentq or through a local settings service
// It is generally done by activity based component or through a local settings service

// Default time formatting settings
Store.set('timeFormat', reactive({
Expand Down Expand Up @@ -118,6 +119,7 @@ export default async function init () {
Reader.register(entry.mimeTypes, readers[entry.reader])
})

// Store the intiaization state
// Store the initialization state
Store.set('kdk.map.initialized', true)
logger.debug('[KDK] Map module initialized')
}
1 change: 1 addition & 0 deletions map/client/map.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ const mixins = Object.assign({}, commonMixins, { map: mapMixins })

export * from './geolocation.js'
export * from './planets.js'
export * from './navigator.js'
export { hooks }
export { utils }
export { composables }
Expand Down
68 changes: 68 additions & 0 deletions map/client/navigator.js
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)
}
}

0 comments on commit 72cf1c7

Please sign in to comment.