hart-estate-widget 0.0.23 → 0.0.24
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -23,6 +23,8 @@ var _Loader = _interopRequireDefault(require("./Loader"));
|
|
23
23
|
|
24
24
|
var _panoramaHelpers = require("../utils/panoramaHelpers");
|
25
25
|
|
26
|
+
var _geometric = require("geometric");
|
27
|
+
|
26
28
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
27
29
|
|
28
30
|
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
@@ -63,21 +65,22 @@ const getPanoramas = (json, images, setLoadingState) => {
|
|
63
65
|
|
64
66
|
const getPanoramaRooms = (json, panoramas) => {
|
65
67
|
return panoramas.map((panorama, index) => {
|
66
|
-
|
67
|
-
|
68
|
+
panorama['panorama_index'] = index;
|
69
|
+
const type = "Room - ".concat(panorama['panorama_id']);
|
70
|
+
if (!json) return {
|
71
|
+
type,
|
72
|
+
id: index,
|
73
|
+
panorama,
|
74
|
+
left: 0,
|
75
|
+
top: 0
|
68
76
|
};
|
77
|
+
const currentRoom = json.Floors[0].Units[0].Rooms.find(room => room.ID === panorama['room_id']);
|
78
|
+
const [left, top] = (0, _geometric.polygonMean)((0, _panoramaHelpers.getRoomCoordinates)(currentRoom, json.Floors[0].Walls, json.Vertices));
|
69
79
|
|
70
|
-
if (
|
71
|
-
currentRoom
|
80
|
+
if (!panorama.linkedSpots.length) {
|
81
|
+
setPanoramaLinks(json, currentRoom, [left, top], panorama, panoramas);
|
72
82
|
}
|
73
83
|
|
74
|
-
const {
|
75
|
-
left,
|
76
|
-
top
|
77
|
-
} = json ? (0, _panoramaHelpers.findRoomCenter)(currentRoom, json.Floors[0].Walls, json.Vertices) : {
|
78
|
-
left: 0,
|
79
|
-
top: 0
|
80
|
-
};
|
81
84
|
return {
|
82
85
|
type: currentRoom.Type,
|
83
86
|
id: index,
|
@@ -88,6 +91,39 @@ const getPanoramaRooms = (json, panoramas) => {
|
|
88
91
|
}, []);
|
89
92
|
};
|
90
93
|
|
94
|
+
const setPanoramaLinks = (json, currentRoom, center, panorama, panoramas) => {
|
95
|
+
json.Floors[0].Doors.forEach(_ref => {
|
96
|
+
let {
|
97
|
+
Location,
|
98
|
+
Walls
|
99
|
+
} = _ref;
|
100
|
+
if (!Walls.some(doorWallId => currentRoom.Walls.some(roomWallId => roomWallId === doorWallId))) return;
|
101
|
+
const connectedRoom = json.Floors[0].Units[0].Rooms.find(room => {
|
102
|
+
const roomHasSameWall = room.Walls.some(roomWallId => Walls.some(doorWallId => roomWallId === doorWallId));
|
103
|
+
const isSameRoom = room.ID === currentRoom.ID;
|
104
|
+
return roomHasSameWall && !isSameRoom;
|
105
|
+
});
|
106
|
+
if (!connectedRoom) return;
|
107
|
+
const connectedPanorama = panoramas.find(_ref2 => {
|
108
|
+
let {
|
109
|
+
room_id
|
110
|
+
} = _ref2;
|
111
|
+
return room_id === connectedRoom.ID;
|
112
|
+
});
|
113
|
+
if (!connectedPanorama) return;
|
114
|
+
const locationX = Location.X - center[0];
|
115
|
+
const locationY = -(Location.Y - center[1]);
|
116
|
+
const defaultScale = 20;
|
117
|
+
const maxScale = 50;
|
118
|
+
const defaultLength = 120;
|
119
|
+
const length = (0, _geometric.lineLength)([[0, 0], [locationX, locationY]]);
|
120
|
+
const scale = length / defaultLength * defaultScale;
|
121
|
+
const finalScale = scale > maxScale ? maxScale : scale;
|
122
|
+
const position = new THREE.Vector3(locationX, -10, locationY);
|
123
|
+
panorama.link(connectedPanorama, position, finalScale);
|
124
|
+
});
|
125
|
+
};
|
126
|
+
|
91
127
|
const initPanorama = () => {
|
92
128
|
let camera = new THREE.PerspectiveCamera(75, window.innerWidth / window.innerHeight, 1, 1100);
|
93
129
|
let controls = new _threeDeviceOrientation.default(camera);
|
@@ -113,12 +149,12 @@ const initPanorama = () => {
|
|
113
149
|
};
|
114
150
|
};
|
115
151
|
|
116
|
-
const PanoramaTab =
|
152
|
+
const PanoramaTab = _ref3 => {
|
117
153
|
let {
|
118
154
|
json,
|
119
155
|
planImage,
|
120
156
|
images
|
121
|
-
} =
|
157
|
+
} = _ref3;
|
122
158
|
const [menuState, setMenuState] = (0, _react.useState)(false);
|
123
159
|
const [loadingState, setLoadingState] = (0, _react.useState)(true);
|
124
160
|
const [isMapActive, setMapState] = (0, _react.useState)(false);
|
@@ -178,6 +214,12 @@ const PanoramaTab = _ref => {
|
|
178
214
|
});
|
179
215
|
panoramas.forEach(panorama => {
|
180
216
|
if (!panorama.panorama_id) return;
|
217
|
+
panorama.addEventListener('enter', _ref4 => {
|
218
|
+
let {
|
219
|
+
target
|
220
|
+
} = _ref4;
|
221
|
+
return setCurrentRoomIndex(target['panorama_index']);
|
222
|
+
});
|
181
223
|
newViewer.add(panorama);
|
182
224
|
});
|
183
225
|
setViewer(newViewer);
|
@@ -3,9 +3,9 @@
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
4
4
|
value: true
|
5
5
|
});
|
6
|
-
exports.
|
6
|
+
exports.getScale = exports.getRoomCoordinates = exports.findWallVertices = void 0;
|
7
7
|
|
8
|
-
require("core-js/modules/
|
8
|
+
require("core-js/modules/es.array.reduce.js");
|
9
9
|
|
10
10
|
var _react = _interopRequireDefault(require("react"));
|
11
11
|
|
@@ -13,59 +13,24 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
|
|
13
13
|
|
14
14
|
const findWallVertices = (walls, wall, vertices) => {
|
15
15
|
const currentWall = walls.find(el => el.ID === wall);
|
16
|
-
return currentWall.Vertices.map(
|
17
|
-
|
18
|
-
|
19
|
-
exports.findWallVertices = findWallVertices;
|
20
|
-
|
21
|
-
const getVerticesLocations = vertices => vertices.map(vertex => vertex.Location);
|
22
|
-
|
23
|
-
exports.getVerticesLocations = getVerticesLocations;
|
24
|
-
|
25
|
-
const findMinMaxCoordinates = (room, walls, vertices) => {
|
26
|
-
let maxX = 0;
|
27
|
-
let minX = Infinity;
|
28
|
-
let maxY = 0;
|
29
|
-
let minY = Infinity;
|
30
|
-
room.Walls.forEach(wall => {
|
31
|
-
const [coord1, coord2] = getVerticesLocations(findWallVertices(walls, wall, vertices)); // CALCULATE MAX COORDS
|
32
|
-
|
33
|
-
if (coord1.X > maxX) maxX = coord1.X;
|
34
|
-
if (coord1.X > maxX) maxX = coord1.X;
|
35
|
-
if (coord2.Y > maxY) maxY = coord2.Y;
|
36
|
-
if (coord2.Y > maxY) maxY = coord2.Y; // CALCULATE MIN COORDS
|
37
|
-
|
38
|
-
if (coord1.X < minX) minX = coord1.X;
|
39
|
-
if (coord1.X < minX) minX = coord1.X;
|
40
|
-
if (coord2.Y < minY) minY = coord2.Y;
|
41
|
-
if (coord2.Y < minY) minY = coord2.Y;
|
16
|
+
return currentWall.Vertices.map(vertexId => {
|
17
|
+
const vertex = vertices.find(el => el.ID === vertexId);
|
18
|
+
return [vertex.Location.X, vertex.Location.Y];
|
42
19
|
});
|
43
|
-
return {
|
44
|
-
maxX,
|
45
|
-
minX,
|
46
|
-
maxY,
|
47
|
-
minY
|
48
|
-
};
|
49
20
|
};
|
50
21
|
|
51
|
-
exports.
|
22
|
+
exports.findWallVertices = findWallVertices;
|
52
23
|
|
53
|
-
const
|
54
|
-
const {
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
const left = (maxX + minX) / 2;
|
61
|
-
const top = (maxY + minY) / 2;
|
62
|
-
return {
|
63
|
-
left,
|
64
|
-
top
|
65
|
-
};
|
24
|
+
const getRoomCoordinates = (room, walls, vertices) => {
|
25
|
+
const points = room.Walls.reduce((acc, wallId) => {
|
26
|
+
const wall = walls.find(wallObject => wallObject.ID === wallId);
|
27
|
+
findWallVertices(walls, wall.ID, vertices).forEach(vertex => acc.push(vertex));
|
28
|
+
return acc;
|
29
|
+
}, []);
|
30
|
+
return points;
|
66
31
|
};
|
67
32
|
|
68
|
-
exports.
|
33
|
+
exports.getRoomCoordinates = getRoomCoordinates;
|
69
34
|
|
70
35
|
const getScale = (image, json) => {
|
71
36
|
if (!json) return {
|
package/package.json
CHANGED
@@ -3,7 +3,7 @@
|
|
3
3
|
"description": "HART Estate widget",
|
4
4
|
"author": "HART",
|
5
5
|
"keywords": [],
|
6
|
-
"version": "0.0.
|
6
|
+
"version": "0.0.24",
|
7
7
|
"private": false,
|
8
8
|
"main": "build/index.js",
|
9
9
|
"module": "build/index.js",
|
@@ -20,6 +20,7 @@
|
|
20
20
|
"dependencies": {
|
21
21
|
"camera-controls": "^1.34.1",
|
22
22
|
"core-js": "^3.21.0",
|
23
|
+
"geometric": "^2.2.10",
|
23
24
|
"hold-event": "^0.1.0",
|
24
25
|
"mobx": "^6.3.13",
|
25
26
|
"mobx-react-lite": "^3.2.3",
|