zone based assets added and 3d widgets dnd updated
This commit is contained in:
@@ -2,7 +2,7 @@ import React, { useEffect, useState } from "react";
|
||||
import List from "./List";
|
||||
import { AddIcon, ArrowIcon, FocusIcon } from "../../icons/ExportCommonIcons";
|
||||
import KebabMenuListMultiSelect from "./KebebMenuListMultiSelect";
|
||||
import { useZones } from "../../../store/store";
|
||||
import { useFloorItems, useZones } from "../../../store/store";
|
||||
import { useSelectedZoneStore } from "../../../store/useZoneStore";
|
||||
|
||||
interface DropDownListProps {
|
||||
@@ -38,92 +38,66 @@ const DropDownList: React.FC<DropDownListProps> = ({
|
||||
const handleToggle = () => {
|
||||
setIsOpen((prev) => !prev); // Toggle the state
|
||||
};
|
||||
|
||||
interface Asset {
|
||||
id: string;
|
||||
name: string;
|
||||
position: [number, number, number]; // x, y, z
|
||||
}
|
||||
|
||||
const [zoneDataList, setZoneDataList] = useState<
|
||||
{ id: string; name: string; assets: Asset[] }[]
|
||||
>([]);
|
||||
const [zonePoints3D, setZonePoints3D] = useState<[]>([]);
|
||||
interface Zone {
|
||||
zoneId: string;
|
||||
zoneName: string;
|
||||
points: [number, number, number][]; // polygon vertices
|
||||
}
|
||||
interface ZoneData {
|
||||
id: string;
|
||||
name: string;
|
||||
assets: { id: string; name: string; position?: [] ;rotation?:{}}[];
|
||||
}
|
||||
const [zoneDataList, setZoneDataList] = useState<ZoneData[]>([]);
|
||||
const { floorItems, setFloorItems } = useFloorItems();
|
||||
|
||||
const { selectedZone, setSelectedZone } = useSelectedZoneStore();
|
||||
const isPointInsidePolygon = (point: [number, number], polygon: [number, number][]) => {
|
||||
let inside = false;
|
||||
for (let i = 0, j = polygon.length - 1; i < polygon.length; j = i++) {
|
||||
const xi = polygon[i][0], zi = polygon[i][1];
|
||||
const xj = polygon[j][0], zj = polygon[j][1];
|
||||
|
||||
useEffect(() => {
|
||||
// const value = (zones || []).map(
|
||||
// (val: { zoneId: string; zoneName: string }) => ({
|
||||
// id: val.zoneId,
|
||||
// name: val.zoneName,
|
||||
// })
|
||||
// );
|
||||
// console.log('zones: ', zones);
|
||||
const value = (zones || []).map((val: { zoneId: string; zoneName: string }) => ({
|
||||
id: val.zoneId,
|
||||
name: val.zoneName
|
||||
}));
|
||||
setZoneDataList(prev => (JSON.stringify(prev) !== JSON.stringify(value) ? value : prev));
|
||||
const allPoints = zones.flatMap((zone: any) => zone.points);
|
||||
setZonePoints3D(allPoints);
|
||||
// setZoneDataList([
|
||||
// {
|
||||
// id: "zone1",
|
||||
// name: "Zone 1",
|
||||
// assets: [
|
||||
// {
|
||||
// id: "asset1",
|
||||
// name: "Asset 1",
|
||||
// },
|
||||
// {
|
||||
// id: "asset2",
|
||||
// name: "Asset 2",
|
||||
// },
|
||||
// {
|
||||
// id: "asset3",
|
||||
// name: "Asset 3",
|
||||
// },
|
||||
// ],
|
||||
// },
|
||||
// {
|
||||
// id: "zone2",
|
||||
// name: "Zone 2",
|
||||
// assets: [
|
||||
// {
|
||||
// id: "asset4",
|
||||
// name: "Asset 4",
|
||||
// },
|
||||
// {
|
||||
// id: "asset5",
|
||||
// name: "Asset 5",
|
||||
// },
|
||||
// {
|
||||
// id: "asset6",
|
||||
// name: "Asset 6",
|
||||
// },
|
||||
// ],
|
||||
// },
|
||||
// {
|
||||
// id: "zone3",
|
||||
// name: "Zone 3",
|
||||
// assets: [
|
||||
// {
|
||||
// id: "asset7",
|
||||
// name: "Asset 7",
|
||||
// },
|
||||
// {
|
||||
// id: "asset8",
|
||||
// name: "Asset 8",
|
||||
// },
|
||||
// ],
|
||||
// },
|
||||
// ]);
|
||||
const intersect = ((zi > point[1]) !== (zj > point[1])) &&
|
||||
(point[0] < (xj - xi) * (point[1] - zi) / (zj - zi + 0.000001) + xi);
|
||||
|
||||
}, [zones]);
|
||||
if (intersect) inside = !inside;
|
||||
}
|
||||
return inside;
|
||||
};
|
||||
useEffect(() => {
|
||||
|
||||
// console.log('zonePoints3D: ', zonePoints3D);
|
||||
}, [zonePoints3D])
|
||||
const updatedZoneList: ZoneData[] = zones.map((zone: Zone) => {
|
||||
const polygon2D = zone.points.map((p: [number, number, number]) => [p[0], p[2]]) as [number, number][];
|
||||
|
||||
const assetsInZone = floorItems
|
||||
.filter((item: any) => {
|
||||
const [x, , z] = item.position;
|
||||
return isPointInsidePolygon([x, z], polygon2D);
|
||||
})
|
||||
.map((item: any) => ({
|
||||
id: item.modeluuid,
|
||||
name: item.modelname,
|
||||
position: item.position,
|
||||
rotation:item.rotation
|
||||
}));
|
||||
|
||||
return {
|
||||
id: zone.zoneId,
|
||||
name: zone.zoneName,
|
||||
assets: assetsInZone,
|
||||
};
|
||||
});
|
||||
setZoneDataList(updatedZoneList);
|
||||
}, [zones, floorItems]);
|
||||
|
||||
|
||||
|
||||
|
||||
return (
|
||||
<div className="dropdown-list-container">
|
||||
|
||||
Reference in New Issue
Block a user