成都SKPAR小程序
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.
 

366 lines
8.8 KiB

const FacilityCodeMap = {
ft: 0,
upft: 0,
downft: 0,
mys: 3,
xsj: 4,
fwt: 7,
dt: 5,
lt: 88,
dit: 89,
cjr: 10,
tcc: 8,
xsjn: 12,
xsjv: 13,
xxt: 14,
tczl: 8,
fcjcg: 7,
door: 39,
czc: 500,
vip: 34,
pq: 40,
ksgj: 30,
xcgc: 57,
tthy: 58,
bc: 26,
etxsj: 69,
};
const floorDiffMap = {
"3_5": 1,
"5_3": 1,
};
export const attachGraphSingle = ({ graph, key, value }) => {
graph[key] = {
...graph[key],
...value,
};
};
export const attachGraph = ({
graph,
leftKey,
rightKey,
leftValue,
rightValue,
}) => {
graph[leftKey] = {
...graph[leftKey],
...leftValue,
};
graph[rightKey] = {
...graph[rightKey],
...rightValue,
};
};
export const getDataNew = async (map) => {
const {
mall: { shopInfo, mapData },
} = map;
return {
serverShopInfo: shopInfo,
mapData,
};
};
export const handleData = (
shopInfo,
mapData,
ftData,
excludeNodes,
extraCosts,
portals,
mall,
facilityTypeMap,
facilityCodeMap
) => {
Object.assign(FacilityCodeMap, facilityCodeMap);
const { floors } = mall;
let shopMap = {};
let shopNavSet = new Set();
const parkingSpaceByFloor = [];
const excludeSet = excludeNodes
? excludeNodes.reduce((acc, nxt) => {
acc.add(nxt);
return acc;
}, new Set())
: new Set();
shopInfo.forEach(({ shopList }, floorOrder) => {
shopList.forEach((shop) => {
shopMap[shop.houseNum] = shop;
shopNavSet.add(floorOrder + "_" + shop.yaxis);
});
});
const noUpMap = {};
const noDownMap = {};
const list = mapData.buildArr
.map(({ mapData }) => mapData)
.map(({ icons, path, stairs, shopArea, floorArea, parkArea }, i) => {
const nodes = path ? path.nodes : [];
let points = [];
let routes = [];
let height = Number(floorArea ? floorArea.toHeight : 0);
nodes.forEach(({ id, list, x, y }) => {
points[id] = {
name: id,
position: [x, height + 0.1, y],
};
list.forEach((node) => {
const needIncrease = extraCosts[`${i}_${id}_${node.id}`];
routes.push({
src: id,
des: node.id,
cost: needIncrease ? 1000 : node.cost,
});
});
});
let facilities = [];
icons.forEach(({ navCode, facCode, Type }) => {
if (points[Number(navCode)])
facilities.push({
Escalator: 0,
NavPoint: Number(navCode),
Type: FacilityCodeMap[facCode],
Images: facCode,
point: points[Number(navCode)].position,
});
});
stairs.forEach(({ navCode, facCode, no, downState, upState }) => {
if (points[Number(navCode)] && no) {
const NavPoint = Number(navCode);
const key = `${i}_${NavPoint}`;
const value = ftData[key];
if (downState) noDownMap[key] = true;
if (upState) noUpMap[key] = true;
facilities.push({
Escalator: Number(no),
NavPoint: NavPoint,
Type: FacilityCodeMap[facCode],
Images: facCode,
point: points[Number(navCode)].position,
entrances: value ? Object.keys(value) : [],
});
}
});
shopArea.forEach(({ name, shopNav, xaxis, yaxis }) => {
if (shopMap[name]) {
shopMap[name].yaxis = shopNav;
shopMap[name].xaxis = [xaxis, height, yaxis];
}
});
parkingSpaceByFloor[i] = parkArea;
return {
facilities,
points,
routes,
};
});
const facilities = list.map(({ facilities }) => facilities);
facilities.forEach((facilitiesOnSameFloor, floorOrder) => {
facilitiesOnSameFloor.forEach((facility) => {
facility.floorOrder = floorOrder;
});
});
const flatFacilities = facilities.reduce((acc, nxt) => acc.concat(nxt), []);
flatFacilities.forEach((fac) => {
fac.isFac = true;
fac.floorName = floors[fac.floorOrder][1];
fac.name = fac.floorName + facilityTypeMap[fac.Type];
fac.xaxis = fac.point;
fac.yaxis = Number(fac.NavPoint);
fac.id = `${fac.floorOrder}_${fac.Type}_${fac.NavPoint}`;
});
const facilityLiftMap = flatFacilities.reduce(
(acc, nxt) =>
!(nxt.Type === 0 || nxt.Type === 5)
? acc
: {
...acc,
[`${nxt.floorOrder}_${nxt.NavPoint}`]: nxt,
},
{}
);
const facilityMap = flatFacilities.reduce(
(acc, nxt) => ({
...acc,
[nxt.id]: nxt,
}),
{}
);
const routes = list.map(({ routes }) => routes);
const points = list.map(({ points }) => points);
const graph = {};
routes.forEach((route, floorOrder) => {
route.forEach(({ src, des, cost }) => {
const srcId = floorOrder + "_" + src;
const desId = floorOrder + "_" + des;
if (excludeSet.has(srcId) || excludeSet.has(desId)) return;
graph[srcId] = {
...graph[srcId],
[desId]: cost,
};
graph[desId] = {
...graph[desId],
[srcId]: cost,
};
});
});
const graphDt = JSON.parse(JSON.stringify(graph));
const graphFt = JSON.parse(JSON.stringify(graph));
let escalatorMap = flatFacilities.reduce(
(acc, { NavPoint, Escalator, Type, floorOrder }) => {
if (NavPoint !== undefined && (Type === 0 || Type === 5)) {
if (acc[`${Type}_${Escalator}`])
acc[`${Type}_${Escalator}`].push({
NavPoint,
floorOrder,
Type,
});
else
acc[`${Type}_${Escalator}`] = [
{
NavPoint,
floorOrder,
Type,
},
];
acc[`${Type}_${Escalator}`].isEscalator = Type === 0;
}
return acc;
},
{}
);
Object.values(ftData).forEach((value) => {
Object.entries(value).forEach(([key, dsts]) => {
dsts.forEach((dst) => {
const value = {
[dst]: 6000,
};
attachGraphSingle({
graph,
key,
value,
});
attachGraphSingle({
graph: graphFt,
key,
value,
});
});
});
});
Object.values(escalatorMap).forEach((list) => {
for (let i = 0; i < list.length - 1; i++) {
for (let j = i + 1; j < list.length; j++) {
const { floorOrder: floorOrderI, NavPoint: src } = list[i];
const { floorOrder: floorOrderJ, NavPoint: des } = list[j];
const leftKey = floorOrderI + "_" + src;
const rightKey = floorOrderJ + "_" + des;
const isUp = Number(floorOrderJ) > Number(floorOrderI);
const floorDiffKey = isUp
? `${floorOrderI}_${floorOrderJ}`
: `${floorOrderJ}_${floorOrderI}`;
const floorDiff =
floorDiffKey in floorDiffMap && floorDiffMap
? floorDiffMap[floorDiffKey]
: Math.abs(floorOrderI - floorOrderJ);
if (ftData[leftKey]) return;
if (ftData[rightKey]) return;
const leftValue = {
[rightKey]:
(isUp && noUpMap[leftKey]) || (!isUp && noDownMap[leftKey])
? Infinity
: list.isEscalator
? 7000 * floorDiff
: 7000 + floorDiff * 1000,
};
const rightValue = {
[leftKey]:
(!isUp && noUpMap[rightKey]) || (isUp && noDownMap[rightKey])
? Infinity
: list.isEscalator
? 7000 * floorDiff
: 7000 + floorDiff * 1000,
};
attachGraph({
graph,
leftKey,
rightKey,
leftValue,
rightValue,
});
if (list.isEscalator)
attachGraph({
graph: graphFt,
leftKey,
rightKey,
leftValue,
rightValue,
});
else
attachGraph({
graph: graphDt,
leftKey,
rightKey,
leftValue,
rightValue,
});
}
}
});
const grahps = [graph, graphDt, graphFt];
portals.forEach(({ leftKey, rightKey, leftValue, rightValue }) =>
grahps.forEach((graph) =>
attachGraph({
graph,
leftKey,
rightKey,
leftValue,
rightValue,
})
)
);
return {
points,
routes,
graph,
graphDt,
graphFt,
facilities,
flatFacilities,
excludeSet,
parkingSpaceByFloor,
facilityLiftMap,
facilityMap,
};
};
const dataHelper = async (map) => {
const {
ftData = {},
excludeNodes,
extraCosts = {},
portals = [],
serverShopInfo,
mapData,
mall,
facilityTypeMap,
facilityCodeMap,
} = map;
return handleData(
serverShopInfo,
mapData,
ftData,
excludeNodes,
extraCosts,
portals,
mall,
facilityTypeMap,
facilityCodeMap
);
};
export default dataHelper;