Overview
TheApp component is the root component of the React Route Finder application. It manages the application state, coordinates the route finding process, and integrates with Google Maps to visualize routes and markers.
Component Structure
The App component is a class-based React component that renders the main application layout and manages:- Route data state
- Google Maps markers
- Route finding operations
- Map visualization updates
State
Stores the current route data returned from the server. Initially an empty object
{}.An array of Google Maps marker instances. Managed as an instance variable rather than state.
Methods
findRoute
Sends a POST request to the server to find an optimal route between two coordinates.Object containing
from and to coordinates with lat and lng properties.- Sends route data to
/routeendpoint - Updates component state with the returned route
- Calls
updateMarkersto visualize the route on the map - Handles errors if the request fails
updateMarkers
Updates the Google Maps visualization by placing markers for each stop in the route and drawing the optimized path.Array of stop objects, each containing
latitude, longitude, id, and name properties.- Removes all existing markers from the map
- Creates new markers for each stop with labels and titles
- Configures waypoints (all stops except first and last)
- Requests optimized driving directions from Google Maps
- Displays the route with custom markers (suppressing default markers)
Google Maps Initialization
The Google Maps integration is initialized globally when the application loads:- Default Center: Buenos Aires coordinates (-34.6037, -58.3816)
- Zoom Level: 12
- Map Element: References the
#mapDOM element - Uses Google Maps Directions API for route calculation and rendering
Render Method
- RouteForm - Input form for entering origin and destination coordinates
- Result - Displays the calculated route instructions
Usage
The App component is defined and immediately rendered insrc/client/index.jsx:
app. The Google Maps container is initialized globally after the render call with id map.
The App class is not exported from index.jsx - it’s an internal implementation that’s rendered directly to the DOM.
File Location
src/client/index.jsx