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

Method _clickNode

modules/modes/DrawLineMode.js:608–681  ·  view source on GitHub ↗

* _clickNode * Clicked on a target node, include that node in the line we are drawing.

(loc, targetNode)

Source from the content-addressed store, hash-verified

606 * Clicked on a target node, include that node in the line we are drawing.
607 */
608 _clickNode(loc, targetNode) {
609 const EPSILON = 1e-6;
610 const context = this.context;
611 const editor = context.systems.editor;
612
613 let graph = editor.staging.graph;
614 let drawWay = this.drawWayID && graph.hasEntity(this.drawWayID);
615 let drawNode = this.drawNodeID && graph.hasEntity(this.drawNodeID);
616 let lastNode = this.lastNodeID && graph.hasEntity(this.lastNodeID);
617 let firstNode = this.firstNodeID && graph.hasEntity(this.firstNodeID);
618
619 // Extend line by reusing target node as a vertex...
620 // (Note that we don't need to replace the draw node in this scenario)
621 if (drawWay) {
622
623 // Target node is the last node - finish the line here.
624 if (targetNode.id === lastNode.id || vecEqual(loc, lastNode.loc, EPSILON)) {
625 this._finish();
626 return;
627 }
628
629 if (DEBUG) {
630 console.log(`DrawLineMode: _clickNode, extending line to ${targetNode.id}`); // eslint-disable-line no-console
631 }
632
633 editor.perform(
634 this._actionRemoveDrawNode(drawWay, drawNode), // Remove the draw node from the draw way
635 actionAddVertex(drawWay.id, targetNode.id, this._insertIndex) // Add target node to draw way
636 );
637
638 // If the line has enough segments, commit the work in progress so we can undo/redo to it.
639 const annotation = this._getAnnotation();
640 if (annotation) {
641 editor.commit({ annotation: annotation, selectedIDs: [drawWay.id] });
642 this._takeSnapshot(firstNode.id, targetNode.id);
643 }
644
645 // Target node is the first node - we just closed the line and can finish it.
646 if (targetNode.id === firstNode.id || vecEqual(loc, firstNode.loc, EPSILON)) {
647 this._finish();
648 return;
649
650 // Target node is some other node - put the draw node back and continue drawing..
651 } else {
652 this.lastNodeID = targetNode.id;
653 editor.perform(
654 actionAddEntity(drawNode),
655 actionAddVertex(drawWay.id, drawNode.id, this._insertIndex)
656 );
657 }
658
659 // Start a new line at target node...
660 } else {
661 if (DEBUG) {
662 console.log(`DrawLineMode: _clickNode, starting line at ${targetNode.id}`); // eslint-disable-line no-console
663 }
664
665 drawNode = osmNode({ loc: loc });

Callers 1

_clickMethod · 0.95

Calls 13

_finishMethod · 0.95
_actionRemoveDrawNodeMethod · 0.95
_getAnnotationMethod · 0.95
_takeSnapshotMethod · 0.95
_refreshEntitiesMethod · 0.95
actionAddVertexFunction · 0.90
actionAddEntityFunction · 0.90
osmNodeFunction · 0.90
osmWayFunction · 0.90
hasEntityMethod · 0.80
performMethod · 0.80
commitMethod · 0.80

Tested by

no test coverage detected