@wework/floormap-sdk
Advanced tools
Comparing version 1.1.9 to 1.1.10-rc2
@@ -219,3 +219,2 @@ import Building from 'models/Building' | ||
expect(mockLoadBuilding.mock.calls[0][0]).toEqual('buildingId-1') | ||
expect(mockLoadBuilding).toHaveBeenCalledWith('buildingId-1') | ||
expect(mockLoadFloorAndSpaces).toHaveBeenCalledWith('floorId-1') | ||
@@ -228,3 +227,2 @@ }) | ||
expect(mockLoadBuilding.mock.calls[0][0]).toEqual('buildingId-1') | ||
expect(mockLoadBuilding).toHaveBeenCalledWith('buildingId-1') | ||
expect(mockLoadFloorAndSpaces).toHaveBeenCalledTimes(0) | ||
@@ -236,5 +234,5 @@ }) | ||
expect(mockLoadBuilding).toHaveBeenCalledWith('buildingId-1') | ||
expect(mockLoadBuilding.mock.calls[0][0]).toEqual('buildingId-1') | ||
expect(mockLoadFloorAndSpaces).toHaveBeenCalledWith('floorId-1') | ||
}) | ||
}) |
@@ -0,1 +1,2 @@ | ||
import _extends from "@babel/runtime/helpers/esm/extends"; | ||
import _regeneratorRuntime from "@babel/runtime/regenerator"; | ||
@@ -87,3 +88,3 @@ import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator"; | ||
/*#__PURE__*/ | ||
_regeneratorRuntime.mark(function _callee2(buildingUUID) { | ||
_regeneratorRuntime.mark(function _callee2(buildingUUID, options) { | ||
var response, meta, _response$data, data, _response$included2, included, building; | ||
@@ -95,8 +96,12 @@ | ||
case 0: | ||
_context2.next = 2; | ||
return this.client.get("/buildings/" + buildingUUID, { | ||
if (options === void 0) { | ||
options = {}; | ||
} | ||
_context2.next = 3; | ||
return this.client.get("/buildings/" + buildingUUID, _extends({}, options, { | ||
include: 'floors' | ||
}); | ||
})); | ||
case 2: | ||
case 3: | ||
response = _context2.sent; | ||
@@ -106,3 +111,3 @@ meta = response.meta, _response$data = response.data, data = _response$data === void 0 ? {} : _response$data, _response$included2 = response.included, included = _response$included2 === void 0 ? [] : _response$included2; | ||
if (meta.success) { | ||
_context2.next = 6; | ||
_context2.next = 7; | ||
break; | ||
@@ -113,7 +118,7 @@ } | ||
case 6: | ||
case 7: | ||
building = new Building(data, included); | ||
return _context2.abrupt("return", building); | ||
case 8: | ||
case 9: | ||
case "end": | ||
@@ -126,3 +131,3 @@ return _context2.stop(); | ||
function loadBuilding(_x2) { | ||
function loadBuilding(_x2, _x3) { | ||
return _loadBuilding.apply(this, arguments); | ||
@@ -129,0 +134,0 @@ } |
@@ -24,3 +24,3 @@ import _regeneratorRuntime from "@babel/runtime/regenerator"; | ||
_regeneratorRuntime.mark(function _callee(buildingId, options) { | ||
var _options, _options$ignoreCache, ignoreCache, cachedBuilding, building; | ||
var _options, _options$ignoreCache, ignoreCache, _options$reload, reload, reqOpts, cachedBuilding, building; | ||
@@ -35,7 +35,13 @@ return _regeneratorRuntime.wrap(function _callee$(_context) { | ||
_options = options, _options$ignoreCache = _options.ignoreCache, ignoreCache = _options$ignoreCache === void 0 ? false : _options$ignoreCache; | ||
_options = options, _options$ignoreCache = _options.ignoreCache, ignoreCache = _options$ignoreCache === void 0 ? false : _options$ignoreCache, _options$reload = _options.reload, reload = _options$reload === void 0 ? false : _options$reload; | ||
reqOpts = {}; | ||
if (reload) { | ||
reqOpts.reload = true; | ||
} | ||
cachedBuilding = _this.buildingById.get(buildingId); | ||
if (!(cachedBuilding && !ignoreCache)) { | ||
_context.next = 5; | ||
_context.next = 7; | ||
break; | ||
@@ -46,7 +52,7 @@ } | ||
case 5: | ||
_context.next = 7; | ||
return _this.loader.loadBuilding(buildingId); | ||
case 7: | ||
_context.next = 9; | ||
return _this.loader.loadBuilding(buildingId, reqOpts); | ||
case 7: | ||
case 9: | ||
building = _context.sent; | ||
@@ -60,3 +66,3 @@ | ||
case 11: | ||
case 13: | ||
case "end": | ||
@@ -152,2 +158,12 @@ return _context.stop(); | ||
_this.objectById.set(space.uuid, space); | ||
var objects = _this.objectsByRoom.get(space.spaceUUID); | ||
if (!objects) { | ||
objects = []; | ||
_this.objectsByRoom.set(space.spaceUUID, objects); | ||
} | ||
objects.push(space); | ||
} | ||
@@ -174,2 +190,3 @@ | ||
this.spaceByAlias = new Map(); | ||
this.objectsByRoom = new Map(); | ||
} // - Private | ||
@@ -365,2 +382,6 @@ | ||
_proto.getObjectsBySpaceId = function getObjectsBySpaceId(id) { | ||
return this.objectsByRoom.get(id) || []; | ||
}; | ||
_proto.updateSpaceData = function updateSpaceData(id, data) { | ||
@@ -393,2 +414,3 @@ var space = this.spaceById.get(id) || this.objectById.get(id); | ||
this.spaceByAlias = new Map(); | ||
this.objectsByRoom = new Map(); | ||
}; | ||
@@ -395,0 +417,0 @@ |
@@ -15,3 +15,3 @@ import _regeneratorRuntime from "@babel/runtime/regenerator"; | ||
import { getCenter, applyInstancing } from '@wework/floormap-utils'; | ||
import { getSpaceRenderObject, getObjectRenderObject } from "../utils/render"; | ||
import { getSpaceRenderObject, getObjectRenderObject, HOT_DESK_TYPES } from "../utils/render"; | ||
import EventDispatcher from "../utils/EventDispatcher"; | ||
@@ -859,2 +859,5 @@ import FloorMapError from "../errors/FloorMapError"; | ||
/** | ||
* | ||
* @deprecated Use .updateSpace(spaceId, data) instead | ||
* | ||
* Update space/object data with given id. | ||
@@ -868,2 +871,14 @@ * This function will trigger `datachange` event on the map | ||
_proto.updateData = function updateData(spaceOrObjectId, data) { | ||
this.updateSpace(spaceOrObjectId, data); | ||
} | ||
/** | ||
* Update space/object data with given id. | ||
* This function will trigger `datachange` event on the map | ||
* @param {string} spaceOrObjectId - id of space/object to be updated | ||
* @param {Object} data - Data to update | ||
*/ | ||
; | ||
_proto.updateSpace = function updateSpace(spaceOrObjectId, data) { | ||
var previousData = this.getSpaceById(spaceOrObjectId); | ||
var newData = this.datasource.updateSpaceData(spaceOrObjectId, data); | ||
@@ -875,2 +890,3 @@ | ||
this.refreshSpace(newData, previousData); | ||
var eventPayload = { | ||
@@ -926,3 +942,4 @@ id: spaceOrObjectId, | ||
return this.datasource.loadBuilding(buildingId, { | ||
ignoreCache: true | ||
ignoreCache: true, | ||
reload: true | ||
}); | ||
@@ -954,3 +971,98 @@ | ||
return refreshBuilding; | ||
}() | ||
}(); | ||
_proto.refreshSpace = function refreshSpace(space, previousData) { | ||
// We don't need to rerender object | ||
if (space.type === 'object') { | ||
return; | ||
} // For space, we don't need to remove, just get new style and apply | ||
// 1. Get a new base style from utils based on new space data | ||
// 2. Set base style to existing style of the space | ||
var _getSpaceRenderObject = getSpaceRenderObject(space), | ||
spaceRenderObject = _getSpaceRenderObject[0], | ||
rest = _getSpaceRenderObject.slice(1); | ||
var style = this.styleManager.getStyleById(space.uuid); | ||
if (style) { | ||
style.setBaseStyle(spaceRenderObject.style || {}); | ||
spaceRenderObject.style = style.getStyle(); | ||
} // 3. draw space with new base style | ||
this.renderer.remove(space.uuid + "_SPRITE"); | ||
this.renderer.draw([spaceRenderObject].concat(rest), true); // Space type change from hot desk types to non-hot-desk-types or vice versa | ||
// We have to rerender all desks/chairs inside the room | ||
if (HOT_DESK_TYPES.includes(space.subType) !== HOT_DESK_TYPES.includes(previousData.subType)) { | ||
var objects = this.getObjectsByFloorId(); | ||
if (!objects || !objects.length) { | ||
return; | ||
} | ||
var renderingObjects = []; // eslint-disable-next-line no-restricted-syntax | ||
for (var _iterator2 = objects, _isArray2 = Array.isArray(_iterator2), _i2 = 0, _iterator2 = _isArray2 ? _iterator2 : _iterator2[Symbol.iterator]();;) { | ||
var _ref5; | ||
if (_isArray2) { | ||
if (_i2 >= _iterator2.length) break; | ||
_ref5 = _iterator2[_i2++]; | ||
} else { | ||
_i2 = _iterator2.next(); | ||
if (_i2.done) break; | ||
_ref5 = _i2.value; | ||
} | ||
var object = _ref5; | ||
var parentSpace = this.datasource.getSpaceById(object.spaceUUID); | ||
var objs = getObjectRenderObject(object, parentSpace); // utils sometime return undefined for unknown type | ||
if (!objs) { | ||
return; | ||
} | ||
var renderObject = objs[0], | ||
restObjects = objs.slice(1); | ||
var objectStyle = this.styleManager.getStyleById(renderObject.id); | ||
if (objectStyle) { | ||
renderObject.style = objectStyle.getStyle(); | ||
} // Reassign properties from current objects | ||
var prevObjectOpts = this.renderer.getRenderObject(renderObject.id); | ||
if (prevObjectOpts) { | ||
renderObject.interactable = prevObjectOpts.interactable; | ||
renderObject.visible = prevObjectOpts.visible; | ||
} // Always show if parent is dedicated desk | ||
if (parentSpace) { | ||
var isDedicatedRoomType = DEDICATED_ROOM_TYPES.includes(parentSpace.subType); | ||
if (isDedicatedRoomType) { | ||
renderObject.visible = true; | ||
} | ||
} | ||
renderingObjects.push.apply(renderingObjects, [renderObject].concat(restObjects)); | ||
} // Remove current desks and chairs | ||
this.renderer.removeInstancedMesh('CHAIRS'); | ||
this.renderer.removeInstancedMesh('TABLES'); | ||
this.renderer.removeInstancedMesh('HOTDESK_TABLES'); | ||
this.renderer.removeInstancedMesh('CHAIRS_OUTLINE'); | ||
this.renderer.removeInstancedMesh('TABLES_OUTLINE'); | ||
this.renderer.removeInstancedMesh('HOTDESK_TABLES_OUTLINE'); // Apply instancing | ||
applyInstancing(renderingObjects, this.renderer); | ||
this.renderer.draw(renderingObjects, true); | ||
} | ||
} | ||
/** @private */ | ||
@@ -1238,6 +1350,6 @@ ; | ||
_proto.setCenter = function setCenter(_ref5) { | ||
var x = _ref5.x, | ||
y = _ref5.y, | ||
z = _ref5.z; | ||
_proto.setCenter = function setCenter(_ref6) { | ||
var x = _ref6.x, | ||
y = _ref6.y, | ||
z = _ref6.z; | ||
this.renderer.setCameraViewPoint({ | ||
@@ -1351,20 +1463,3 @@ position: { | ||
for (var _iterator2 = this.hooks.onRender, _isArray2 = Array.isArray(_iterator2), _i2 = 0, _iterator2 = _isArray2 ? _iterator2 : _iterator2[Symbol.iterator]();;) { | ||
var _ref6; | ||
if (_isArray2) { | ||
if (_i2 >= _iterator2.length) break; | ||
_ref6 = _iterator2[_i2++]; | ||
} else { | ||
_i2 = _iterator2.next(); | ||
if (_i2.done) break; | ||
_ref6 = _i2.value; | ||
} | ||
var listener = _ref6; | ||
listener(payload); | ||
} // eslint-disable-next-line no-restricted-syntax | ||
for (var _iterator3 = spaceRenderObjects, _isArray3 = Array.isArray(_iterator3), _i3 = 0, _iterator3 = _isArray3 ? _iterator3 : _iterator3[Symbol.iterator]();;) { | ||
for (var _iterator3 = this.hooks.onRender, _isArray3 = Array.isArray(_iterator3), _i3 = 0, _iterator3 = _isArray3 ? _iterator3 : _iterator3[Symbol.iterator]();;) { | ||
var _ref7; | ||
@@ -1381,12 +1476,8 @@ | ||
var object = _ref7; | ||
var style = this.styleManager.getStyleById(object.id); | ||
if (style) { | ||
object.style = style.getStyle(); | ||
} | ||
var listener = _ref7; | ||
listener(payload); | ||
} // eslint-disable-next-line no-restricted-syntax | ||
for (var _iterator4 = renderObjects, _isArray4 = Array.isArray(_iterator4), _i4 = 0, _iterator4 = _isArray4 ? _iterator4 : _iterator4[Symbol.iterator]();;) { | ||
for (var _iterator4 = spaceRenderObjects, _isArray4 = Array.isArray(_iterator4), _i4 = 0, _iterator4 = _isArray4 ? _iterator4 : _iterator4[Symbol.iterator]();;) { | ||
var _ref8; | ||
@@ -1403,4 +1494,25 @@ | ||
var _object = _ref8; | ||
var object = _ref8; | ||
var style = this.styleManager.getStyleById(object.id); | ||
if (style) { | ||
object.style = style.getStyle(); | ||
} | ||
} // eslint-disable-next-line no-restricted-syntax | ||
for (var _iterator5 = renderObjects, _isArray5 = Array.isArray(_iterator5), _i5 = 0, _iterator5 = _isArray5 ? _iterator5 : _iterator5[Symbol.iterator]();;) { | ||
var _ref9; | ||
if (_isArray5) { | ||
if (_i5 >= _iterator5.length) break; | ||
_ref9 = _iterator5[_i5++]; | ||
} else { | ||
_i5 = _iterator5.next(); | ||
if (_i5.done) break; | ||
_ref9 = _i5.value; | ||
} | ||
var _object = _ref9; | ||
var _style = this.styleManager.getStyleById(_object.id); | ||
@@ -1492,3 +1604,7 @@ | ||
var spaceRenderObj = objs[0], | ||
rest = objs.slice(1); | ||
rest = objs.slice(1); // We apply instancing to the object per room for further update | ||
// if (object.spaceUUID && spaceRenderObj.instancingId) { | ||
// spaceRenderObj.instancingId = `${object.spaceUUID}_${object.subType}` | ||
// } | ||
var _spaceRenderObj$style2 = spaceRenderObj.style, | ||
@@ -1495,0 +1611,0 @@ style = _spaceRenderObj$style2 === void 0 ? {} : _spaceRenderObj$style2; |
@@ -31,2 +31,8 @@ import _extends from "@babel/runtime/helpers/esm/extends"; | ||
_proto.setBaseStyle = function setBaseStyle(baseStyle) { | ||
_classPrivateFieldSet(this, _baseStyle, baseStyle); | ||
this.flatten(); | ||
}; | ||
_proto.flatten = function flatten() { | ||
@@ -33,0 +39,0 @@ _classPrivateFieldSet(this, _currentStyle, Object.assign.apply(Object, [{}, _classPrivateFieldGet(this, _baseStyle)].concat(this.stack))); |
import _get from "lodash/get"; | ||
import { createRenderObjects } from '@wework/floormap-utils'; | ||
var HOT_DESK_TYPES = ['HOT DESK', 'HOT DESKS', 'PRIVATE HOT DESK AREA', 'PRIVATE HOT DESKS AREA']; | ||
export var HOT_DESK_TYPES = ['HOT DESK', 'HOT DESKS', 'PRIVATE HOT DESK AREA', 'PRIVATE HOT DESKS AREA']; | ||
export var getObjectRenderObject = function getObjectRenderObject(object, parentSpace) { | ||
@@ -5,0 +5,0 @@ var objectSubType = object.subType; |
@@ -219,3 +219,2 @@ import Building from 'models/Building' | ||
expect(mockLoadBuilding.mock.calls[0][0]).toEqual('buildingId-1') | ||
expect(mockLoadBuilding).toHaveBeenCalledWith('buildingId-1') | ||
expect(mockLoadFloorAndSpaces).toHaveBeenCalledWith('floorId-1') | ||
@@ -228,3 +227,2 @@ }) | ||
expect(mockLoadBuilding.mock.calls[0][0]).toEqual('buildingId-1') | ||
expect(mockLoadBuilding).toHaveBeenCalledWith('buildingId-1') | ||
expect(mockLoadFloorAndSpaces).toHaveBeenCalledTimes(0) | ||
@@ -236,5 +234,5 @@ }) | ||
expect(mockLoadBuilding).toHaveBeenCalledWith('buildingId-1') | ||
expect(mockLoadBuilding.mock.calls[0][0]).toEqual('buildingId-1') | ||
expect(mockLoadFloorAndSpaces).toHaveBeenCalledWith('floorId-1') | ||
}) | ||
}) |
@@ -8,2 +8,4 @@ "use strict"; | ||
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends")); | ||
var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator")); | ||
@@ -98,3 +100,3 @@ | ||
/*#__PURE__*/ | ||
_regenerator.default.mark(function _callee2(buildingUUID) { | ||
_regenerator.default.mark(function _callee2(buildingUUID, options) { | ||
var response, meta, _response$data, data, _response$included2, included, building; | ||
@@ -106,8 +108,12 @@ | ||
case 0: | ||
_context2.next = 2; | ||
return this.client.get("/buildings/" + buildingUUID, { | ||
if (options === void 0) { | ||
options = {}; | ||
} | ||
_context2.next = 3; | ||
return this.client.get("/buildings/" + buildingUUID, (0, _extends2.default)({}, options, { | ||
include: 'floors' | ||
}); | ||
})); | ||
case 2: | ||
case 3: | ||
response = _context2.sent; | ||
@@ -117,3 +123,3 @@ meta = response.meta, _response$data = response.data, data = _response$data === void 0 ? {} : _response$data, _response$included2 = response.included, included = _response$included2 === void 0 ? [] : _response$included2; | ||
if (meta.success) { | ||
_context2.next = 6; | ||
_context2.next = 7; | ||
break; | ||
@@ -124,7 +130,7 @@ } | ||
case 6: | ||
case 7: | ||
building = new _Building.default(data, included); | ||
return _context2.abrupt("return", building); | ||
case 8: | ||
case 9: | ||
case "end": | ||
@@ -137,3 +143,3 @@ return _context2.stop(); | ||
function loadBuilding(_x2) { | ||
function loadBuilding(_x2, _x3) { | ||
return _loadBuilding.apply(this, arguments); | ||
@@ -140,0 +146,0 @@ } |
@@ -37,3 +37,3 @@ "use strict"; | ||
_regenerator.default.mark(function _callee(buildingId, options) { | ||
var _options, _options$ignoreCache, ignoreCache, cachedBuilding, building; | ||
var _options, _options$ignoreCache, ignoreCache, _options$reload, reload, reqOpts, cachedBuilding, building; | ||
@@ -48,7 +48,13 @@ return _regenerator.default.wrap(function _callee$(_context) { | ||
_options = options, _options$ignoreCache = _options.ignoreCache, ignoreCache = _options$ignoreCache === void 0 ? false : _options$ignoreCache; | ||
_options = options, _options$ignoreCache = _options.ignoreCache, ignoreCache = _options$ignoreCache === void 0 ? false : _options$ignoreCache, _options$reload = _options.reload, reload = _options$reload === void 0 ? false : _options$reload; | ||
reqOpts = {}; | ||
if (reload) { | ||
reqOpts.reload = true; | ||
} | ||
cachedBuilding = _this.buildingById.get(buildingId); | ||
if (!(cachedBuilding && !ignoreCache)) { | ||
_context.next = 5; | ||
_context.next = 7; | ||
break; | ||
@@ -59,7 +65,7 @@ } | ||
case 5: | ||
_context.next = 7; | ||
return _this.loader.loadBuilding(buildingId); | ||
case 7: | ||
_context.next = 9; | ||
return _this.loader.loadBuilding(buildingId, reqOpts); | ||
case 7: | ||
case 9: | ||
building = _context.sent; | ||
@@ -73,3 +79,3 @@ | ||
case 11: | ||
case 13: | ||
case "end": | ||
@@ -165,2 +171,12 @@ return _context.stop(); | ||
_this.objectById.set(space.uuid, space); | ||
var objects = _this.objectsByRoom.get(space.spaceUUID); | ||
if (!objects) { | ||
objects = []; | ||
_this.objectsByRoom.set(space.spaceUUID, objects); | ||
} | ||
objects.push(space); | ||
} | ||
@@ -186,2 +202,3 @@ | ||
this.spaceByAlias = new Map(); | ||
this.objectsByRoom = new Map(); | ||
} // - Private | ||
@@ -377,2 +394,6 @@ | ||
_proto.getObjectsBySpaceId = function getObjectsBySpaceId(id) { | ||
return this.objectsByRoom.get(id) || []; | ||
}; | ||
_proto.updateSpaceData = function updateSpaceData(id, data) { | ||
@@ -405,2 +426,3 @@ var space = this.spaceById.get(id) || this.objectById.get(id); | ||
this.spaceByAlias = new Map(); | ||
this.objectsByRoom = new Map(); | ||
}; | ||
@@ -407,0 +429,0 @@ |
@@ -872,2 +872,5 @@ "use strict"; | ||
/** | ||
* | ||
* @deprecated Use .updateSpace(spaceId, data) instead | ||
* | ||
* Update space/object data with given id. | ||
@@ -881,2 +884,14 @@ * This function will trigger `datachange` event on the map | ||
_proto.updateData = function updateData(spaceOrObjectId, data) { | ||
this.updateSpace(spaceOrObjectId, data); | ||
} | ||
/** | ||
* Update space/object data with given id. | ||
* This function will trigger `datachange` event on the map | ||
* @param {string} spaceOrObjectId - id of space/object to be updated | ||
* @param {Object} data - Data to update | ||
*/ | ||
; | ||
_proto.updateSpace = function updateSpace(spaceOrObjectId, data) { | ||
var previousData = this.getSpaceById(spaceOrObjectId); | ||
var newData = this.datasource.updateSpaceData(spaceOrObjectId, data); | ||
@@ -888,2 +903,3 @@ | ||
this.refreshSpace(newData, previousData); | ||
var eventPayload = { | ||
@@ -937,3 +953,4 @@ id: spaceOrObjectId, | ||
return this.datasource.loadBuilding(buildingId, { | ||
ignoreCache: true | ||
ignoreCache: true, | ||
reload: true | ||
}); | ||
@@ -965,3 +982,98 @@ | ||
return refreshBuilding; | ||
}() | ||
}(); | ||
_proto.refreshSpace = function refreshSpace(space, previousData) { | ||
// We don't need to rerender object | ||
if (space.type === 'object') { | ||
return; | ||
} // For space, we don't need to remove, just get new style and apply | ||
// 1. Get a new base style from utils based on new space data | ||
// 2. Set base style to existing style of the space | ||
var _getSpaceRenderObject = (0, _render2.getSpaceRenderObject)(space), | ||
spaceRenderObject = _getSpaceRenderObject[0], | ||
rest = _getSpaceRenderObject.slice(1); | ||
var style = this.styleManager.getStyleById(space.uuid); | ||
if (style) { | ||
style.setBaseStyle(spaceRenderObject.style || {}); | ||
spaceRenderObject.style = style.getStyle(); | ||
} // 3. draw space with new base style | ||
this.renderer.remove(space.uuid + "_SPRITE"); | ||
this.renderer.draw([spaceRenderObject].concat(rest), true); // Space type change from hot desk types to non-hot-desk-types or vice versa | ||
// We have to rerender all desks/chairs inside the room | ||
if (_render2.HOT_DESK_TYPES.includes(space.subType) !== _render2.HOT_DESK_TYPES.includes(previousData.subType)) { | ||
var objects = this.getObjectsByFloorId(); | ||
if (!objects || !objects.length) { | ||
return; | ||
} | ||
var renderingObjects = []; // eslint-disable-next-line no-restricted-syntax | ||
for (var _iterator2 = objects, _isArray2 = Array.isArray(_iterator2), _i2 = 0, _iterator2 = _isArray2 ? _iterator2 : _iterator2[Symbol.iterator]();;) { | ||
var _ref5; | ||
if (_isArray2) { | ||
if (_i2 >= _iterator2.length) break; | ||
_ref5 = _iterator2[_i2++]; | ||
} else { | ||
_i2 = _iterator2.next(); | ||
if (_i2.done) break; | ||
_ref5 = _i2.value; | ||
} | ||
var object = _ref5; | ||
var parentSpace = this.datasource.getSpaceById(object.spaceUUID); | ||
var objs = (0, _render2.getObjectRenderObject)(object, parentSpace); // utils sometime return undefined for unknown type | ||
if (!objs) { | ||
return; | ||
} | ||
var renderObject = objs[0], | ||
restObjects = objs.slice(1); | ||
var objectStyle = this.styleManager.getStyleById(renderObject.id); | ||
if (objectStyle) { | ||
renderObject.style = objectStyle.getStyle(); | ||
} // Reassign properties from current objects | ||
var prevObjectOpts = this.renderer.getRenderObject(renderObject.id); | ||
if (prevObjectOpts) { | ||
renderObject.interactable = prevObjectOpts.interactable; | ||
renderObject.visible = prevObjectOpts.visible; | ||
} // Always show if parent is dedicated desk | ||
if (parentSpace) { | ||
var isDedicatedRoomType = DEDICATED_ROOM_TYPES.includes(parentSpace.subType); | ||
if (isDedicatedRoomType) { | ||
renderObject.visible = true; | ||
} | ||
} | ||
renderingObjects.push.apply(renderingObjects, [renderObject].concat(restObjects)); | ||
} // Remove current desks and chairs | ||
this.renderer.removeInstancedMesh('CHAIRS'); | ||
this.renderer.removeInstancedMesh('TABLES'); | ||
this.renderer.removeInstancedMesh('HOTDESK_TABLES'); | ||
this.renderer.removeInstancedMesh('CHAIRS_OUTLINE'); | ||
this.renderer.removeInstancedMesh('TABLES_OUTLINE'); | ||
this.renderer.removeInstancedMesh('HOTDESK_TABLES_OUTLINE'); // Apply instancing | ||
(0, _floormapUtils.applyInstancing)(renderingObjects, this.renderer); | ||
this.renderer.draw(renderingObjects, true); | ||
} | ||
} | ||
/** @private */ | ||
@@ -1249,6 +1361,6 @@ ; | ||
_proto.setCenter = function setCenter(_ref5) { | ||
var x = _ref5.x, | ||
y = _ref5.y, | ||
z = _ref5.z; | ||
_proto.setCenter = function setCenter(_ref6) { | ||
var x = _ref6.x, | ||
y = _ref6.y, | ||
z = _ref6.z; | ||
this.renderer.setCameraViewPoint({ | ||
@@ -1362,20 +1474,3 @@ position: { | ||
for (var _iterator2 = this.hooks.onRender, _isArray2 = Array.isArray(_iterator2), _i2 = 0, _iterator2 = _isArray2 ? _iterator2 : _iterator2[Symbol.iterator]();;) { | ||
var _ref6; | ||
if (_isArray2) { | ||
if (_i2 >= _iterator2.length) break; | ||
_ref6 = _iterator2[_i2++]; | ||
} else { | ||
_i2 = _iterator2.next(); | ||
if (_i2.done) break; | ||
_ref6 = _i2.value; | ||
} | ||
var listener = _ref6; | ||
listener(payload); | ||
} // eslint-disable-next-line no-restricted-syntax | ||
for (var _iterator3 = spaceRenderObjects, _isArray3 = Array.isArray(_iterator3), _i3 = 0, _iterator3 = _isArray3 ? _iterator3 : _iterator3[Symbol.iterator]();;) { | ||
for (var _iterator3 = this.hooks.onRender, _isArray3 = Array.isArray(_iterator3), _i3 = 0, _iterator3 = _isArray3 ? _iterator3 : _iterator3[Symbol.iterator]();;) { | ||
var _ref7; | ||
@@ -1392,12 +1487,8 @@ | ||
var object = _ref7; | ||
var style = this.styleManager.getStyleById(object.id); | ||
if (style) { | ||
object.style = style.getStyle(); | ||
} | ||
var listener = _ref7; | ||
listener(payload); | ||
} // eslint-disable-next-line no-restricted-syntax | ||
for (var _iterator4 = renderObjects, _isArray4 = Array.isArray(_iterator4), _i4 = 0, _iterator4 = _isArray4 ? _iterator4 : _iterator4[Symbol.iterator]();;) { | ||
for (var _iterator4 = spaceRenderObjects, _isArray4 = Array.isArray(_iterator4), _i4 = 0, _iterator4 = _isArray4 ? _iterator4 : _iterator4[Symbol.iterator]();;) { | ||
var _ref8; | ||
@@ -1414,4 +1505,25 @@ | ||
var _object = _ref8; | ||
var object = _ref8; | ||
var style = this.styleManager.getStyleById(object.id); | ||
if (style) { | ||
object.style = style.getStyle(); | ||
} | ||
} // eslint-disable-next-line no-restricted-syntax | ||
for (var _iterator5 = renderObjects, _isArray5 = Array.isArray(_iterator5), _i5 = 0, _iterator5 = _isArray5 ? _iterator5 : _iterator5[Symbol.iterator]();;) { | ||
var _ref9; | ||
if (_isArray5) { | ||
if (_i5 >= _iterator5.length) break; | ||
_ref9 = _iterator5[_i5++]; | ||
} else { | ||
_i5 = _iterator5.next(); | ||
if (_i5.done) break; | ||
_ref9 = _i5.value; | ||
} | ||
var _object = _ref9; | ||
var _style = this.styleManager.getStyleById(_object.id); | ||
@@ -1500,3 +1612,7 @@ | ||
var spaceRenderObj = objs[0], | ||
rest = objs.slice(1); | ||
rest = objs.slice(1); // We apply instancing to the object per room for further update | ||
// if (object.spaceUUID && spaceRenderObj.instancingId) { | ||
// spaceRenderObj.instancingId = `${object.spaceUUID}_${object.subType}` | ||
// } | ||
var _spaceRenderObj$style2 = spaceRenderObj.style, | ||
@@ -1503,0 +1619,0 @@ style = _spaceRenderObj$style2 === void 0 ? {} : _spaceRenderObj$style2; |
@@ -39,2 +39,7 @@ "use strict"; | ||
_proto.setBaseStyle = function setBaseStyle(baseStyle) { | ||
(0, _classPrivateFieldSet2.default)(this, _baseStyle, baseStyle); | ||
this.flatten(); | ||
}; | ||
_proto.flatten = function flatten() { | ||
@@ -41,0 +46,0 @@ (0, _classPrivateFieldSet2.default)(this, _currentStyle, Object.assign.apply(Object, [{}, (0, _classPrivateFieldGet2.default)(this, _baseStyle)].concat(this.stack))); |
@@ -6,3 +6,3 @@ "use strict"; | ||
exports.__esModule = true; | ||
exports.getSpaceRenderObject = exports.getObjectRenderObject = void 0; | ||
exports.getSpaceRenderObject = exports.getObjectRenderObject = exports.HOT_DESK_TYPES = void 0; | ||
@@ -14,2 +14,3 @@ var _get2 = _interopRequireDefault(require("lodash/get")); | ||
var HOT_DESK_TYPES = ['HOT DESK', 'HOT DESKS', 'PRIVATE HOT DESK AREA', 'PRIVATE HOT DESKS AREA']; | ||
exports.HOT_DESK_TYPES = HOT_DESK_TYPES; | ||
@@ -16,0 +17,0 @@ var getObjectRenderObject = function getObjectRenderObject(object, parentSpace) { |
{ | ||
"name": "@wework/floormap-sdk", | ||
"version": "1.1.9", | ||
"version": "1.1.10-rc2", | ||
"main": "./lib/index.js", | ||
@@ -83,4 +83,4 @@ "module": "es/index.js", | ||
"@babel/runtime": "^7.0.0", | ||
"@wework/floormap-utils": "0.9.5", | ||
"@wework/floormap.gl": "1.0.1", | ||
"@wework/floormap-utils": "0.9.5-rc1", | ||
"@wework/floormap.gl": "1.1.0-rc1", | ||
"axios": "^0.18.0", | ||
@@ -87,0 +87,0 @@ "crypto-js": "^3.1.9-1", |
@@ -219,3 +219,2 @@ import Building from 'models/Building' | ||
expect(mockLoadBuilding.mock.calls[0][0]).toEqual('buildingId-1') | ||
expect(mockLoadBuilding).toHaveBeenCalledWith('buildingId-1') | ||
expect(mockLoadFloorAndSpaces).toHaveBeenCalledWith('floorId-1') | ||
@@ -228,3 +227,2 @@ }) | ||
expect(mockLoadBuilding.mock.calls[0][0]).toEqual('buildingId-1') | ||
expect(mockLoadBuilding).toHaveBeenCalledWith('buildingId-1') | ||
expect(mockLoadFloorAndSpaces).toHaveBeenCalledTimes(0) | ||
@@ -236,5 +234,5 @@ }) | ||
expect(mockLoadBuilding).toHaveBeenCalledWith('buildingId-1') | ||
expect(mockLoadBuilding.mock.calls[0][0]).toEqual('buildingId-1') | ||
expect(mockLoadFloorAndSpaces).toHaveBeenCalledWith('floorId-1') | ||
}) | ||
}) |
@@ -33,4 +33,5 @@ import _ from 'lodash' | ||
async loadBuilding(buildingUUID) { | ||
async loadBuilding(buildingUUID, options = {}) { | ||
const response = await this.client.get(`/buildings/${buildingUUID}`, { | ||
...options, | ||
include: 'floors', | ||
@@ -37,0 +38,0 @@ }) |
@@ -19,2 +19,4 @@ import _ from 'lodash' | ||
this.spaceByAlias = new Map() | ||
this.objectsByRoom = new Map() | ||
} | ||
@@ -24,4 +26,9 @@ | ||
loadBuilding = async (buildingId, options = {}) => { | ||
const { ignoreCache = false } = options | ||
const { ignoreCache = false, reload = false } = options | ||
const reqOpts = {} | ||
if (reload) { | ||
reqOpts.reload = true | ||
} | ||
const cachedBuilding = this.buildingById.get(buildingId) | ||
@@ -32,3 +39,3 @@ | ||
} | ||
const building = await this.loader.loadBuilding(buildingId) | ||
const building = await this.loader.loadBuilding(buildingId, reqOpts) | ||
@@ -68,2 +75,8 @@ this.floorsByBuildingId.set(building.uuid, building.floors) | ||
this.objectById.set(space.uuid, space) | ||
let objects = this.objectsByRoom.get(space.spaceUUID) | ||
if (!objects) { | ||
objects = [] | ||
this.objectsByRoom.set(space.spaceUUID, objects) | ||
} | ||
objects.push(space) | ||
} | ||
@@ -170,2 +183,6 @@ | ||
getObjectsBySpaceId(id) { | ||
return this.objectsByRoom.get(id) || [] | ||
} | ||
updateSpaceData(id, data) { | ||
@@ -198,2 +215,3 @@ const space = this.spaceById.get(id) || this.objectById.get(id) | ||
this.spaceByAlias = new Map() | ||
this.objectsByRoom = new Map() | ||
} | ||
@@ -200,0 +218,0 @@ } |
@@ -9,3 +9,3 @@ /* eslint-disable no-param-reassign */ | ||
import { getCenter, applyInstancing } from '@wework/floormap-utils' | ||
import { getSpaceRenderObject, getObjectRenderObject } from 'utils/render' | ||
import { getSpaceRenderObject, getObjectRenderObject, HOT_DESK_TYPES } from 'utils/render' | ||
import EventDispatcher from 'utils/EventDispatcher' | ||
@@ -612,2 +612,5 @@ import FloorMapError from 'errors/FloorMapError' | ||
/** | ||
* | ||
* @deprecated Use .updateSpace(spaceId, data) instead | ||
* | ||
* Update space/object data with given id. | ||
@@ -619,2 +622,13 @@ * This function will trigger `datachange` event on the map | ||
updateData(spaceOrObjectId, data) { | ||
this.updateSpace(spaceOrObjectId, data) | ||
} | ||
/** | ||
* Update space/object data with given id. | ||
* This function will trigger `datachange` event on the map | ||
* @param {string} spaceOrObjectId - id of space/object to be updated | ||
* @param {Object} data - Data to update | ||
*/ | ||
updateSpace(spaceOrObjectId, data) { | ||
const previousData = this.getSpaceById(spaceOrObjectId) | ||
const newData = this.datasource.updateSpaceData(spaceOrObjectId, data) | ||
@@ -624,2 +638,5 @@ if (!newData) { | ||
} | ||
this.refreshSpace(newData, previousData) | ||
const eventPayload = { | ||
@@ -654,3 +671,6 @@ id: spaceOrObjectId, | ||
const building = await this.datasource.loadBuilding(buildingId, { ignoreCache: true }) | ||
const building = await this.datasource.loadBuilding(buildingId, { | ||
ignoreCache: true, | ||
reload: true, | ||
}) | ||
this.eventEmitter.emit('datachange', { | ||
@@ -664,2 +684,81 @@ payload: { id: building.uuid }, | ||
refreshSpace(space, previousData) { | ||
// We don't need to rerender object | ||
if (space.type === 'object') { | ||
return | ||
} | ||
// For space, we don't need to remove, just get new style and apply | ||
// 1. Get a new base style from utils based on new space data | ||
// 2. Set base style to existing style of the space | ||
const [spaceRenderObject, ...rest] = getSpaceRenderObject(space) | ||
const style = this.styleManager.getStyleById(space.uuid) | ||
if (style) { | ||
style.setBaseStyle(spaceRenderObject.style || {}) | ||
spaceRenderObject.style = style.getStyle() | ||
} | ||
// 3. draw space with new base style | ||
this.renderer.remove(`${space.uuid}_SPRITE`) | ||
this.renderer.draw([spaceRenderObject, ...rest], true) | ||
// Space type change from hot desk types to non-hot-desk-types or vice versa | ||
// We have to rerender all desks/chairs inside the room | ||
if (HOT_DESK_TYPES.includes(space.subType) !== HOT_DESK_TYPES.includes(previousData.subType)) { | ||
const objects = this.getObjectsByFloorId() | ||
if (!objects || !objects.length) { | ||
return | ||
} | ||
const renderingObjects = [] | ||
// eslint-disable-next-line no-restricted-syntax | ||
for (const object of objects) { | ||
const parentSpace = this.datasource.getSpaceById(object.spaceUUID) | ||
const objs = getObjectRenderObject(object, parentSpace) | ||
// utils sometime return undefined for unknown type | ||
if (!objs) { | ||
return | ||
} | ||
const [renderObject, ...restObjects] = objs | ||
const objectStyle = this.styleManager.getStyleById(renderObject.id) | ||
if (objectStyle) { | ||
renderObject.style = objectStyle.getStyle() | ||
} | ||
// Reassign properties from current objects | ||
const prevObjectOpts = this.renderer.getRenderObject(renderObject.id) | ||
if (prevObjectOpts) { | ||
renderObject.interactable = prevObjectOpts.interactable | ||
renderObject.visible = prevObjectOpts.visible | ||
} | ||
// Always show if parent is dedicated desk | ||
if (parentSpace) { | ||
const isDedicatedRoomType = DEDICATED_ROOM_TYPES.includes(parentSpace.subType) | ||
if (isDedicatedRoomType) { | ||
renderObject.visible = true | ||
} | ||
} | ||
renderingObjects.push(renderObject, ...restObjects) | ||
} | ||
// Remove current desks and chairs | ||
this.renderer.removeInstancedMesh('CHAIRS') | ||
this.renderer.removeInstancedMesh('TABLES') | ||
this.renderer.removeInstancedMesh('HOTDESK_TABLES') | ||
this.renderer.removeInstancedMesh('CHAIRS_OUTLINE') | ||
this.renderer.removeInstancedMesh('TABLES_OUTLINE') | ||
this.renderer.removeInstancedMesh('HOTDESK_TABLES_OUTLINE') | ||
// Apply instancing | ||
applyInstancing(renderingObjects, this.renderer) | ||
this.renderer.draw(renderingObjects, true) | ||
} | ||
} | ||
/** @private */ | ||
@@ -1102,2 +1201,8 @@ retrieveExtensionData = (space) => { | ||
const [spaceRenderObj, ...rest] = objs | ||
// We apply instancing to the object per room for further update | ||
// if (object.spaceUUID && spaceRenderObj.instancingId) { | ||
// spaceRenderObj.instancingId = `${object.spaceUUID}_${object.subType}` | ||
// } | ||
const { style = {} } = spaceRenderObj | ||
@@ -1104,0 +1209,0 @@ const styleObject = this.styleManager.createStyle(object.uuid, object, style) |
@@ -14,2 +14,7 @@ class Style { | ||
setBaseStyle(baseStyle) { | ||
this.#baseStyle = baseStyle | ||
this.flatten() | ||
} | ||
flatten() { | ||
@@ -16,0 +21,0 @@ this.#currentStyle = Object.assign({}, this.#baseStyle, ...this.stack) |
import _ from 'lodash' | ||
import { createRenderObjects } from '@wework/floormap-utils' | ||
const HOT_DESK_TYPES = ['HOT DESK', 'HOT DESKS', 'PRIVATE HOT DESK AREA', 'PRIVATE HOT DESKS AREA'] | ||
export const HOT_DESK_TYPES = [ | ||
'HOT DESK', | ||
'HOT DESKS', | ||
'PRIVATE HOT DESK AREA', | ||
'PRIVATE HOT DESKS AREA', | ||
] | ||
@@ -6,0 +11,0 @@ export const getObjectRenderObject = (object, parentSpace) => { |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
11173700
73530
3
+ Added@wework/floormap-utils@0.9.5-rc1(transitive)
+ Added@wework/floormap.gl@1.1.0-rc1(transitive)
- Removed@wework/floormap-utils@0.9.5(transitive)
- Removed@wework/floormap.gl@1.0.1(transitive)