An interactive web-based map visualization tool for testing and debugging geofencing logic. This tool displays real-time badge locations, geofence boundaries, and visual indicators for geofence events.
- Real-time Badge Tracking: Display badge locations (lat/lon) as points or circles (with radius)
- Geofence Visualization: Display geofence boundaries as GeoJSON polygons
- Event Indicators: Visual feedback for events:
enter: Green flash/animationexit: Red flash/animationcross: Yellow/orange flash (radius extends outside)inside: Blue indicatoroutside: Gray indicator
- Testing Tools:
- Manual badge placement by clicking on map
- Radius adjustment for badges
- Import/Export test scenarios as JSON
- Real-time Updates: MQTT/WebSocket integration for live data
- Event Log: History of recent geofence events
- Statistics Dashboard: Track badges, geofences, and event counts
- Frontend: React + Vite
- Mapping: Leaflet.js
- Real-time: Socket.io (WebSocket)
- Backend: Express.js
- MQTT: mqtt.js
- Node.js 18+ and npm
- MQTT broker (e.g., Mosquitto, Mainflux)
- Access to geofence data source
- Install frontend dependencies:
cd geofence-visualizer
npm install- Install server dependencies:
cd server
npm install- Configure MQTT connection (optional):
- Set environment variables or edit
server/index.js:
export MQTT_BROKER=mqtt://localhost:1883 export MQTT_USERNAME=your_username export MQTT_PASSWORD=your_password export MQTT_TOPIC_BADGES=old/assets/+/location export MQTT_TOPIC_GEOFENCE=geofence/+
- Set environment variables or edit
- Start the backend server (in one terminal):
cd server
npm start- Start the frontend dev server (in another terminal):
npm run dev- Open your browser:
- Frontend: http://localhost:3000
- Backend API: http://localhost:3001
- Build the frontend:
npm run build- Serve the built files (you can use any static file server):
npm run previewThe tool automatically connects to the MQTT broker configured in the server. Check the connection status in the top-right corner of the interface.
- Click "+ Add Badge" in the control panel
- Enter:
- MAC address
- Latitude
- Longitude
- Radius (optional, in feet)
- Click "Add"
- Enable "Test Mode" in the controls
- Select a badge from the badge list
- Click anywhere on the map to move the badge
- Adjust radius using the slider/input for the selected badge
Geofences can be added by:
- Importing from GeoJSON file (
.geojsonextension):- Click "Import GeoJSON" button in the Geofences section
- Supports standard GeoJSON formats:
- FeatureCollection (multiple geofences)
- Feature (single geofence)
- Polygon/MultiPolygon (direct geometry)
- Array of geofences
- Geofence names are extracted from
properties.nameorproperties.id - MAC addresses are extracted from
properties.mac(optional)
- Importing from JSON file (see example data format below)
- Receiving via MQTT/WebSocket
Note: The tool specifically supports .geojson file extension for geofence imports.
- Import Badges/Geofences: Click "Import Data" and select a JSON file
- Import Geofences Only: Click "Import GeoJSON" and select a
.geojsonfile - Export All Data: Click "Export Data" to save badges and geofences as JSON
- Export Geofences as GeoJSON: Click "Export as GeoJSON" to save geofences in standard GeoJSON format
{
"mac": "feed31446a32",
"latitude": 28.59448340810775683408107756,
"longitude": 77.200186828551038682855103,
"radius": 20.5
}Standard GeoJSON Format (for .geojson files):
{
"type": "FeatureCollection",
"features": [
{
"type": "Feature",
"properties": {
"name": "DelhiHall1",
"mac": "feed31446a32"
},
"geometry": {
"type": "Polygon",
"coordinates": [[
[77.20018682855103, 28.594483408107756],
[77.2002, 28.5945],
[77.2003, 28.594483408107756],
[77.20018682855103, 28.594483408107756]
]]
}
}
]
}Custom Format (for JSON test data files):
{
"name": "DelhiHall1",
"mac": "feed31446a32",
"polygon": {
"type": "Polygon",
"coordinates": [[
[77.20018682855103, 28.594483408107756],
[77.2002, 28.5945],
[77.2003, 28.594483408107756],
[77.20018682855103, 28.594483408107756]
]]
}
}{
"detect": "enter",
"id": "feed31446a32",
"hook": "geofence_feed31446a32_DelhiHall1",
"object": {
"type": "Polygon",
"coordinates": [[...]]
},
"time": "2025-11-05T03:46:41Z"
}{
"badges": [
{
"mac": "feed31446a32",
"latitude": 28.59448340810775683408107756,
"longitude": 77.200186828551038682855103,
"radius": 20.5
}
],
"geofences": [
{
"name": "DelhiHall1",
"mac": "feed31446a32",
"polygon": {
"type": "Polygon",
"coordinates": [[[77.20018682855103, 28.594483408107756], ...]]
}
}
]
}The tool fully supports importing geofences from .geojson files. Supported formats include:
-
FeatureCollection (recommended for multiple geofences):
{ "type": "FeatureCollection", "features": [ { "type": "Feature", "properties": { "name": "Geofence1" }, "geometry": { "type": "Polygon", "coordinates": [...] } } ] } -
Single Feature:
{ "type": "Feature", "properties": { "name": "Geofence1" }, "geometry": { "type": "Polygon", "coordinates": [...] } } -
Direct Polygon Geometry:
{ "type": "Polygon", "coordinates": [[...]] }
See example-geofences.geojson for a complete example.
The server subscribes to:
- Badge locations:
old/assets/+/location(wildcard for MAC address) - Geofence events:
geofence/+(wildcard for MAC address)
MQTT_BROKER: MQTT broker URL (default:mqtt://localhost:1883)MQTT_USERNAME: MQTT username (optional)MQTT_PASSWORD: MQTT password (optional)MQTT_TOPIC_BADGES: Badge location topic (default:old/assets/+/location)MQTT_TOPIC_GEOFENCE: Geofence event topic (default:geofence/+)PORT: Server port (default:3001)
- MQTT not connecting: Check broker URL and credentials
- WebSocket not connecting: Ensure server is running on port 3001
- No data appearing: Verify MQTT topics match your broker configuration
- Map not loading: Check internet connection (uses OpenStreetMap tiles)
- Badges not showing: Verify badge data has valid lat/lon coordinates
- Geofences not rendering: Check GeoJSON polygon format
geofence-visualizer/
├── src/
│ ├── components/
│ │ ├── BadgeLayer.jsx # Badge visualization
│ │ ├── GeofenceLayer.jsx # Geofence visualization
│ │ ├── ControlPanel.jsx # Control panel UI
│ │ ├── EventLog.jsx # Event log display
│ │ └── StatisticsPanel.jsx # Statistics dashboard
│ ├── utils/
│ │ └── geometry.js # Geometry utilities
│ ├── App.jsx # Main app component
│ └── main.jsx # Entry point
├── server/
│ └── index.js # Express + Socket.io server
└── package.json
- Drawing Tools: Integrate Leaflet.draw for polygon editing
- Historical Playback: Add time-based replay of badge movements
- Multiple Map Providers: Add Mapbox, Google Maps support
- Geofence Editor: Visual polygon editor on the map
See project license file.
For issues and questions, refer to the main project documentation or create an issue in the repository.