A Next.js application that displays an interactive map with school pins in Wrocław, Poland. Users can select a position on the map and generate isochrone polygons showing areas reachable within specified time ranges using different transport methods.
- Interactive Map: Click anywhere on the map to select an origin point
- School Pins: View schools in Wrocław, Poland with location markers
- Transport Modes: Switch between driving, walking, and cycling
- Time Ranges: Multiple preset options (5, 10, 15, 30, 60 minutes) plus custom time input
- Isochrone Visualization: Colored polygons showing reachable areas from the selected origin
- Responsive Design: Works on desktop and mobile devices
- Framework: Next.js 16 (App Router)
- Language: TypeScript
- Styling: Tailwind CSS
- Map Library: Leaflet with react-leaflet
- Isochrone API: OpenRouteService
- Analytics: Google Analytics 4
- Deployment: Vercel
The application includes Google Analytics 4 (GA4) integration for tracking user interactions. To enable it:
- Create a Google Analytics 4 property in your Google Analytics account
- Get your Measurement ID (format:
G-XXXXXXXXXX) - Add it to your
.env.localfile asNEXT_PUBLIC_GA_ID
The following events are automatically tracked:
- Origin Selection: When users select a point on the map
- Isochrone Generation: When isochrones are generated (includes transport mode and time range)
- School List Interactions: Sorting, filtering, and focusing on schools
- Filter Changes: When users change filter settings
- Page Views: Automatic page view tracking
You can also use the analytics utility functions in lib/analytics.ts to track custom events.
- Node.js 20.19.0 or higher (or 22.13.0+ or >=24)
- npm, yarn, pnpm, or bun
- OpenRouteService API key (Get one here)
- Clone the repository:
git clone <repository-url>
cd school-stats- Install dependencies:
npm install- Create a
.env.localfile in the root directory:
OPENROUTESERVICE_API_KEY=your_api_key_here
NEXT_PUBLIC_GA_ID=your_google_analytics_id_here # Optional: G-XXXXXXXXXX or UA-XXXXXXXXX-X- Generate geocoded school data (first time setup):
npm run geocode-schoolsThis will geocode all Wrocław schools from data/output/merged-schools.json and merge the coordinates into a new file merged-schools-geocoded.json. This may take a while due to API rate limits (approximately 1 request per second).
- Run the development server:
npm run dev- Open http://localhost:3000 in your browser.
school-stats/
├── app/
│ ├── api/
│ │ ├── isochrones/
│ │ │ └── route.ts # API route for OpenRouteService
│ │ └── schools/
│ │ └── route.ts # API route for schools data
│ ├── components/
│ │ ├── Map.tsx # Main map component with Leaflet
│ │ ├── TransportSelector.tsx # Transport mode selector
│ │ └── TimeRangeSelector.tsx # Time range selector
│ ├── layout.tsx # Root layout
│ ├── page.tsx # Main page component
│ └── globals.css # Global styles
├── data/
│ ├── output/
│ │ ├── merged-schools.json # Merged school data (source)
│ │ ├── merged-schools-geocoded.json # School data with coordinates (generated)
│ │ └── geocode-cache.json # Temporary cache during geocoding
│ └── raw/ # Raw data files
├── lib/
│ ├── schools.ts # School data loader with caching
│ ├── geocoding.ts # Geocoding utilities
│ └── types.ts # TypeScript type definitions
├── scripts/
│ └── geocode-schools.ts # Script to geocode all schools
└── public/ # Static assets
- Select Origin: Click anywhere on the map to set the origin point for isochrone calculation
- Choose Transport: Select your preferred transport method (Driving, Walking, or Cycling)
- Set Time Ranges:
- Click preset buttons (5, 10, 15, 30, 60 minutes) to add/remove time ranges
- Enter a custom time in minutes (optional)
- View Results: Colored polygons will appear showing areas reachable within each time range
The application uses the OpenRouteService API for isochrone calculations. The API is called through a Next.js API route (/api/isochrones) which:
- Accepts coordinates, transport profile, and time ranges
- Proxies requests to OpenRouteService
- Returns GeoJSON FeatureCollection with polygon geometries
- Endpoint:
https://api.openrouteservice.org/v2/isochrones/{profile} - Free Tier: Limited requests per day (check OpenRouteService pricing)
- Transport Profiles:
driving-car- Car/Drivingfoot-walking- Walkingcycling-regular- Cycling
-
Push your code to a Git repository (GitHub, GitLab, or Bitbucket)
-
Import your project to Vercel:
- Go to Vercel
- Click "New Project"
- Import your repository
-
Add environment variable:
- In project settings, add
OPENROUTESERVICE_API_KEYwith your API key
- In project settings, add
-
Deploy:
- Vercel will automatically deploy on every push to main branch
The app will be available at https://your-project.vercel.app
Create a .env.local file (or set in Vercel dashboard):
OPENROUTESERVICE_API_KEY=your_api_key_here
NEXT_PUBLIC_GA_ID=your_google_analytics_id_here # Optional: G-XXXXXXXXXX
npm run dev- Start development servernpm run build- Build for productionnpm run start- Start production servernpm run lint- Run ESLintnpm run geocode-schools- Geocode all schools (generates coordinates cache)npm run merge-schools- Merge raw school data files
The application loads school data from data/output/merged-schools-geocoded.json. This file contains:
- School name, address, and location
- Exam results by year
- School type and public/private status
- Coordinates (geocoded addresses) - added by the geocoding script
Schools are filtered to only show those in Wrocław that have coordinates. The data is cached in memory for optimal performance (1 hour cache duration).
Since the source data doesn't include coordinates, schools need to be geocoded first. The geocode-schools script:
- Loads all schools from
data/output/merged-schools.json - Filters for Wrocław schools
- Geocodes each address using OpenStreetMap Nominatim API
- Merges coordinates back into the school data
- Saves everything to
data/output/merged-schools-geocoded.json - Respects rate limits (1 request per second)
The geocoded file contains all schools with coordinates added for Wrocław schools. If new schools are added or addresses change, re-run the geocoding script to update the geocoded file.
- Leaflet components are dynamically imported to avoid SSR issues
- The map is centered on Wrocław, Poland (51.1079°N, 17.0385°E)
- School data is currently hardcoded in
lib/schools.ts - Isochrone polygons are color-coded by time range (green for short times, red for longer times)
This project is open source and available under the MIT License.