hart-estate-widget 0.0.33 → 0.0.36

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,
@@ -5,11 +5,11 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.default = void 0;
7
7
 
8
- require("core-js/modules/es.regexp.exec.js");
8
+ require("core-js/modules/es.array.reduce.js");
9
9
 
10
- require("core-js/modules/es.string.match.js");
10
+ require("core-js/modules/es.regexp.exec.js");
11
11
 
12
- require("core-js/modules/es.array.reduce.js");
12
+ require("core-js/modules/es.string.replace.js");
13
13
 
14
14
  require("core-js/modules/es.string.includes.js");
15
15
 
@@ -46,18 +46,22 @@ const {
46
46
  ORBIT
47
47
  } = PANOLENS.CONTROLS;
48
48
  const pathName = 'Panorama_0_0_';
49
- (0, _panoramaHelpers.imageToUri)(_spotIcon.default, img => PANOLENS.DataImage.Spot = img);
50
- (0, _panoramaHelpers.imageToUri)(_doorIcon.default, img => PANOLENS.DataImage.Door = img);
51
49
 
52
50
  const getCameraFromSrc = (json, src) => {
53
- const cameraIdTimestamp = src.match(/(?<=CameraId)[\s\S]*?(?=\.png)/);
54
- const cameraId = "CameraId".concat(cameraIdTimestamp);
55
- return json.Floors[0].CameraPoints.find(_ref => {
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 => {
56
60
  let {
57
61
  ID
58
62
  } = _ref;
59
63
  return ID === cameraId;
60
- });
64
+ })) || null;
61
65
  };
62
66
 
63
67
  const createPanorama = (image, index, setLoadingState) => {
@@ -107,6 +111,7 @@ const getPanoramaRooms = (json, panoramas) => {
107
111
  };
108
112
  const currentRoom = json.Floors[0].Units[0].Rooms.find(room => room.ID === panorama['room_id']);
109
113
  let [left, top] = (0, _geometric.polygonMean)((0, _panoramaHelpers.getRoomCoordinates)(currentRoom, json.Floors[0].Walls, json.Vertices));
114
+ panorama['roomType'] = currentRoom.Type;
110
115
 
111
116
  if (!panorama.linkedSpots.length) {
112
117
  if (panorama.src.includes('_CameraId')) {
@@ -141,6 +146,7 @@ const setPanoramaLinks = (json, currentRoom, center, panorama, panoramas) => {
141
146
  return src === image;
142
147
  });
143
148
  const currentCamera = getCameraFromSrc(json, connectedPanorama.src);
149
+ if (!currentCamera) return;
144
150
  connectPanorama(panorama, connectedPanorama, currentCamera.Location, center, false);
145
151
  });
146
152
  json.Floors[0].Doors.forEach(_ref3 => {
@@ -170,16 +176,18 @@ const connectPanorama = function connectPanorama(panorama, connectedPanorama, lo
170
176
  let isDoorLink = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : false;
171
177
  const locationX = location.Y - center[1];
172
178
  const locationY = location.X - center[0];
173
- const locationZ = isDoorLink ? -10 : -50;
174
- const icon = isDoorLink ? PANOLENS.DataImage.Door : PANOLENS.DataImage.Spot;
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());
175
182
  const defaultScale = 20;
176
183
  const maxScale = 50;
177
184
  const defaultLength = 120;
178
185
  const length = (0, _geometric.lineLength)([[0, 0], [locationX, locationY]]);
179
186
  const scale = length / defaultLength * defaultScale;
180
187
  const finalScale = scale > maxScale ? maxScale : scale;
188
+ const resultScale = isDoorLink ? finalScale : finalScale - 15;
181
189
  const position = new THREE.Vector3(locationX, locationZ, locationY);
182
- panorama.link(connectedPanorama, position, finalScale, icon);
190
+ panorama.link(connectedPanorama, position, resultScale, iconUrl);
183
191
  };
184
192
 
185
193
  const initPanorama = () => {
@@ -196,11 +204,6 @@ const initPanorama = () => {
196
204
  };
197
205
 
198
206
  animate();
199
-
200
- if (DeviceOrientationEvent.requestPermission) {
201
- DeviceOrientationEvent.requestPermission().catch(() => console.log('Device motion not allowed'));
202
- }
203
-
204
207
  return {
205
208
  camera,
206
209
  controls
@@ -3,7 +3,7 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.imageToUri = exports.getScale = exports.getRoomCoordinates = exports.findWallVertices = void 0;
6
+ exports.getScale = exports.getRoomCoordinates = exports.findWallVertices = void 0;
7
7
 
8
8
  require("core-js/modules/es.array.reduce.js");
9
9
 
@@ -49,21 +49,4 @@ const getScale = (image, json) => {
49
49
  };
50
50
  };
51
51
 
52
- exports.getScale = getScale;
53
-
54
- const imageToUri = (url, callback) => {
55
- const canvas = document.createElement('canvas');
56
- const ctx = canvas.getContext('2d');
57
- const image = new Image();
58
- image.src = url;
59
-
60
- image.onload = () => {
61
- canvas.width = image.width;
62
- canvas.height = image.height;
63
- ctx.drawImage(image, 0, 0);
64
- callback(canvas.toDataURL('image/png'));
65
- canvas.remove();
66
- };
67
- };
68
-
69
- exports.imageToUri = imageToUri;
52
+ exports.getScale = getScale;
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.33",
6
+ "version": "0.0.36",
7
7
  "private": false,
8
8
  "main": "build/index.js",
9
9
  "module": "build/index.js",