hart-estate-widget 0.0.34 → 0.0.37

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,16 +5,16 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.default = void 0;
7
7
 
8
+ require("core-js/modules/es.array.reduce.js");
9
+
8
10
  require("core-js/modules/es.regexp.exec.js");
9
11
 
10
- require("core-js/modules/es.string.match.js");
12
+ require("core-js/modules/es.string.replace.js");
11
13
 
12
- require("core-js/modules/es.array.reduce.js");
14
+ require("core-js/modules/web.dom-collections.iterator.js");
13
15
 
14
16
  require("core-js/modules/es.string.includes.js");
15
17
 
16
- require("core-js/modules/web.dom-collections.iterator.js");
17
-
18
18
  var _react = _interopRequireWildcard(require("react"));
19
19
 
20
20
  var _store = _interopRequireDefault(require("../store"));
@@ -45,15 +45,17 @@ const {
45
45
  DEVICEORIENTATION,
46
46
  ORBIT
47
47
  } = PANOLENS.CONTROLS;
48
+ const imgExtentions = ['.png', '.PNG', '.jpg', '.JPG'];
48
49
  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
50
 
52
51
  const getCameraFromSrc = (json, src) => {
53
52
  var _json$Floors$0$Camera;
54
53
 
55
- const cameraIdTimestamp = src.match(/(?<=CameraId)[\s\S]*?(?=\.png)/);
56
- const cameraId = "CameraId".concat(cameraIdTimestamp);
54
+ const cameraIdIndex = src.indexOf('CameraId');
55
+ if (cameraIdIndex === -1) return null;
56
+ const cameraId = imgExtentions.reduce((acc, extention) => {
57
+ return acc.replace(extention, '');
58
+ }, src.substring(cameraIdIndex));
57
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 => {
58
60
  let {
59
61
  ID
@@ -79,7 +81,14 @@ const createPanorama = (image, index, setLoadingState) => {
79
81
  const getPanoramas = (json, images, setLoadingState) => {
80
82
  if (!json) return images.map((image, index) => createPanorama(image, index, setLoadingState));
81
83
  return json.Floors[0].Units[0].Rooms.reduce((acc, jsonRoom, index) => {
82
- const roomImages = images.filter(img => img.includes(pathName + index));
84
+ const roomImages = images.filter(img => {
85
+ const panoramaIdIndex = img.indexOf(pathName);
86
+ if (panoramaIdIndex === -1) return false;
87
+ const panoramaId = imgExtentions.reduce((acc, extention) => {
88
+ return acc.replace(extention, '');
89
+ }, img.substring(panoramaIdIndex + pathName.length));
90
+ return Number(panoramaId) === index;
91
+ });
83
92
  if (!roomImages.length) return acc;
84
93
  roomImages.forEach(image => {
85
94
  const panorama = createPanorama(image, index, setLoadingState);
@@ -109,6 +118,7 @@ const getPanoramaRooms = (json, panoramas) => {
109
118
  };
110
119
  const currentRoom = json.Floors[0].Units[0].Rooms.find(room => room.ID === panorama['room_id']);
111
120
  let [left, top] = (0, _geometric.polygonMean)((0, _panoramaHelpers.getRoomCoordinates)(currentRoom, json.Floors[0].Walls, json.Vertices));
121
+ panorama['roomType'] = currentRoom.Type;
112
122
 
113
123
  if (!panorama.linkedSpots.length) {
114
124
  if (panorama.src.includes('_CameraId')) {
@@ -173,16 +183,18 @@ const connectPanorama = function connectPanorama(panorama, connectedPanorama, lo
173
183
  let isDoorLink = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : false;
174
184
  const locationX = location.Y - center[1];
175
185
  const locationY = location.X - center[0];
176
- const locationZ = isDoorLink ? -10 : -50;
177
- const icon = isDoorLink ? PANOLENS.DataImage.Door : PANOLENS.DataImage.Spot;
186
+ const locationZ = isDoorLink ? -10 : -100;
187
+ const icon = isDoorLink ? _doorIcon.default : _spotIcon.default;
188
+ const iconUrl = "".concat(icon, "?id=").concat(panorama['panorama_index'], "-").concat(panorama['panorama_id'], "-").concat(Math.random());
178
189
  const defaultScale = 20;
179
190
  const maxScale = 50;
180
191
  const defaultLength = 120;
181
192
  const length = (0, _geometric.lineLength)([[0, 0], [locationX, locationY]]);
182
193
  const scale = length / defaultLength * defaultScale;
183
194
  const finalScale = scale > maxScale ? maxScale : scale;
195
+ const resultScale = isDoorLink ? finalScale : finalScale - 15;
184
196
  const position = new THREE.Vector3(locationX, locationZ, locationY);
185
- panorama.link(connectedPanorama, position, finalScale, icon);
197
+ panorama.link(connectedPanorama, position, resultScale, iconUrl);
186
198
  };
187
199
 
188
200
  const initPanorama = () => {
@@ -199,11 +211,6 @@ const initPanorama = () => {
199
211
  };
200
212
 
201
213
  animate();
202
-
203
- if (DeviceOrientationEvent.requestPermission) {
204
- DeviceOrientationEvent.requestPermission().catch(() => console.log('Device motion not allowed'));
205
- }
206
-
207
214
  return {
208
215
  camera,
209
216
  controls
@@ -325,6 +332,7 @@ const PanoramaTab = _ref5 => {
325
332
  src: planImage,
326
333
  className: isMapActive ? 'active' : '',
327
334
  onClick: toggleMap,
335
+ onLoad: setScale,
328
336
  alt: "plan"
329
337
  }), !isMapDisabled && panoramaRooms.map((room, index) => /*#__PURE__*/_react.default.createElement("div", {
330
338
  key: index,
@@ -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.34",
6
+ "version": "0.0.37",
7
7
  "private": false,
8
8
  "main": "build/index.js",
9
9
  "module": "build/index.js",