Skip to content

Commit

Permalink
RendererMap -> MapSystem, 3dMap -> Map3dSystem
Browse files Browse the repository at this point in the history
I also got the old RendererMap tests working again.
These were skipped, but they can work now with some substantial mocking.
Mostly because MapSystem listens to events emitted by many other things.

It might make more sense to avoid these listeners and instead have the other
systems tell them map to redraw as needed. We have map.deferredRedraw() now
so this can be done in a less intrusive way.

Also, we still have to sort out initialization of the map a bit better, but
we're getting there.
  • Loading branch information
bhousel committed May 30, 2023
1 parent 695f472 commit 1d5e617
Show file tree
Hide file tree
Showing 117 changed files with 759 additions and 838 deletions.
8 changes: 4 additions & 4 deletions modules/behaviors/BehaviorDrag.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ export class BehaviorDrag extends AbstractBehavior {
this.lastMove = null;
this.dragTarget = null;

const eventManager = this.context.map().renderer.events;
const eventManager = this.context.mapSystem().renderer.events;
eventManager.on('modifierchanged', this._doMove);
eventManager.on('pointerover', this._doMove);
eventManager.on('pointerout', this._doMove);
Expand Down Expand Up @@ -87,7 +87,7 @@ export class BehaviorDrag extends AbstractBehavior {
this.lastMove = null;
this.dragTarget = null;

const eventManager = this.context.map().renderer.events;
const eventManager = this.context.mapSystem().renderer.events;
eventManager.off('modifierchanged', this._doMove);
eventManager.off('pointerover', this._doMove);
eventManager.off('pointerout', this._doMove);
Expand Down Expand Up @@ -127,7 +127,7 @@ export class BehaviorDrag extends AbstractBehavior {
* @param `e` A Pixi FederatedPointerEvent
*/
_pointermove(e) {
const map = this.context.map();
const map = this.context.mapSystem();

// If we detect the edit (right-click) menu, we should cease any dragging behavior.
const hasEditmenu = map.supersurface.select('.edit-menu').size();
Expand Down Expand Up @@ -231,7 +231,7 @@ export class BehaviorDrag extends AbstractBehavior {
_snappingDisabled() {
// Ignore it if we are not over the canvas
// (e.g. sidebar, out of browser window, over a button, toolbar, modal)
const eventManager = this.context.map().renderer.events;
const eventManager = this.context.mapSystem().renderer.events;
if (!eventManager.pointerOverRenderer) return false;

const modifiers = eventManager.modifierKeys;
Expand Down
8 changes: 4 additions & 4 deletions modules/behaviors/BehaviorDraw.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ export class BehaviorDraw extends AbstractBehavior {

this._spaceClickDisabled = false;

const eventManager = this.context.map().renderer.events;
const eventManager = this.context.mapSystem().renderer.events;
eventManager.on('keydown', this._keydown);
eventManager.on('keyup', this._keyup);
eventManager.on('modifierchanged', this._doMove);
Expand Down Expand Up @@ -96,7 +96,7 @@ export class BehaviorDraw extends AbstractBehavior {

this._spaceClickDisabled = false;

const eventManager = this.context.map().renderer.events;
const eventManager = this.context.mapSystem().renderer.events;
eventManager.off('keydown', this._keydown);
eventManager.off('keyup', this._keyup);
eventManager.off('modifierchanged', this._doMove);
Expand Down Expand Up @@ -257,7 +257,7 @@ export class BehaviorDraw extends AbstractBehavior {
// Ignore it if we are not over the canvas
// (e.g. sidebar, out of browser window, over a button, toolbar, modal)
const context = this.context;
const eventManager = context.map().renderer.events;
const eventManager = context.mapSystem().renderer.events;
if (!eventManager.pointerOverRenderer) return;

const modifiers = eventManager.modifierKeys;
Expand Down Expand Up @@ -317,7 +317,7 @@ export class BehaviorDraw extends AbstractBehavior {
// Ignore it if we are not over the canvas
// (e.g. sidebar, out of browser window, over a button, toolbar, modal)
const context = this.context;
const eventManager = context.map().renderer.events;
const eventManager = context.mapSystem().renderer.events;
// if (!eventManager.pointerOverRenderer) return;

const modifiers = eventManager.modifierKeys;
Expand Down
6 changes: 3 additions & 3 deletions modules/behaviors/BehaviorHover.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export class BehaviorHover extends AbstractBehavior {
this.lastMove = null;
this.hoverTarget = null;

const eventManager = this.context.map().renderer.events;
const eventManager = this.context.mapSystem().renderer.events;
eventManager.on('modifierchanged', this._doHover);
eventManager.on('pointerover', this._doHover);
eventManager.on('pointerout', this._doHover);
Expand All @@ -69,7 +69,7 @@ export class BehaviorHover extends AbstractBehavior {
this.lastMove = null;
this.hoverTarget = null;

const eventManager = this.context.map().renderer.events;
const eventManager = this.context.mapSystem().renderer.events;
eventManager.off('modifierchanged', this._doHover);
eventManager.off('pointerover', this._doHover);
eventManager.off('pointerout', this._doHover);
Expand Down Expand Up @@ -102,7 +102,7 @@ export class BehaviorHover extends AbstractBehavior {
if (interaction.gesture) return; // dont change hover while interacting with the map

const context = this.context;
const eventManager = context.map().renderer.events;
const eventManager = context.mapSystem().renderer.events;
const modifiers = eventManager.modifierKeys;
const hasModifierKey = modifiers.has('Alt') || modifiers.has('Control') || modifiers.has('Meta');
const eventData = Object.assign({}, this.lastMove); // shallow copy
Expand Down
14 changes: 7 additions & 7 deletions modules/behaviors/BehaviorLasso.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export class BehaviorLasso extends AbstractBehavior {
this._lassoing = false;
this._extent = null;

const eventManager = this.context.map().renderer.events;
const eventManager = this.context.mapSystem().renderer.events;
eventManager.on('pointerdown', this._pointerdown);
eventManager.on('pointermove', this._pointermove);
eventManager.on('pointerup', this._pointerup);
Expand All @@ -55,7 +55,7 @@ export class BehaviorLasso extends AbstractBehavior {
this._lassoing = false;
this._extent = null;

const eventManager = this.context.map().renderer.events;
const eventManager = this.context.mapSystem().renderer.events;
eventManager.off('pointerdown', this._pointerdown);
eventManager.off('pointermove', this._pointermove);
eventManager.off('pointerup', this._pointerup);
Expand All @@ -70,15 +70,15 @@ export class BehaviorLasso extends AbstractBehavior {
_pointerdown() {
// Ignore it if we are not over the canvas
// (e.g. sidebar, out of browser window, over a button, toolbar, modal)
const eventManager = this.context.map().renderer.events;
const eventManager = this.context.mapSystem().renderer.events;
if (!eventManager.pointerOverRenderer) return;

const modifiers = eventManager.modifierKeys;
const drawLasso = modifiers.has('Shift');

if (drawLasso) {
this._lassoing = true;
const coord = this.context.map().mouseLoc();
const coord = this.context.mapSystem().mouseLoc();
this._extent = new Extent(coord);
this._coords.push(coord);
}
Expand All @@ -93,10 +93,10 @@ export class BehaviorLasso extends AbstractBehavior {
_pointermove() {
if (!this._lassoing) return;

const eventManager = this.context.map().renderer.events;
const eventManager = this.context.mapSystem().renderer.events;
if (!eventManager.pointerOverRenderer) return;

const coord = this.context.map().mouseLoc();
const coord = this.context.mapSystem().mouseLoc();

// Update geometry and extent
this._extent = this._extent.extend(new Extent(coord));
Expand All @@ -105,7 +105,7 @@ export class BehaviorLasso extends AbstractBehavior {
// Push the polygon data to the map UI for rendering.
const mapUILayer = this.context.scene().layers.get('map-ui');
mapUILayer.lassoPolygonData = this._coords;
this.context.map().immediateRedraw();
this.context.mapSystem().immediateRedraw();
}


Expand Down
18 changes: 9 additions & 9 deletions modules/behaviors/BehaviorMapInteraction.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ export class BehaviorMapInteraction extends AbstractBehavior {
this.lastDown = null;
this.gesture = null;

const eventManager = this.context.map().renderer.events;
const eventManager = this.context.mapSystem().renderer.events;
eventManager.on('click', this._click);
eventManager.on('keydown', this._keydown);
eventManager.on('pointerdown', this._pointerdown);
Expand All @@ -81,7 +81,7 @@ export class BehaviorMapInteraction extends AbstractBehavior {
this.lastDown = null;
this.gesture = null;

const eventManager = this.context.map().renderer.events;
const eventManager = this.context.mapSystem().renderer.events;
eventManager.off('click', this._click);
eventManager.off('keydown', this._keydown);
eventManager.off('pointerdown', this._pointerdown);
Expand All @@ -104,7 +104,7 @@ export class BehaviorMapInteraction extends AbstractBehavior {
if (activeElement !== 'BODY') return;

const context = this.context;
const map = context.map();
const map = context.mapSystem();
const EASE = 100; // milliseconds

if (e.shiftKey) {
Expand Down Expand Up @@ -161,7 +161,7 @@ export class BehaviorMapInteraction extends AbstractBehavior {
const x2 = x - p1[0] * k2;
const y2 = y - p1[1] * k2;

this.context.map().transformEase({ x: x2, y: y2, k: k2 });
this.context.mapSystem().transformEase({ x: x2, y: y2, k: k2 });
}


Expand All @@ -175,7 +175,7 @@ export class BehaviorMapInteraction extends AbstractBehavior {
if (this.lastDown) return; // a pointer is already down

// If shift is pressed it's a lasso, not a map drag
const eventManager = this.context.map().renderer.events;
const eventManager = this.context.mapSystem().renderer.events;
if (eventManager.modifierKeys.has('Shift')) return;

const down = this._getEventData(e);
Expand Down Expand Up @@ -219,7 +219,7 @@ export class BehaviorMapInteraction extends AbstractBehavior {

const tNew = { x: t.x + newX, y: t.y + newY, k: t.k };

this.context.map().transform(tNew);
this.context.mapSystem().transform(tNew);
}
}

Expand All @@ -237,7 +237,7 @@ export class BehaviorMapInteraction extends AbstractBehavior {
this.lastDown = null;
this.gesture = null;

const eventManager = this.context.map().renderer.events;
const eventManager = this.context.mapSystem().renderer.events;
eventManager.setCursor('inherit');
}

Expand All @@ -253,7 +253,7 @@ export class BehaviorMapInteraction extends AbstractBehavior {
this.lastDown = null;
this.gesture = null;

const eventManager = this.context.map().renderer.events;
const eventManager = this.context.mapSystem().renderer.events;
eventManager.setCursor('inherit');
}

Expand Down Expand Up @@ -294,7 +294,7 @@ export class BehaviorMapInteraction extends AbstractBehavior {
tNew = { x: t.x - dX, y: t.y - dY, k: t.k };
}

this.context.map().transform(tNew);
this.context.mapSystem().transform(tNew);
}

}
8 changes: 4 additions & 4 deletions modules/behaviors/BehaviorMapNudging.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export class BehaviorMapNudging extends AbstractBehavior {
*/
enable() {
if (this._enabled) return;
const eventManager = this.context.map().renderer.events;
const eventManager = this.context.mapSystem().renderer.events;
eventManager.on('pointermove', this._pointermove);
}

Expand All @@ -62,7 +62,7 @@ export class BehaviorMapNudging extends AbstractBehavior {
disable() {
if (!this._enabled) return;
this._enabled = false;
const eventManager = this.context.map().renderer.events;
const eventManager = this.context.mapSystem().renderer.events;
eventManager.off('pointermove', this._pointermove);
}

Expand All @@ -76,12 +76,12 @@ export class BehaviorMapNudging extends AbstractBehavior {
if (!this._enabled) return;

const point = [e.global.x, e.global.y];
const nudge = geomViewportNudge(point, this.context.map().dimensions);
const nudge = geomViewportNudge(point, this.context.mapSystem().dimensions);
if (nudge) {
const [dX, dY] = [nudge[0] * nudgeFactor, nudge[1] * nudgeFactor];
const t = this.context.projection.transform();
const tNew = { x: t.x + dX, y: t.y + dY, k: t.k };
this.context.map().transform(tNew);
this.context.mapSystem().transform(tNew);
}
}

Expand Down
8 changes: 4 additions & 4 deletions modules/behaviors/BehaviorPaste.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export class BehaviorPaste extends AbstractBehavior {
if (this._enabled) return;
this._enabled = true;

const eventManager = this.context.map().renderer.events;
const eventManager = this.context.mapSystem().renderer.events;
eventManager.on('keydown', this._keydown);
}

Expand All @@ -47,7 +47,7 @@ export class BehaviorPaste extends AbstractBehavior {
if (!this._enabled) return;
this._enabled = false;

const eventManager = this.context.map().renderer.events;
const eventManager = this.context.mapSystem().renderer.events;
eventManager.off('keydown', this._keydown);
}

Expand Down Expand Up @@ -79,7 +79,7 @@ export class BehaviorPaste extends AbstractBehavior {

// Ignore it if we are not over the canvas
// (e.g. sidebar, out of browser window, over a button, toolbar, modal)
const eventManager = context.map().renderer.events;
const eventManager = context.mapSystem().renderer.events;
if (!eventManager.pointerOverRenderer) return;

e.preventDefault();
Expand Down Expand Up @@ -115,7 +115,7 @@ export class BehaviorPaste extends AbstractBehavior {
// Default to map center if we can't determine the mouse pointer
const copyLoc = context.copyLoc();
const copyPoint = (copyLoc && projection.project(copyLoc)) || projection.project(extent.center());
const mousePoint = eventManager.coord || context.map().centerPoint();
const mousePoint = eventManager.coord || context.mapSystem().centerPoint();
const delta = vecSubtract(mousePoint, copyPoint);

const annotation = context.t('operations.paste.annotation', { n: pasteIDs.size });
Expand Down
12 changes: 6 additions & 6 deletions modules/behaviors/BehaviorSelect.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ export class BehaviorSelect extends AbstractBehavior {
this.lastSpace = null;
this.lastClick = null;

const eventManager = this.context.map().renderer.events;
const eventManager = this.context.mapSystem().renderer.events;
eventManager.on('keydown', this._keydown);
eventManager.on('keyup', this._keyup);
eventManager.on('pointerdown', this._pointerdown);
Expand Down Expand Up @@ -106,7 +106,7 @@ export class BehaviorSelect extends AbstractBehavior {

this._cancelLongPress();

const eventManager = this.context.map().renderer.events;
const eventManager = this.context.mapSystem().renderer.events;
eventManager.off('keydown', this._keydown);
eventManager.off('keyup', this._keyup);
eventManager.off('pointerdown', this._pointerdown);
Expand Down Expand Up @@ -292,7 +292,7 @@ export class BehaviorSelect extends AbstractBehavior {
this._cancelLongPress();

const context = this.context;
const eventManager = context.map().renderer.events;
const eventManager = context.mapSystem().renderer.events;

const modifiers = eventManager.modifierKeys;
const disableSnap = modifiers.has('Alt') || modifiers.has('Control') || modifiers.has('Meta');
Expand Down Expand Up @@ -380,7 +380,7 @@ export class BehaviorSelect extends AbstractBehavior {
if (datum.captured_at) {
// Determine the layer that was clicked on, obtain its service.
const layerID = target.layer.id;
context.map().centerEase(datum.loc);
context.mapSystem().centerEase(datum.loc);
context.photoSystem().selectPhoto(layerID, datum.id);
// // No mode change event here, just manually tell the renderer to select it, for now
// const scene = context.scene();
Expand All @@ -394,7 +394,7 @@ export class BehaviorSelect extends AbstractBehavior {
const service = context.services.get('mapillary');
if (!service) return;

context.map().centerEase(event.loc);
context.mapSystem().centerEase(event.loc);
const selectedImageID = service.getActiveImage() && service.getActiveImage().id;

service.getDetections(datum.id).then(detections => {
Expand Down Expand Up @@ -497,7 +497,7 @@ export class BehaviorSelect extends AbstractBehavior {
if (!this._enabled || !this.lastClick) return; // nothing to do

const context = this.context;
const eventManager = context.map().renderer.events;
const eventManager = context.mapSystem().renderer.events;

const modifiers = eventManager.modifierKeys;
const disableSnap = modifiers.has('Alt') || modifiers.has('Control') || modifiers.has('Meta');
Expand Down
2 changes: 1 addition & 1 deletion modules/core/ImagerySystem.js
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ export class ImagerySystem extends EventEmitter {
*
*/
chooseDefaultSource() {
const map = this.context.map();
const map = this.context.mapSystem();
const available = this.sources(map.extent(), map.zoom());
const first = available[0];
const best = available.find(s => s.best);
Expand Down
Loading

0 comments on commit 1d5e617

Please sign in to comment.