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

Method enter

modules/modes/DrawLineMode.js:79–152  ·  view source on GitHub ↗

* enter * Enters the mode. * Draw a new line, or optionally continue an existing line. * @param {Object?} options - Optional `Object` of options passed to the new mode * @param {Object} options.continueNodeID - an OSM node to continue from * @param {Object} options.continueWay

(options = {})

Source from the content-addressed store, hash-verified

77 * @return {boolean} `true` if the mode can be entered, `false` if not
78 */
79 enter(options = {}) {
80 const context = this.context;
81 const editor = context.systems.editor;
82 const graph = editor.staging.graph;
83
84 const continueNodeID = options.continueNodeID;
85 const continueWayID = options.continueWayID;
86 const continueNode = continueNodeID && graph.hasEntity(continueNodeID);
87 const continueWay = continueWayID && graph.hasEntity(continueWayID);
88
89 // If either parameter is present, make sure they are both valid
90 if (continueNode || continueWay) {
91 if (!(continueNode instanceof osmNode)) return false;
92 if (!(continueWay instanceof osmWay)) return false;
93
94 if (DEBUG) {
95 console.log(`DrawLineMode: entering, continuing line ${continueWay.id}`); // eslint-disable-line no-console
96 }
97
98 } else { // Start a new line
99 if (DEBUG) {
100 console.log('DrawLineMode: entering'); // eslint-disable-line no-console
101 }
102 }
103
104 this._active = true;
105
106 this.drawWayID = null;
107 this.drawNodeID = null;
108 this.lastNodeID = null;
109 this.firstNodeID = null;
110 this._insertIndex = undefined;
111 this._lastPoint = null;
112 this._selectedData.clear();
113
114 const eventManager = context.systems.gfx.events;
115 eventManager.setCursor('crosshair');
116
117 context.enableBehaviors(['hover', 'draw', 'mapInteraction', 'mapNudge']);
118
119 context.behaviors.hover
120 .on('hoverchange', this._hover);
121
122 context.behaviors.draw
123 .on('move', this._move)
124 .on('click', this._click)
125 .on('finish', this._finish)
126 .on('cancel', this._cancel);
127
128 context.behaviors.mapNudge
129 .on('nudge', this._nudge);
130
131 editor
132 .on('historyjump', this._restoreSnapshot);
133
134 context.behaviors.mapInteraction.doubleClickEnabled = false;
135
136 editor.setCheckpoint('beginDraw');

Callers 3

_finishMethod · 0.45
_cancelMethod · 0.45
_restoreSnapshotMethod · 0.45

Calls 8

_addDrawNodeMethod · 0.95
_refreshEntitiesMethod · 0.95
hasEntityMethod · 0.80
setCursorMethod · 0.80
enableBehaviorsMethod · 0.80
setCheckpointMethod · 0.80
clearMethod · 0.45
onMethod · 0.45

Tested by

no test coverage detected