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

Method render

modules/core/MapSystem.js:235–282  ·  view source on GitHub ↗

* render * Accepts a parent selection, and renders the content under it. * (The parent selection is required the first time, but can be inferred on subsequent renders) * @param {d3-selection} $parent - A d3-selection to a HTMLElement that this component should render itself into

($parent = this.$parent)

Source from the content-addressed store, hash-verified

233 * @param {d3-selection} $parent - A d3-selection to a HTMLElement that this component should render itself into
234 */
235 render($parent = this.$parent) {
236 if ($parent instanceof selection) {
237 this.$parent = $parent;
238 } else {
239 return; // no parent - called too early?
240 }
241
242 const context = this.context;
243 const gfx = context.systems.gfx;
244
245 // Everything in here runs one time (on enter).
246 // The 'main-map' is an absolutely positioned container that fills the space where the map will go.
247 const $$mainmap = $parent.selectAll('.main-map')
248 .data([0])
249 .enter()
250 .append('div')
251 .attr('class', 'main-map')
252 // Suppress the native right-click context menu
253 .on('contextmenu', e => e.preventDefault())
254 // Suppress swipe-to-navigate browser pages on trackpad/magic mouse – iD#5552
255 .on('wheel.map mousewheel.map', e => e.preventDefault());
256
257 // The `supersurface` is a wrapper div that we temporarily transform as the user zooms and pans.
258 // This allows us to defer actual rendering until the browser has more time to do it.
259 // At regular intervals we reset this root transform and actually redraw the map.
260 const $$supersurface = $$mainmap
261 .append(() => gfx.supersurface)
262 .attr('class', 'supersurface');
263
264 // Content beneath the supersurface may be transformed and will need to rerender sometimes.
265 // This includes the Pixi WebGL canvas and the right-click edit menu
266
267 // Historically `surface` was the root of the SVG DOM - Now it's the Pixi WebGL canvas.
268 // Things that will not work anymore:
269 // - d3 selecting surface's child stuff
270 // - css classing surface's child stuff
271 // - listening to events on the surface
272 $$supersurface
273 .append(() => gfx.surface)
274 .attr('class', 'surface');
275
276 // The `overlay` is a div that is transformed to cancel out the supersurface.
277 // This is a place to put things _not drawn by pixi_ that should stay positioned
278 // with the map, like the editmenu.
279 $$supersurface
280 .append(() => gfx.overlay)
281 .attr('class', 'overlay');
282 }
283
284
285 /**

Callers

nothing calls this directly

Calls 3

dataMethod · 0.80
onMethod · 0.45
enterMethod · 0.45

Tested by

no test coverage detected