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

Method _click

modules/modes/DrawLineMode.js:396–461  ·  view source on GitHub ↗

* _click * Process whatever the user clicked on. * @param {Object} eventData - Object containing data about the event and what was targeted

(eventData)

Source from the content-addressed store, hash-verified

394 * @param {Object} eventData - Object containing data about the event and what was targeted
395 */
396 _click(eventData) {
397 const context = this.context;
398 const editor = context.systems.editor;
399 const locations = context.systems.locations;
400 const viewport = context.viewport;
401 const point = eventData.coord.map;
402 let loc = viewport.unproject(point);
403
404 if (locations.blocksAt(loc).length) return; // editing is blocked here
405
406 const eventManager = context.systems.gfx.events;
407 eventManager.setCursor('crosshair');
408
409 let graph = editor.staging.graph;
410 let drawNode = this.drawNodeID && graph.hasEntity(this.drawNodeID);
411
412 // Start transaction now - if we are making a draw node, we want it included.
413 editor.beginTransaction();
414
415 // If draw node has gone missing (probably due to undo/redo), replace it.
416 // Note that we don't need the distance checking code here that we have in `_move()`.
417 // If we receive a 'click', we really do need a draw node now!
418 if (this.drawWayID && !drawNode) {
419 drawNode = this._addDrawNode();
420 graph = editor.staging.graph;
421 }
422
423 // Calculate snap, if any..
424 // Allow snapping only for OSM Entities in the current graph (i.e. not Rapid features)
425 const datum = eventData?.target?.data;
426 const choice = eventData?.target?.choice;
427 const target = datum && graph.hasEntity(datum.id);
428 let node, edge;
429
430 // Snap to a node
431 if (target?.type === 'node') {
432 loc = target.loc;
433 node = target;
434
435 // Snap to a way
436// } else if (target?.type === 'way' && choice) {
437// const edge = [ target.nodes[choice.index - 1], target.nodes[choice.index] ];
438// this._clickWay(choice.loc, edge);
439// return;
440// }
441 } else if (target?.type === 'way') {
442 const choice = geoChooseEdge(graph.childNodes(target), point, viewport, this.drawNodeID);
443 const SNAP_DIST = 6; // hack to avoid snap to fill, see #719
444 if (choice && choice.distance < SNAP_DIST) {
445 loc = choice.loc;
446 edge = [ target.nodes[choice.index - 1], target.nodes[choice.index] ];
447 }
448 }
449
450 // Handle whatever was clicked on.
451 // The `_click?` functions below are responsible for calling `_refreshEntities()` and `endTransaction()`
452 // because in certain situations we will be finishing the line and jumping right into `exit()`
453 if (node) {

Callers

nothing calls this directly

Calls 10

_addDrawNodeMethod · 0.95
_clickNodeMethod · 0.95
_clickWayMethod · 0.95
_clickLocMethod · 0.95
geoChooseEdgeFunction · 0.90
blocksAtMethod · 0.80
setCursorMethod · 0.80
hasEntityMethod · 0.80
beginTransactionMethod · 0.80
childNodesMethod · 0.80

Tested by

no test coverage detected