Once a road exists, you can populate it with obstacles. Each obstacle is placed at an exact pixel coordinate within the road canvas and is assigned a type — a cone, rock, tire, and so on. When you submit the form, the coordinate and type are sent to the backend viaDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/tutosrive/avl_tree_car_front/llms.txt
Use this file to discover all available pages before exploring further.
POST /avl/node/add, the backend inserts the obstacle into the AVL tree, and the D3.js tree visualization redraws automatically to reflect the new state. You can add as many obstacles as you like without closing the dialog.
Prerequisites
A road must exist before you can insert obstacles. The Insert Obstacles button (#btn-insert-obstacles) is disabled on the home screen until either:
- A road has been created with the Create Road dialog, or
- Obstacles have been loaded with Load JSON.
Steps
Click Insert Obstacles
Click the Insert Obstacles button (
#btn-insert-obstacles) on the home screen. HomeController ensures that both AVLController and ObstaclesController are initialised, then calls ObstaclesController.init(roadCtrl, avlCtrl, homeCtrl).The controller:- Fetches the
addObstacles.htmltemplate. - Requests the obstacle types list from
GET /data/json/obstacles_types.jsonand builds an<option>list. - Opens the Add Obstacles modal dialog.
- Displays the valid coordinate ranges for the current road in the form.
Fill in the coordinate fields
The form contains two number inputs for the pixel position of the obstacle on the road canvas:
The dialog computes these ranges from the live The
| Field | Element ID | Min | Max | Description |
|---|---|---|---|---|
| X | #obstacle-x | ~5 % of road width | Road width − 15 | Horizontal pixel position from the left edge |
| Y | #obstacle-y | 5 | Road height | Vertical pixel position from the top edge |
Road model and displays them as helper text directly in the form so you always know the valid bounds:min and max HTML attributes on both inputs are set dynamically to these values, so the browser’s native validation also enforces them.Select an obstacle type
Choose a type from the Obstacle Type dropdown (
As soon as you pick a type, a preview image (
#types-obtacles). The list is loaded dynamically from GET /data/json/obstacles_types.json at dialog open time.| # | Type | SVG preview file |
|---|---|---|
| 1 | Cone | cone.svg |
| 2 | Rock | rock.svg |
| 3 | Tree | tree.svg |
| 4 | Tire | tire.svg |
| 5 | Nail | nail.svg |
| 6 | Trunk | trunk.svg |
| 7 | Person | person.svg |
| 8 | Car | car.svg |
| 9 | Bicycle | bicycle.svg |
| 10 | Chair | chair.svg |
#obstacle-preview) updates to show the corresponding SVG icon loaded from ./app/assets/img/svg/<type>.svg. If you revert to the placeholder Select Type option, the preview shows the generic obstacle.svg image.Click Add
Click the Add button. The
ObstaclesController.#addAction() runs the following sequence:- Validates the form (
#form-obstacles) — if any required field is empty or out of range, a warning toast is shown, the out-of-range error message is displayed inside the dialog, and the request is not sent. - Shows an info toast: The data is sending to backend, please wait…
- Disables all modal buttons temporarily to prevent duplicate submissions.
- Constructs an
Obstaclemodel instance from the form data{ x, y, type }. - POSTs to
/avl/node/add:
type field is sent as the obstacle’s numeric ID (the value attribute of the selected <option>).Handle the response
On
status 200 the controller:- Hides the error message container if it was visible.
- Calls
avlCtrl.getTree()— emitsget_tree_avlto the backend, which responds with the updated balanced tree via theavl_tree_balancedSocket.IO event, triggering a full D3.js redraw. - Sets
obstacleObj.idto the ID returned by the backend inreq.data. - Calls
road.setObstacle(obstacleObj)to append the new obstacle to the client-side road model. - Enables the Remove & Watch Roads button if at least one obstacle now exists.
- Re-enables all modal buttons.
Add more obstacles or close the dialog
The modal stays open after a successful insertion. You can immediately enter the next obstacle’s coordinates and type and click Add again. Repeat this for as many obstacles as needed.When you are done, click Accept or Cancel to close the dialog. Both buttons call
ObstaclesController.#closeMenu(), which removes the modal from the DOM and clears the elements reference map.Coordinate validation details
If a submitted value falls outside the allowed range, the controller calls#validateMinAndMax(), which builds an HTML error message and displays it in the #obstacle-error-p element inside the dialog. For example:
visually-hidden) by default and only becomes visible when validation fails. It is cleared automatically on the next successful add.