Territory Walker - Geospatial Tracking Application
Defines a geospatial tracking app with path recording, area claiming, and circle completion using React, Express, PostgreSQL, and Leaflet.
What this file does
Defines a geospatial tracking app with path recording, area claiming, and circle completion using React, Express, PostgreSQL, and Leaflet.
When to use it
- Building a location-based tracking or territory claiming application
- Implementing real-time GPS path recording with visual feedback
- Adding historical path visualization and user authentication to a map app
- Setting up a full-stack geospatial project with Drizzle ORM and Leaflet
Assumes this stack
Territory Walker - Geospatial Tracking Application
Project Overview
Territory Walker is a geospatial tracking application that enables users to log, visualize, and analyze their geographical interactions and claims. Users can walk around, track their paths, claim areas, and complete circles for achievements.
Architecture
- Frontend: React with TypeScript using Vite
- Backend: Express.js with TypeScript
- Database: PostgreSQL with Drizzle ORM
- Mapping: Leaflet for interactive maps
- Styling: Tailwind CSS with shadcn/ui components
- State Management: TanStack React Query for server state
Core Features
User Authentication
- Username/email login or anonymous guest access
- User data persistence across sessions using localStorage
Location Tracking
- Real-time GPS position tracking with accuracy monitoring
- Path recording with timestamp and accuracy data
- Visual feedback for GPS accuracy issues
Path Management
- Active path tracking during user movement
- Previous path visualization on map reload
- Path saving with length and area calculations
- Historical path data retrieval by username
Map Visualization
- Interactive Leaflet map with real-time position updates
- Different visual styles for active vs completed paths
- User path overlays showing travel history
- Claims and completed circles visualization
Area Claiming
- 10-meter radius circular area claiming system
- Overlap detection to prevent duplicate claims
- User territory statistics and leaderboards
Circle Completion
- Detection of completed 10-meter circles during walking
- Achievement tracking with completion time
- Circle visualization on map
Recent Changes (2025-08-03)
Migration to Replit Environment
- Successfully migrated from Replit Agent to Replit environment
- Created PostgreSQL database with proper SSL configuration
- Set up all database tables (users, claims, user_paths, completed_circles, map_view_preferences)
- Fixed cross-env dependency issues for proper Node.js environment handling
- Enhanced internet connectivity error handling with automatic recovery
Internet Connectivity & Error Handling
- Added useNetworkStatus hook for real-time network status monitoring
- Enhanced MapView component with automatic retry when connection returns
- Improved error messages with visual distinction between connection and map errors
- Connection status indicator showing online/offline state
- Automatic map reload when internet connection is restored
- Better tile loading fallbacks with multiple map providers
User Path History Feature
- Added getUserPathsByUsername method in DatabaseStorage class
- Created API endpoint
/api/user-paths/username/:usernamefor fetching historical paths - Enhanced MapView component to fetch and display all user paths on login/reload
- Visual distinction between active paths (blue) and completed paths (gray)
- Path information popups showing length, area, points count, and creation date
New Area Calculation Formula
- Implemented claimed area formula:
Area = (distance * 2 * r) + (π * r²) - Updated calculateClaimedArea function in geometry utilities
- Modified location tracker to use new formula for real-time area calculation
- Enhanced total area tracking with corridor and circular end cap calculations
- Formula parameters: r = 10 meters (path radius), distance = total path length
Database Schema
- userPaths table stores path data with JSON point arrays
- Foreign key relationships link paths to users
- isActive field distinguishes between current and historical paths
Frontend Improvements
- Real-time path fetching when map loads
- Historical path rendering with different visual styles
- Path popup information with detailed statistics
- Error handling for malformed path data
- Network connectivity monitoring with automatic recovery
User Preferences
- Users want to see their previous traveled paths when logging in with the same username
- Paths should be visually distinct between active and completed states
- Path information should be accessible via map popups
Technical Implementation Details
Path Data Structure
{
lat: number,
lng: number,
timestamp: number,
accuracy?: number
}
API Endpoints
GET /api/user-paths/user/:userId- Get paths by user IDGET /api/user-paths/username/:username- Get paths by usernameGET /api/user-paths/active/:userId- Get active path for userPOST /api/user-paths- Create new pathPUT /api/user-paths/:id- Update existing path
Database Initialization
- Automatic table creation on application startup for new environments
- Database migration handling with proper error handling and validation
- Cross-platform compatibility for both Replit and local development environments
Known Issues Resolved
- ✅ Fixed foreign key constraint violations with automatic database initialization
- ✅ Resolved cross-environment database setup with dbInit.ts module
- ✅ Enhanced error handling for database connection and initialization failures
Documentation & Setup
- Created comprehensive setup guide with database configuration examples
- Added .env.example template for easy environment variable setup
- Included troubleshooting section for common deployment issues
- Cross-platform setup instructions for Replit, local, and cloud environments
User Preferences
- Users want clear setup instructions for different deployment environments
- Prefer automatic database initialization over manual table creation
- Need troubleshooting guidance for common connection and map loading issues
Next Steps
- Implement proper user session management with authentication persistence
- Add path filtering and search capabilities for historical data
- Enhance mobile GPS accuracy handling with better algorithms
- Add real-time collaboration features for shared territory claiming
What's inside
10 feature sections, 5 API endpoints, 1 TypeScript data structure, 1 database schema description, and a changelog.
Change this for your project
- Replace
jalajsharma172/Earthclaimwith your own repository name - Replace
r = 10 meterswith your desired claim radius - Replace
Territory Walkerwith your application name throughout
Where it goes
Keep it in your repository where the agent or team that needs it will read it.
Worth borrowing
- Using a
useNetworkStatushook to monitor connectivity and auto-retry map loading - Distinguishing active vs completed paths with different visual styles (blue vs gray)
- Storing path data as JSON point arrays with timestamps and accuracy metadata
Related Documents
GOOBY - Closing Store Marketplace
Defines a full-stack marketplace app for discovering closing retail stores in NY/NJ/CT/PA, with automated closure scanning and admin review.
Lua Code Obfuscator/Deobfuscator
Provides a full-stack web app for obfuscating and deobfuscating Roblox Lua scripts with a Monaco editor and PostgreSQL storage.
GREEN NODE - Project Overview
Describes a full-stack recycling platform with three runtime modes, provider architecture, and development scripts for Cochabamba, Bolivia.
ADN Systems DMR Peer Server
Documents a forked FreeDMR server for amateur radio DMR voice/data routing with bridges, proxies, scheduled voice announcements, and centralized security.