179 lines
7.5 KiB
JavaScript
179 lines
7.5 KiB
JavaScript
"use strict";
|
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
if (k2 === undefined) k2 = k;
|
|
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
}
|
|
Object.defineProperty(o, k2, desc);
|
|
}) : (function(o, m, k, k2) {
|
|
if (k2 === undefined) k2 = k;
|
|
o[k2] = m[k];
|
|
}));
|
|
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
}) : function(o, v) {
|
|
o["default"] = v;
|
|
});
|
|
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
};
|
|
var __importStar = (this && this.__importStar) || (function () {
|
|
var ownKeys = function(o) {
|
|
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
var ar = [];
|
|
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
return ar;
|
|
};
|
|
return ownKeys(o);
|
|
};
|
|
return function (mod) {
|
|
if (mod && mod.__esModule) return mod;
|
|
var result = {};
|
|
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
__setModuleDefault(result, mod);
|
|
return result;
|
|
};
|
|
})();
|
|
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
};
|
|
var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
return function (target, key) { decorator(target, key, paramIndex); }
|
|
};
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
exports.MapsController = void 0;
|
|
const common_1 = require("@nestjs/common");
|
|
const swagger_1 = require("@nestjs/swagger");
|
|
const fs = __importStar(require("fs"));
|
|
const path = __importStar(require("path"));
|
|
const maps_service_1 = require("./maps.service");
|
|
const api_key_guard_1 = require("../common/guards/api-key.guard");
|
|
let MapsController = class MapsController {
|
|
mapsService;
|
|
constructor(mapsService) {
|
|
this.mapsService = mapsService;
|
|
}
|
|
async syncRoutes() {
|
|
return this.mapsService.requestRoutingSync();
|
|
}
|
|
async getStyleJson(theme, res) {
|
|
const isDark = theme === 'obsidian';
|
|
const filename = isDark ? 'style-dark.json' : 'style.json';
|
|
const fallbackFilename = 'style.json';
|
|
const pathsToCheck = [
|
|
path.join('/data', filename),
|
|
path.join(process.cwd(), '../../', filename),
|
|
path.join(process.cwd(), filename),
|
|
path.join('/data', fallbackFilename),
|
|
path.join(process.cwd(), '../../', fallbackFilename),
|
|
path.join(process.cwd(), fallbackFilename),
|
|
];
|
|
let stylePath = '';
|
|
for (const p of pathsToCheck) {
|
|
if (fs.existsSync(p)) {
|
|
stylePath = p;
|
|
break;
|
|
}
|
|
}
|
|
if (!stylePath) {
|
|
return res.status(404).send('Style not found');
|
|
}
|
|
try {
|
|
const styleRaw = fs.readFileSync(stylePath, 'utf8');
|
|
const styleObj = JSON.parse(styleRaw);
|
|
if (theme === 'light') {
|
|
styleObj.layers.forEach((layer) => {
|
|
if (layer.id === 'background') {
|
|
layer.paint['background-color'] = '#FFFFFF';
|
|
}
|
|
});
|
|
}
|
|
else if (theme === 'obsidian') {
|
|
styleObj.layers.forEach((layer) => {
|
|
if (layer.id === 'background') {
|
|
layer.paint['background-color'] = '#101014';
|
|
}
|
|
});
|
|
}
|
|
res.setHeader('Content-Type', 'application/json');
|
|
res.send(styleObj);
|
|
}
|
|
catch (e) {
|
|
res.status(500).send('Error parsing style.json');
|
|
}
|
|
}
|
|
async getRoute(query) {
|
|
const waypoints = [];
|
|
if (query.fromLat && query.fromLng) {
|
|
waypoints.push([parseFloat(query.fromLat), parseFloat(query.fromLng)]);
|
|
}
|
|
const stopKeys = Object.keys(query)
|
|
.filter(key => key.startsWith('stop') && key.endsWith('Lat'))
|
|
.sort((a, b) => {
|
|
const numA = parseInt(a.replace('stop', '').replace('Lat', ''), 10);
|
|
const numB = parseInt(b.replace('stop', '').replace('Lat', ''), 10);
|
|
return numA - numB;
|
|
});
|
|
for (const latKey of stopKeys) {
|
|
const prefix = latKey.replace('Lat', '');
|
|
const lngKey = `${prefix}Lng`;
|
|
if (query[latKey] && query[lngKey]) {
|
|
waypoints.push([parseFloat(query[latKey]), parseFloat(query[lngKey])]);
|
|
}
|
|
}
|
|
if (query.toLat && query.toLng) {
|
|
waypoints.push([parseFloat(query.toLat), parseFloat(query.toLng)]);
|
|
}
|
|
const profile = query.profile || 'car';
|
|
const steps = query.steps === 'true';
|
|
const locale = query.locale || 'en';
|
|
const alternatives = query.alternatives === 'true';
|
|
return this.mapsService.getRoute(waypoints, profile, steps, locale, alternatives);
|
|
}
|
|
async getConfig() {
|
|
return this.mapsService.getMapConfig();
|
|
}
|
|
};
|
|
exports.MapsController = MapsController;
|
|
__decorate([
|
|
(0, common_1.Post)('sync-routes'),
|
|
(0, swagger_1.ApiOperation)({ summary: 'Request GraphHopper routing sync 🔄' }),
|
|
__metadata("design:type", Function),
|
|
__metadata("design:paramtypes", []),
|
|
__metadata("design:returntype", Promise)
|
|
], MapsController.prototype, "syncRoutes", null);
|
|
__decorate([
|
|
(0, common_1.Get)('style.json'),
|
|
(0, swagger_1.ApiOperation)({ summary: 'Get MapLibre style JSON 🎨' }),
|
|
__param(0, (0, common_1.Query)('theme')),
|
|
__param(1, (0, common_1.Res)()),
|
|
__metadata("design:type", Function),
|
|
__metadata("design:paramtypes", [String, Object]),
|
|
__metadata("design:returntype", Promise)
|
|
], MapsController.prototype, "getStyleJson", null);
|
|
__decorate([
|
|
(0, common_1.Get)('route'),
|
|
(0, swagger_1.ApiOperation)({ summary: 'Calculate a route with dynamic waypoints 🚗' }),
|
|
__param(0, (0, common_1.Query)()),
|
|
__metadata("design:type", Function),
|
|
__metadata("design:paramtypes", [Object]),
|
|
__metadata("design:returntype", Promise)
|
|
], MapsController.prototype, "getRoute", null);
|
|
__decorate([
|
|
(0, common_1.Get)('config'),
|
|
(0, swagger_1.ApiOperation)({ summary: 'Get map configuration for the region 🗺️' }),
|
|
__metadata("design:type", Function),
|
|
__metadata("design:paramtypes", []),
|
|
__metadata("design:returntype", Promise)
|
|
], MapsController.prototype, "getConfig", null);
|
|
exports.MapsController = MapsController = __decorate([
|
|
(0, swagger_1.ApiTags)('maps'),
|
|
(0, common_1.Controller)('maps'),
|
|
(0, common_1.UseGuards)(api_key_guard_1.ApiKeyGuard),
|
|
__metadata("design:paramtypes", [maps_service_1.MapsService])
|
|
], MapsController);
|
|
//# sourceMappingURL=maps.controller.js.map
|