hart-estate-widget 0.0.32 → 0.0.35

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.
Binary file
Binary file
@@ -7,6 +7,8 @@ exports.default = void 0;
7
7
 
8
8
  require("core-js/modules/web.dom-collections.iterator.js");
9
9
 
10
+ require("core-js/modules/es.promise.js");
11
+
10
12
  var _react = _interopRequireWildcard(require("react"));
11
13
 
12
14
  var _mobxReactLite = require("mobx-react-lite");
@@ -56,6 +58,19 @@ const Application = (0, _mobxReactLite.observer)(_ref => {
56
58
  _store.default.dispatchEvent('enterComponent');
57
59
  };
58
60
 
61
+ const openPanorama = async () => {
62
+ try {
63
+ if (DeviceOrientationEvent.requestPermission) {
64
+ await DeviceOrientationEvent.requestPermission();
65
+ }
66
+ } catch (e) {
67
+ console.error(e);
68
+ console.log('Device motion not allowed');
69
+ }
70
+
71
+ hideTabPanes();
72
+ };
73
+
59
74
  const tabsList = {
60
75
  'planImage': /*#__PURE__*/_react.default.createElement(_ImageTab.default, {
61
76
  image: config.planImage,
@@ -85,7 +100,7 @@ const Application = (0, _mobxReactLite.observer)(_ref => {
85
100
  image: _store.default.hallRoomImage,
86
101
  title: "Panoramic tour",
87
102
  text: ['Use mouse to rotate', 'To move through the rooms, click on the layout thumbnail'],
88
- onStart: hideTabPanes
103
+ onStart: openPanorama
89
104
  }, /*#__PURE__*/_react.default.createElement(_PanoramaTab.default, {
90
105
  json: config.json,
91
106
  planImage: config.planImage,
@@ -7,6 +7,10 @@ exports.default = void 0;
7
7
 
8
8
  require("core-js/modules/es.array.reduce.js");
9
9
 
10
+ require("core-js/modules/es.regexp.exec.js");
11
+
12
+ require("core-js/modules/es.string.replace.js");
13
+
10
14
  require("core-js/modules/es.string.includes.js");
11
15
 
12
16
  require("core-js/modules/web.dom-collections.iterator.js");
@@ -27,6 +31,10 @@ var _panoramaHelpers = require("../utils/panoramaHelpers");
27
31
 
28
32
  var _geometric = require("geometric");
29
33
 
34
+ var _spotIcon = _interopRequireDefault(require("../assets/img/spot-icon.png"));
35
+
36
+ var _doorIcon = _interopRequireDefault(require("../assets/img/door-icon.png"));
37
+
30
38
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
31
39
 
32
40
  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); }
@@ -39,6 +47,23 @@ const {
39
47
  } = PANOLENS.CONTROLS;
40
48
  const pathName = 'Panorama_0_0_';
41
49
 
50
+ const getCameraFromSrc = (json, src) => {
51
+ var _json$Floors$0$Camera;
52
+
53
+ const cameraIdIndex = src.indexOf('CameraId');
54
+ const imgExtentions = ['.png', '.PNG', '.jpg', '.JPG'];
55
+ if (cameraIdIndex === -1) return null;
56
+ const cameraId = imgExtentions.reduce((acc, extention) => {
57
+ return acc.replace(extention, '');
58
+ }, src.substring(cameraIdIndex));
59
+ return ((_json$Floors$0$Camera = json.Floors[0].CameraPoints) === null || _json$Floors$0$Camera === void 0 ? void 0 : _json$Floors$0$Camera.find(_ref => {
60
+ let {
61
+ ID
62
+ } = _ref;
63
+ return ID === cameraId;
64
+ })) || null;
65
+ };
66
+
42
67
  const createPanorama = (image, index, setLoadingState) => {
43
68
  const panorama = new PANOLENS.ImagePanorama(image);
44
69
  panorama['panorama_id'] = index + 1;
@@ -56,17 +81,19 @@ const createPanorama = (image, index, setLoadingState) => {
56
81
  const getPanoramas = (json, images, setLoadingState) => {
57
82
  if (!json) return images.map((image, index) => createPanorama(image, index, setLoadingState));
58
83
  return json.Floors[0].Units[0].Rooms.reduce((acc, jsonRoom, index) => {
59
- const image = images.find(img => img.includes(pathName + index));
60
- if (!image) return acc;
61
- const panorama = createPanorama(image, index, setLoadingState);
62
- panorama['room_id'] = jsonRoom.ID;
63
-
64
- if (panorama['room_id'] === _store.default.hallRoomId) {
65
- acc.unshift(panorama);
66
- } else {
67
- acc.push(panorama);
68
- }
69
-
84
+ const roomImages = images.filter(img => img.includes(pathName + index));
85
+ if (!roomImages.length) return acc;
86
+ roomImages.forEach(image => {
87
+ const panorama = createPanorama(image, index, setLoadingState);
88
+ panorama['room_images'] = roomImages;
89
+ panorama['room_id'] = jsonRoom.ID;
90
+
91
+ if (panorama['room_id'] === _store.default.hallRoomId) {
92
+ acc.unshift(panorama);
93
+ } else {
94
+ acc.push(panorama);
95
+ }
96
+ });
70
97
  return acc;
71
98
  }, []);
72
99
  };
@@ -83,9 +110,19 @@ const getPanoramaRooms = (json, panoramas) => {
83
110
  top: 0
84
111
  };
85
112
  const currentRoom = json.Floors[0].Units[0].Rooms.find(room => room.ID === panorama['room_id']);
86
- const [left, top] = (0, _geometric.polygonMean)((0, _panoramaHelpers.getRoomCoordinates)(currentRoom, json.Floors[0].Walls, json.Vertices));
113
+ let [left, top] = (0, _geometric.polygonMean)((0, _panoramaHelpers.getRoomCoordinates)(currentRoom, json.Floors[0].Walls, json.Vertices));
114
+ panorama['roomType'] = currentRoom.Type;
87
115
 
88
116
  if (!panorama.linkedSpots.length) {
117
+ if (panorama.src.includes('_CameraId')) {
118
+ const currentCamera = getCameraFromSrc(json, panorama.src);
119
+ const {
120
+ Location
121
+ } = currentCamera;
122
+ left = Location.X;
123
+ top = Location.Y;
124
+ }
125
+
89
126
  setPanoramaLinks(json, currentRoom, [left, top], panorama, panoramas);
90
127
  }
91
128
 
@@ -100,11 +137,23 @@ const getPanoramaRooms = (json, panoramas) => {
100
137
  };
101
138
 
102
139
  const setPanoramaLinks = (json, currentRoom, center, panorama, panoramas) => {
103
- json.Floors[0].Doors.forEach(_ref => {
140
+ panorama['room_images'].forEach(image => {
141
+ if (image === panorama.src) return;
142
+ const connectedPanorama = panoramas.find(_ref2 => {
143
+ let {
144
+ src
145
+ } = _ref2;
146
+ return src === image;
147
+ });
148
+ const currentCamera = getCameraFromSrc(json, connectedPanorama.src);
149
+ if (!currentCamera) return;
150
+ connectPanorama(panorama, connectedPanorama, currentCamera.Location, center, false);
151
+ });
152
+ json.Floors[0].Doors.forEach(_ref3 => {
104
153
  let {
105
154
  Location,
106
155
  Walls
107
- } = _ref;
156
+ } = _ref3;
108
157
  if (!Walls.some(doorWallId => currentRoom.Walls.some(roomWallId => roomWallId === doorWallId))) return;
109
158
  const connectedRoom = json.Floors[0].Units[0].Rooms.find(room => {
110
159
  const roomHasSameWall = room.Walls.some(roomWallId => Walls.some(doorWallId => roomWallId === doorWallId));
@@ -112,26 +161,35 @@ const setPanoramaLinks = (json, currentRoom, center, panorama, panoramas) => {
112
161
  return roomHasSameWall && !isSameRoom;
113
162
  });
114
163
  if (!connectedRoom) return;
115
- const connectedPanorama = panoramas.find(_ref2 => {
164
+ const connectedPanorama = panoramas.find(_ref4 => {
116
165
  let {
117
166
  room_id
118
- } = _ref2;
167
+ } = _ref4;
119
168
  return room_id === connectedRoom.ID;
120
169
  });
121
170
  if (!connectedPanorama) return;
122
- const locationX = Location.Y - center[1];
123
- const locationY = Location.X - center[0];
124
- const defaultScale = 20;
125
- const maxScale = 50;
126
- const defaultLength = 120;
127
- const length = (0, _geometric.lineLength)([[0, 0], [locationX, locationY]]);
128
- const scale = length / defaultLength * defaultScale;
129
- const finalScale = scale > maxScale ? maxScale : scale;
130
- const position = new THREE.Vector3(locationX, -10, locationY);
131
- panorama.link(connectedPanorama, position, finalScale);
171
+ connectPanorama(panorama, connectedPanorama, Location, center, true);
132
172
  });
133
173
  };
134
174
 
175
+ const connectPanorama = function connectPanorama(panorama, connectedPanorama, location, center) {
176
+ let isDoorLink = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : false;
177
+ const locationX = location.Y - center[1];
178
+ const locationY = location.X - center[0];
179
+ const locationZ = isDoorLink ? -10 : -100;
180
+ const icon = isDoorLink ? _doorIcon.default : _spotIcon.default;
181
+ const iconUrl = "".concat(icon, "?id=").concat(panorama['panorama_index'], "-").concat(panorama['panorama_id'], "-").concat(Math.random());
182
+ const defaultScale = 20;
183
+ const maxScale = 50;
184
+ const defaultLength = 120;
185
+ const length = (0, _geometric.lineLength)([[0, 0], [locationX, locationY]]);
186
+ const scale = length / defaultLength * defaultScale;
187
+ const finalScale = scale > maxScale ? maxScale : scale;
188
+ const resultScale = isDoorLink ? finalScale : finalScale - 15;
189
+ const position = new THREE.Vector3(locationX, locationZ, locationY);
190
+ panorama.link(connectedPanorama, position, resultScale, iconUrl);
191
+ };
192
+
135
193
  const initPanorama = () => {
136
194
  let camera = new THREE.PerspectiveCamera(75, window.innerWidth / window.innerHeight, 1, 1100);
137
195
  let controls = new _threeDeviceOrientation.default(camera);
@@ -146,23 +204,18 @@ const initPanorama = () => {
146
204
  };
147
205
 
148
206
  animate();
149
-
150
- if (DeviceOrientationEvent.requestPermission) {
151
- DeviceOrientationEvent.requestPermission().catch(() => console.log('Device motion not allowed'));
152
- }
153
-
154
207
  return {
155
208
  camera,
156
209
  controls
157
210
  };
158
211
  };
159
212
 
160
- const PanoramaTab = _ref3 => {
213
+ const PanoramaTab = _ref5 => {
161
214
  let {
162
215
  json,
163
216
  planImage,
164
217
  images
165
- } = _ref3;
218
+ } = _ref5;
166
219
  const [menuState, setMenuState] = (0, _react.useState)(false);
167
220
  const [loadingState, setLoadingState] = (0, _react.useState)(true);
168
221
  const [isMapActive, setMapState] = (0, _react.useState)(false);
@@ -240,10 +293,10 @@ const PanoramaTab = _ref3 => {
240
293
  });
241
294
  panoramas.forEach(panorama => {
242
295
  if (!panorama.panorama_id) return;
243
- panorama.addEventListener('enter', _ref4 => {
296
+ panorama.addEventListener('enter', _ref6 => {
244
297
  let {
245
298
  target
246
- } = _ref4;
299
+ } = _ref6;
247
300
  return setCurrentRoomIndex(target['panorama_index']);
248
301
  });
249
302
  newViewer.add(panorama);
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.32",
6
+ "version": "0.0.35",
7
7
  "private": false,
8
8
  "main": "build/index.js",
9
9
  "module": "build/index.js",