feat: refs #7882 Added osrmservice #3281
|
@ -23,8 +23,8 @@ module.exports = Self => {
|
||||||
Self.optimize = async addressIds => {
|
Self.optimize = async addressIds => {
|
||||||
const models = Self.app.models;
|
const models = Self.app.models;
|
||||||
try {
|
try {
|
||||||
const locationiqConfig = await models.LocationiqConfig.findOne();
|
const osrmConfig = await models.OsrmConfig.findOne();
|
||||||
if (!locationiqConfig) throw new UserError(`LocationIQ service is not configured`);
|
if (!osrmConfig) throw new UserError(`OSRM service is not configured`);
|
||||||
|
|
||||||
let coords = [];
|
let coords = [];
|
||||||
for (const addressId of addressIds) {
|
for (const addressId of addressIds) {
|
||||||
|
@ -39,10 +39,9 @@ module.exports = Self => {
|
||||||
.map(coord => `${coord.longitude},${coord.latitude}`)
|
.map(coord => `${coord.longitude},${coord.latitude}`)
|
||||||
.join(';');
|
.join(';');
|
||||||
const response = await axios.post(`
|
const response = await axios.post(`
|
||||||
${locationiqConfig.url}optimize/driving/${concatCoords}?key=${locationiqConfig.key}
|
${osrmConfig.url}/trip/v1/driving/${concatCoords}
|
||||||
`);
|
`);
|
||||||
const tolerance = locationiqConfig.tolerance;
|
const tolerance = osrmConfig.tolerance;
|
||||||
|
|
||||||
for (waypoint of response.data.waypoints) {
|
for (waypoint of response.data.waypoints) {
|
||||||
const longitude = waypoint.location[0];
|
const longitude = waypoint.location[0];
|
||||||
const latitude = waypoint.location[1];
|
const latitude = waypoint.location[1];
|
|
@ -88,7 +88,7 @@
|
||||||
"Language": {
|
"Language": {
|
||||||
"dataSource": "vn"
|
"dataSource": "vn"
|
||||||
},
|
},
|
||||||
"LocationiqConfig": {
|
"OsrmConfig": {
|
||||||
"dataSource": "vn"
|
"dataSource": "vn"
|
||||||
},
|
},
|
||||||
"Machine": {
|
"Machine": {
|
||||||
|
|
|
@ -1,4 +0,0 @@
|
||||||
module.exports = Self => {
|
|
||||||
require('../methods/locationiq-config/optimize')(Self);
|
|
||||||
};
|
|
||||||
|
|
|
@ -0,0 +1,4 @@
|
||||||
|
module.exports = Self => {
|
||||||
|
require('../methods/osrm-config/optimize')(Self);
|
||||||
|
};
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
{
|
{
|
||||||
"name": "LocationiqConfig",
|
"name": "OsrmConfig",
|
||||||
"base": "VnModel",
|
"base": "VnModel",
|
||||||
"options": {
|
"options": {
|
||||||
"mysql": {
|
"mysql": {
|
||||||
"table": "locationiqConfig"
|
"table": "osrmConfig"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"properties": {
|
"properties": {
|
||||||
|
@ -16,10 +16,6 @@
|
||||||
"type": "string",
|
"type": "string",
|
||||||
"required": true
|
"required": true
|
||||||
},
|
},
|
||||||
"key": {
|
|
||||||
"type": "string",
|
|
||||||
"required": true
|
|
||||||
},
|
|
||||||
"tolerance": {
|
"tolerance": {
|
||||||
"type": "number",
|
"type": "number",
|
||||||
"required": false
|
"required": false
|
|
@ -1,9 +1,7 @@
|
||||||
CREATE TABLE `vn`.`locationiqConfig` (
|
CREATE TABLE `vn`.`osrmConfig` (
|
||||||
`id` int(10) unsigned NOT NULL,
|
`id` int(10) unsigned NOT NULL,
|
||||||
`url` varchar(100) NOT NULL COMMENT 'Dirección base de la API',
|
`url` varchar(100) NOT NULL COMMENT 'Dirección base de la API',
|
||||||
`key` varchar(100) NOT NULL COMMENT 'Access token',
|
|
||||||
`tolerance` decimal(6,6) NOT NULL DEFAULT 0 COMMENT 'Tolerancia entre las coordenadas enviadas y las retornadas',
|
`tolerance` decimal(6,6) NOT NULL DEFAULT 0 COMMENT 'Tolerancia entre las coordenadas enviadas y las retornadas',
|
||||||
`maxCoordsRequest` int(10) unsigned DEFAULT NULL COMMENT 'Número máximo de coordenadas por petición',
|
|
||||||
PRIMARY KEY (`id`),
|
PRIMARY KEY (`id`),
|
||||||
CONSTRAINT `locationiqConfig_check` CHECK (`id` = 1)
|
CONSTRAINT `osrmConfig_check` CHECK (`id` = 1)
|
||||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci;
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci;
|
Loading…
Reference in New Issue