hart-estate-widget 0.0.31 → 0.0.34

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
@@ -5,6 +5,10 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.default = void 0;
7
7
 
8
+ require("core-js/modules/es.regexp.exec.js");
9
+
10
+ require("core-js/modules/es.string.match.js");
11
+
8
12
  require("core-js/modules/es.array.reduce.js");
9
13
 
10
14
  require("core-js/modules/es.string.includes.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); }
@@ -38,6 +46,21 @@ const {
38
46
  ORBIT
39
47
  } = PANOLENS.CONTROLS;
40
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
+
52
+ const getCameraFromSrc = (json, src) => {
53
+ var _json$Floors$0$Camera;
54
+
55
+ const cameraIdTimestamp = src.match(/(?<=CameraId)[\s\S]*?(?=\.png)/);
56
+ const cameraId = "CameraId".concat(cameraIdTimestamp);
57
+ 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
+ let {
59
+ ID
60
+ } = _ref;
61
+ return ID === cameraId;
62
+ })) || null;
63
+ };
41
64
 
42
65
  const createPanorama = (image, index, setLoadingState) => {
43
66
  const panorama = new PANOLENS.ImagePanorama(image);
@@ -56,17 +79,19 @@ const createPanorama = (image, index, setLoadingState) => {
56
79
  const getPanoramas = (json, images, setLoadingState) => {
57
80
  if (!json) return images.map((image, index) => createPanorama(image, index, setLoadingState));
58
81
  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
-
82
+ const roomImages = images.filter(img => img.includes(pathName + index));
83
+ if (!roomImages.length) return acc;
84
+ roomImages.forEach(image => {
85
+ const panorama = createPanorama(image, index, setLoadingState);
86
+ panorama['room_images'] = roomImages;
87
+ panorama['room_id'] = jsonRoom.ID;
88
+
89
+ if (panorama['room_id'] === _store.default.hallRoomId) {
90
+ acc.unshift(panorama);
91
+ } else {
92
+ acc.push(panorama);
93
+ }
94
+ });
70
95
  return acc;
71
96
  }, []);
72
97
  };
@@ -83,9 +108,18 @@ const getPanoramaRooms = (json, panoramas) => {
83
108
  top: 0
84
109
  };
85
110
  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));
111
+ let [left, top] = (0, _geometric.polygonMean)((0, _panoramaHelpers.getRoomCoordinates)(currentRoom, json.Floors[0].Walls, json.Vertices));
87
112
 
88
113
  if (!panorama.linkedSpots.length) {
114
+ if (panorama.src.includes('_CameraId')) {
115
+ const currentCamera = getCameraFromSrc(json, panorama.src);
116
+ const {
117
+ Location
118
+ } = currentCamera;
119
+ left = Location.X;
120
+ top = Location.Y;
121
+ }
122
+
89
123
  setPanoramaLinks(json, currentRoom, [left, top], panorama, panoramas);
90
124
  }
91
125
 
@@ -100,11 +134,23 @@ const getPanoramaRooms = (json, panoramas) => {
100
134
  };
101
135
 
102
136
  const setPanoramaLinks = (json, currentRoom, center, panorama, panoramas) => {
103
- json.Floors[0].Doors.forEach(_ref => {
137
+ panorama['room_images'].forEach(image => {
138
+ if (image === panorama.src) return;
139
+ const connectedPanorama = panoramas.find(_ref2 => {
140
+ let {
141
+ src
142
+ } = _ref2;
143
+ return src === image;
144
+ });
145
+ const currentCamera = getCameraFromSrc(json, connectedPanorama.src);
146
+ if (!currentCamera) return;
147
+ connectPanorama(panorama, connectedPanorama, currentCamera.Location, center, false);
148
+ });
149
+ json.Floors[0].Doors.forEach(_ref3 => {
104
150
  let {
105
151
  Location,
106
152
  Walls
107
- } = _ref;
153
+ } = _ref3;
108
154
  if (!Walls.some(doorWallId => currentRoom.Walls.some(roomWallId => roomWallId === doorWallId))) return;
109
155
  const connectedRoom = json.Floors[0].Units[0].Rooms.find(room => {
110
156
  const roomHasSameWall = room.Walls.some(roomWallId => Walls.some(doorWallId => roomWallId === doorWallId));
@@ -112,26 +158,33 @@ const setPanoramaLinks = (json, currentRoom, center, panorama, panoramas) => {
112
158
  return roomHasSameWall && !isSameRoom;
113
159
  });
114
160
  if (!connectedRoom) return;
115
- const connectedPanorama = panoramas.find(_ref2 => {
161
+ const connectedPanorama = panoramas.find(_ref4 => {
116
162
  let {
117
163
  room_id
118
- } = _ref2;
164
+ } = _ref4;
119
165
  return room_id === connectedRoom.ID;
120
166
  });
121
167
  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);
168
+ connectPanorama(panorama, connectedPanorama, Location, center, true);
132
169
  });
133
170
  };
134
171
 
172
+ const connectPanorama = function connectPanorama(panorama, connectedPanorama, location, center) {
173
+ let isDoorLink = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : false;
174
+ const locationX = location.Y - center[1];
175
+ const locationY = location.X - center[0];
176
+ const locationZ = isDoorLink ? -10 : -50;
177
+ const icon = isDoorLink ? PANOLENS.DataImage.Door : PANOLENS.DataImage.Spot;
178
+ const defaultScale = 20;
179
+ const maxScale = 50;
180
+ const defaultLength = 120;
181
+ const length = (0, _geometric.lineLength)([[0, 0], [locationX, locationY]]);
182
+ const scale = length / defaultLength * defaultScale;
183
+ const finalScale = scale > maxScale ? maxScale : scale;
184
+ const position = new THREE.Vector3(locationX, locationZ, locationY);
185
+ panorama.link(connectedPanorama, position, finalScale, icon);
186
+ };
187
+
135
188
  const initPanorama = () => {
136
189
  let camera = new THREE.PerspectiveCamera(75, window.innerWidth / window.innerHeight, 1, 1100);
137
190
  let controls = new _threeDeviceOrientation.default(camera);
@@ -157,12 +210,12 @@ const initPanorama = () => {
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);
@@ -40,7 +40,9 @@ class Store {
40
40
  return json.Floors[0].Doors.some(door => door.Walls.some(doorWallId => doorWallId === wallId));
41
41
  });
42
42
  const exteriorDoor = json.Floors[0].Doors.find(door => {
43
- return door.Walls.some(doorWallId => json.Floors[0].ExteriorWalls.some(exteriorWallId => exteriorWallId === doorWallId));
43
+ const isSameDoor = door.Walls.some(doorWallId => doorWallId === exteriorWallWithDoor);
44
+ const isExterior = door.Walls.some(doorWallId => json.Floors[0].ExteriorWalls.some(exteriorWallId => exteriorWallId === doorWallId));
45
+ return isSameDoor && isExterior;
44
46
  });
45
47
  const wallWithExteriorDoor = exteriorDoor.Walls.find(wallId => wallId !== exteriorWallWithDoor);
46
48
  const room = json.Floors[0].Units[0].Rooms.find(_ref => {
@@ -3,7 +3,7 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.getScale = exports.getRoomCoordinates = exports.findWallVertices = void 0;
6
+ exports.imageToUri = exports.getScale = exports.getRoomCoordinates = exports.findWallVertices = void 0;
7
7
 
8
8
  require("core-js/modules/es.array.reduce.js");
9
9
 
@@ -49,4 +49,21 @@ const getScale = (image, json) => {
49
49
  };
50
50
  };
51
51
 
52
- exports.getScale = getScale;
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;
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.31",
6
+ "version": "0.0.34",
7
7
  "private": false,
8
8
  "main": "build/index.js",
9
9
  "module": "build/index.js",