* 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 = {})
| 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'); |
no test coverage detected