-
-
Notifications
You must be signed in to change notification settings - Fork 64
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #781 from WatWowMap/route-support
feat: initial route support
- Loading branch information
Showing
45 changed files
with
1,010 additions
and
109 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
{ | ||
"name": "reactmap", | ||
"version": "1.21.1", | ||
"version": "1.22.2", | ||
"description": "React based frontend map.", | ||
"main": "ReactMap.js", | ||
"author": "TurtIeSocks <[email protected]>", | ||
|
@@ -35,10 +35,10 @@ | |
"yarn": "^1.22.x" | ||
}, | ||
"devDependencies": { | ||
"@sentry/vite-plugin": "^2.2.1", | ||
"@sentry/vite-plugin": "2.2.1", | ||
"@types/react": "^18.2.15", | ||
"@types/react-dom": "^18.2.7", | ||
"@vitejs/plugin-react": "^4.0.0", | ||
"@vitejs/plugin-react": "4.0.0", | ||
"eslint": "^8.44.0", | ||
"eslint-config-airbnb": "^19.0.4", | ||
"eslint-config-prettier": "^8.8.0", | ||
|
@@ -50,9 +50,9 @@ | |
"nodemon": "^2.0.22", | ||
"prettier": "^2.8.8", | ||
"rollup-plugin-delete": "^2.0.0", | ||
"vite": "^4.3.9", | ||
"vite-plugin-checker": "^0.6.0", | ||
"vite-plugin-static-copy": "^0.16.0" | ||
"vite": "4.3.9", | ||
"vite-plugin-checker": "0.6.0", | ||
"vite-plugin-static-copy": "0.16.0" | ||
}, | ||
"dependencies": { | ||
"@apollo/client": "^3.7.15", | ||
|
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
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,105 @@ | ||
const { Model } = require('objection') | ||
const getAreaSql = require('../services/functions/getAreaSql') | ||
|
||
const GET_ALL_SELECT = /** @type {const} */ ([ | ||
'id', | ||
'start_lat', | ||
'start_lon', | ||
'end_lat', | ||
'end_lon', | ||
'waypoints', | ||
'image_border_color', | ||
'reversible', | ||
]) | ||
|
||
class Route extends Model { | ||
static get tableName() { | ||
return 'route' | ||
} | ||
|
||
/** | ||
* Returns the bare essentials for displaying on the map | ||
* @param {import('../types').Permissions} perms | ||
* @param {object} args | ||
* @param {import('../types').DbContext} ctx | ||
* @returns | ||
*/ | ||
static async getAll(perms, args, ctx) { | ||
const { areaRestrictions } = perms | ||
const { onlyAreas, onlyDistance } = args.filters | ||
|
||
const distanceInMeters = (onlyDistance || [0.5, 100]).map((x) => x * 1000) | ||
|
||
const query = this.query() | ||
.select(GET_ALL_SELECT) | ||
.whereBetween('start_lat', [args.minLat, args.maxLat]) | ||
.andWhereBetween('start_lon', [args.minLon, args.maxLon]) | ||
.andWhereBetween('distance_meters', distanceInMeters) | ||
.union((qb) => { | ||
qb.select(GET_ALL_SELECT) | ||
.whereBetween('end_lat', [args.minLat, args.maxLat]) | ||
.andWhereBetween('end_lon', [args.minLon, args.maxLon]) | ||
.andWhereBetween('distance_meters', distanceInMeters) | ||
.from('route') | ||
|
||
getAreaSql(qb, areaRestrictions, onlyAreas, ctx.isMad, 'route') | ||
}) | ||
|
||
if (!getAreaSql(query, areaRestrictions, onlyAreas, ctx.isMad, 'route')) { | ||
return [] | ||
} | ||
const results = await query | ||
|
||
return results.map((result) => { | ||
if (typeof result.waypoints === 'string') { | ||
result.waypoints = JSON.parse(result.waypoints) | ||
} else if (result.waypoints === null) { | ||
result.waypoints = [] | ||
} | ||
return result | ||
}) | ||
} | ||
|
||
/** | ||
* Returns the full route after querying it, generally from the Popup | ||
* @param {number} id | ||
*/ | ||
static async getOne(id) { | ||
const result = await this.query().findById(id) | ||
if (typeof result.waypoints === 'string') { | ||
result.waypoints = JSON.parse(result.waypoints) | ||
} else if (result.waypoints === null) { | ||
result.waypoints = [] | ||
} | ||
if (typeof result.tags === 'string') { | ||
result.tags = JSON.parse(result.tags) | ||
} else if (result.tags === null) { | ||
result.tags = [] | ||
} | ||
if (typeof result.image === 'string') { | ||
result.image = result.image.replace('http://', 'https://') | ||
} | ||
if (typeof result.start_image === 'string') { | ||
result.start_image = result.start_image.replace('http://', 'https://') | ||
} | ||
if (typeof result.end_image === 'string') { | ||
result.end_image = result.end_image.replace('http://', 'https://') | ||
} | ||
return result | ||
} | ||
|
||
/** | ||
* returns route context | ||
* @returns {{ max_distance: number, max_duration: number }} | ||
*/ | ||
static async getFilterContext() { | ||
const result = await this.query() | ||
.max('distance_meters AS max_distance') | ||
.max('duration_seconds AS max_duration') | ||
.first() | ||
|
||
return result | ||
} | ||
} | ||
|
||
module.exports = Route |
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
Oops, something went wrong.