You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
39 lines
1.3 KiB
39 lines
1.3 KiB
const fs = require("fs")
|
|
const _ = require("lodash");
|
|
const Service = require("egg").Service;
|
|
class HomeService extends Service {
|
|
//设置收藏数据
|
|
async setRouterFav(params) {
|
|
let { ctx } = this
|
|
let pathStr = `${ctx.app.baseDir}/app/public/task/${_.get(params, ["routeList", 0, "map"])}/${params.did}/${params.pid}`
|
|
fs.mkdirSync(pathStr, { recursive: true, })
|
|
fs.writeFileSync(`${pathStr}/routeList.json`, JSON.stringify(params, null, 2))
|
|
return { haserror: false, msg: `${pathStr}/routeList.json:成功写入。` }
|
|
}
|
|
//获取收藏数据
|
|
async getRouterFav(params) {
|
|
let { ctx } = this
|
|
try {
|
|
let pathStr = `${ctx.app.baseDir}/app/public/task/${_.get(params, ["mapName"])}/${params.did}/${params.pid}/routeList.json`
|
|
let readResult = fs.readFileSync(pathStr, { encoding: "utf8" })
|
|
return readResult
|
|
} catch (error) {
|
|
return {
|
|
...params,
|
|
routeList: []
|
|
}
|
|
}
|
|
}
|
|
//获取瓦片地图
|
|
async getMapPng(params) {
|
|
let { ctx } = this
|
|
let pathObj = _.drop(_.compact(_.split(params.url, "/")))
|
|
let z = parseInt(pathObj[1]) - 1
|
|
let y = parseInt(pathObj[2])
|
|
let x = parseInt(pathObj[3])
|
|
let pngPath = `${ctx.app.baseDir}/app/public/map/${pathObj[0]}/${z}/${y}/${x}.png`
|
|
return pngPath
|
|
}
|
|
}
|
|
|
|
module.exports = HomeService;
|
|
|