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.
387 lines
9.0 KiB
387 lines
9.0 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,
|
|
sjcd: 25,
|
|
};
|
|
const defaultFacilityTypeMap = {
|
|
0: "扶梯",
|
|
1: "扶梯",
|
|
2: "扶梯",
|
|
3: "母婴室",
|
|
4: "卫生间",
|
|
5: "直梯",
|
|
6: "厕所",
|
|
7: "服务台",
|
|
8: "停车场",
|
|
9: "儿童厕所",
|
|
10: "无障碍卫生间",
|
|
11: "吸烟室",
|
|
12: "男洗手间",
|
|
13: "女洗手间",
|
|
14: "信息台",
|
|
16: "饮水处",
|
|
21: "地铁",
|
|
25: "新能源充电站",
|
|
26: "泊车",
|
|
28: "家庭洗手间(男)",
|
|
29: "家庭洗手间",
|
|
30: "公交",
|
|
34: "VIP",
|
|
39: "出入口",
|
|
40: "喷泉",
|
|
35: "男洗手间",
|
|
36: "女洗手间",
|
|
57: "下沉广场",
|
|
58: "天台花园",
|
|
69: "儿童洗手间",
|
|
88: "楼梯",
|
|
89: "地铁",
|
|
93: "男更衣室",
|
|
94: "女更衣室",
|
|
500: "出租车",
|
|
};
|
|
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
|
|
) => {
|
|
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)]) {
|
|
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 + defaultFacilityTypeMap[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 floorDiff = Math.abs(floorOrderI - floorOrderJ);
|
|
const isUp = Number(floorOrderJ) > Number(floorOrderI);
|
|
if (ftData[leftKey]) return;
|
|
if (ftData[rightKey]) return;
|
|
const leftValue = {
|
|
[rightKey]:
|
|
(isUp && noUpMap[leftKey]) || (!isUp && noDownMap[leftKey])
|
|
? Infinity
|
|
: list.isEscalator
|
|
? 7000 * floorDiff
|
|
: 10000 + floorDiff * 1000,
|
|
};
|
|
const rightValue = {
|
|
[leftKey]:
|
|
(!isUp && noUpMap[rightKey]) || (isUp && noDownMap[rightKey])
|
|
? Infinity
|
|
: list.isEscalator
|
|
? 7000 * floorDiff
|
|
: 10000 + 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,
|
|
} = map;
|
|
|
|
return handleData(
|
|
serverShopInfo,
|
|
mapData,
|
|
ftData,
|
|
excludeNodes,
|
|
extraCosts,
|
|
portals,
|
|
mall
|
|
);
|
|
};
|
|
export default dataHelper;
|
|
|