MCPcopy Create free account
hub / github.com/facebook/Rapid / resize

Method resize

modules/core/UiSystem.js:284–343  ·  view source on GitHub ↗
(e)

Source from the content-addressed store, hash-verified

282 * @param {Event} e? - the resize event (if any)
283 */
284 resize(e) {
285 const context = this.context;
286 const map = context.systems.map;
287 const viewport = context.viewport;
288 const $container = context.container();
289
290 // This is an actual resize event - class the container as resizing.
291 if (e) {
292 window.clearTimeout(this._resizeTimeout);
293 $container.classed('resizing', true);
294 this._resizeTimeout = window.setTimeout(() => {
295 $container.classed('resizing', false);
296 }, 400); // if no resizes for 400ms, remove class
297 }
298
299 const $mainContent = $container.selectAll('.main-content');
300 if (!$mainContent.size()) return; // called too early?
301
302 const curr = this._copyRect($mainContent.node().getBoundingClientRect());
303 const prev = this._mapRect || curr;
304 this._mapRect = curr;
305
306 // Determine how the map is getting resized
307 // (we do prev-curr because we want negative values to pan with)
308 const dtop = prev.top - curr.top;
309 const dright = prev.right - curr.right;
310 const dbottom = prev.bottom - curr.bottom;
311 const dleft = prev.left - curr.left;
312
313 // Un-pan map to keep it centered in the same spot.
314 // (div/2 because the map grows/shrinks from the middle, so we only need to pan half this distance)
315 const [dw, dh] = [dleft + dright, dtop + dbottom];
316 if (dw || dh) {
317 map.pan([dw / 2, dh / 2]);
318 }
319
320 let dims = [curr.width, curr.height];
321
322// experiment:
323// Previously, the map surfaces were anchored to the top left of the main-map.
324// Now, the map surfaces are centered in a CSS Grid, to support rotation around the center.
325// We can extend the map dimensions a little bit so that as the user pans, we dont see seams at the edges of the map.
326const overscan = 50;
327dims = vecAdd(dims, [overscan * 2, overscan * 2]);
328
329 viewport.dimensions = dims;
330
331 // check if header or footer have overflowed
332 this.checkOverflow('.map-toolbar');
333 this.checkOverflow('.map-footer');
334
335 this.emit('uichange');
336
337// this was for the restrictions editor?
338// or any other component that needs to know when resizing is happening
339// // Use outdated code so it works on Explorer
340// const resizeWindowEvent = document.createEvent('Event');
341// resizeWindowEvent.initEvent('resizeWindow', true, true);

Callers 5

startAsyncMethod · 0.95
_drawMethod · 0.45
showViewerMethod · 0.45
_initViewerMethod · 0.45
startAsyncMethod · 0.45

Calls 4

_copyRectMethod · 0.95
checkOverflowMethod · 0.95
panMethod · 0.80
containerMethod · 0.45

Tested by

no test coverage detected