How rajtoshranjan/earth works
Main Project and Purpose Overview
• The project is a rich interactive web application for exploring a 3D representation of Earth’s surface, featuring map interactions (zoom, pan), search, measurement tools, and layer management (both raster and vector).
• It is built primarily as a single-page application (SPA) using React while integrating Maplibre GL JS and custom hooks for managing map layers and interactions.
And List the Key Architectural Components
• User Interface Components:
• The Header component (providing search functionality and navigation).
• The Layer Panel (for adding layers, drawing features, and handling map overlays).
• The Map Container, which holds the interactive map view.
• Application Core:
• React entry point (src/main.tsx and src/app.tsx) that bootstraps the application.
• Global context (src/contexts) used for state management across components.
• Custom hooks under src/core/hooks, especially use-maplibre-layers, which encapsulate business logic related to managing the map’s layers and integrating with Maplibre.
• Maplibre integration housed in src/core/maplibre with utilities for map setup, initialization, and operations.
• Services and External APIs:
• API service for Maptiler (located in src/services/apis/maptiler) which likely provides map data, tiles, or geolocation services.
• Firebase configurations and GitHub workflows hint at CI/CD and hosting deployments, even if not strictly part of the application’s runtime logic.
• Assets and Styling:
• Tailwind CSS and PostCSS configurations indicate that styling is done using a utility-first approach.
• Environment and Configuration:
• Environment variables are managed via the env-files folder.
• Various config files (.eslintrc.js, tsconfig.json, vite.config.ts) ensure code quality, type safety, and build processes.
Relationships & Interactions between Components
• The User interacts with the UI elements (Header, Buttons, Inputs, etc.), which are implemented as React components.
• User actions in components trigger state changes via the global context and custom hooks.
• The Map Container communicates with the underlying Maplibre layer (through components in src/core/maplibre and hooks in src/core/hooks) to update map views and render layers.
• When layer changes or map interactions occur, the application might call external APIs (such as Maptiler, via the services layer) to fetch additional map data.
• The entire UI is stitched together through React’s component composition and state management. Configuration files and build scripts ensure proper development and deployment flows.
Important Architectural Patterns and Principles
• Component-Based Architecture: Clear separation into UI components (modular and reusable).
• Custom Hooks: Encapsulate map-related logic and side effects.
• State Management via Context API: Provides global state persistence (such as storing map state in local storage as mentioned in the README).
• Separation of Concerns: Distinct directories handle assets, business logic (core and hooks), UI presentation (components/ui), and external integration (services).
• Deployment & Quality Controls: CI/CD workflows (GitHub Actions for linting, testing, and Firebase deployment) and well-defined configuration files uphold best practices.