Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

CRUD Web GIS: Build Process

CRUD Web GIS: Build Process

Interactive webmap for CRUD operations on spatial layers with Leaflet and PostGIS. Leaflet • PHP • PostGIS

Stack: Leaflet, PHP, PostGIS
Data: Infrastructure layers (valves, pipelines, buildings)
Goal: Enable CRUD workflows directly on the map

Get started by clicking the home button 🏠 at the top left and filtering to your desired locality. Create features, update attributes and delete features below 👇.

Live Webmap

If the embed does not load, open: https://webmap.kunmiadebanjo.com/

How to Use the Webmap

  1. Open the live webmap and choose a DMA from the sidebar to load features.

  2. Click a feature to inspect attributes in the popup.

  3. Use the edit tools in the popup to update or delete a feature.

  4. Use the sidebar forms to add new valves, pipelines, or buildings.

Quick Overview

Architecture

High-level flow

  1. User loads the webmap and selects a DMA (area filter).

  2. Frontend calls backend endpoints to load features by DMA.

  3. GeoJSON is returned and rendered by Leaflet with styling and tooltips/popups.

  4. Edits and deletes occur from popups, inserts from sidebar forms, all handled via AJAX POST to PHP endpoints.

Frontend build (Leaflet UI)

Key file: index.php

Libraries and plugins

Map setup

Layer logic

Each layer includes:

Drawing + insert workflow

Geoman drawing creates a geometry, then writes GeoJSON into a hidden textarea:

Insert forms collect attributes + geometry and POST to insert_data.php.

Backend build (PHP + PostGIS)

Key files: init.php, load_data.php, find_data.php, insert_data.php, update_data.php, delete_data.php

Database connection

init.php reads database config from /home/kunmiade/config/db.php or environment variables:

If config is missing, the API exits with an error.

Write security token

Write operations require a token (via header X-WEBMAP-TOKEN or POST token). Token is read from config or WEBMAP_WRITE_TOKEN environment variable.

Read endpoints

Both endpoints return GeoJSON FeatureCollections using ST_AsGeoJSON(geom).

Write endpoints

Data model (as used by the app)

Tables referenced by the frontend:

Deployment notes

What I would improve next