Ali Zafer Projects

Türkçe oku

Projects

Open source · Maps and spatial data

Pafta

Draw an area on a map, measure it and store it as GeoJSON.

Pafta is an open-source web application that calculates the area, perimeter and centre of a polygon or rectangle the moment it is drawn on the map, and saves the area automatically. Its interface takes its cue from a cadastral map sheet (“pafta” in Turkish); behind it are a small, framework-free PHP REST API and a MariaDB database with a spatial column.

  • Open source · MIT
  • PHP REST API
  • Live demo
  • 11 PHPUnit tests

Explore the project Screenshots

Live demo (opens in a new tab)Source code (opens in a new tab)Documentation (Turkish)

Pafta: a hatched selected area over Antalya with corner handles, coordinate ticks and a title block showing the area
Live demo · selected area

A rewrite of ExeGeo, an earlier map sample project: it treats the same idea not as a learning example but as a validated product with clear limits.

Category
Maps and spatial data application
Project type
Open source (MIT)
Platform
Web · PHP 8.2+ and MariaDB 10.6+
Status
Live · public demo
First release
November 2026 (rewrite of ExeGeo)
Developer
Ali Zafer

The live demo is open to everyone: you can draw and save areas, and the records are reset to sample data every night. Tests run on GitHub Actions on every push with PHP 8.2, 8.3 and 8.4; the schema is loaded twice and checked on MariaDB 10.11.

01Why Pafta?

Drawing an area on a map is easy; measuring it, validating it and storing it as reusable data is a different job.

ExeGeo was a sample project that showed the basics of layers, markers and pop-ups with Leaflet. Pafta takes the same idea to the server: the drawn area is measured with Turf.js, validated by the PHP API and stored in a spatial column in MariaDB.

The interface is framed like a cadastral map sheet: latitude and longitude ticks along the edges that update as you pan, and a title block in the corner with the sheet name, scale, number of areas and total area.

02Product approach

Measure while drawing
Area (m², hectares or km²), perimeter and centre are calculated with Turf.js as you draw.
Automatic saving
A new area is created once; every later change updates the same record, and quick successive edits never create duplicates.
An API with a clear contract
Every response is JSON; errors share one format, and validation errors come back as 422 with a list of details.
Clear limits
At most 60 writes and 20 address searches per minute from the same IP; beyond that the API answers 429 with Retry-After.
Derived data on the server
The bounding box and centre are calculated from the geometry by database triggers; they are never taken from the client.
A well-behaved map
Follows the OpenStreetMap tile and Nominatim policies: attribution, an identifying request, at most one search per second and a one-day cache.

03System architecture

The back end is a small, self-contained PHP application. Only the public/ folder is the web root; source code, templates and settings cannot be reached from outside.

Browser interfaceLeaflet, Leaflet.draw and Turf.js
PHP REST APIFront controller, router and error handling; no framework
ZonesCreate, update and delete areas; paginated list and search
ZoneInputValidation of geometry, name, tags, style and metadata
RateLimitPer-IP write and search limits
PlacesAddress and place search
MariaDBSpatial column, triggers
OpenStreetMap · NominatimMap tiles and address search
The diagram shows the actual structure of the repository (src/Controllers, src/Zones, src/Http).

04Roadmap

  1. Phase 01

    Data exchange

    • GeoJSON and KML import
    • Export a single area or a selection
    • CSV area report
  2. Phase 02

    Working with more data

    • Load areas by the visible map extent (today: the latest 1,000 areas)
    • Intersection and “within” queries with MariaDB spatial functions
    • Overlapping area warning
  3. Phase 03

    Drawing and measuring

    • Undo and redo
    • Distance measuring tool
    • Circle and buffer zones
  4. Phase 04

    Users and sharing

    • Accounts and area ownership
    • Read-only share links
    • Write access with API keys
  5. Long term

    Research areas

    • Satellite and topographic base maps
    • Offline use
    • OpenAPI documentation

The roadmap shows the direction of development; it is not a promise of dates or completion. Features available today are listed under “What works today”.

05Technical approach

  • PHP 8.2+
  • MariaDB spatial column
  • REST API · JSON
  • Leaflet 1.9
  • Leaflet.draw
  • Turf.js
  • PHPUnit
  • GitHub Actions
  • Pinned libraries with SRI

06Validation and security

The API meets everything that comes from outside with clearly bounded rules; the interface escapes every piece of text it receives before displaying it.

  • Name 1–190 characters; generated automatically if empty
  • Only Polygon and MultiPolygon; closed rings of at least 4 points, at most 10,000 points in total
  • At most 20 tags and 8 KB of metadata; only allowed style fields
  • Every query is parameterised
  • 415 if the body is not application/json
  • Error details reach the client only when debugging is enabled

The rules are taken from the README and source code in the repository; they are not the result of an independent security audit.

07What works today

Features available in the live demo and in the repository.

  • Drawing and editingDraw from the toolbar or the keyboard (P polygon, R rectangle); the selected area is hatched and its corners can be dragged.
  • MeasuringArea, perimeter and centre are calculated instantly.
  • StyleFill and stroke colour, opacity, weight and dashed lines, stored with the area.
  • Saved areasServer-side pagination and search by name; download every area as a single GeoJSON file.
  • Address searchShows which area the selected place falls in or, if none, the distance to the nearest area.
  • 81 provinces and keyboardChoosing a province moves the map there; F shows every area, Delete removes, Esc releases.

08Related articles

Articles on the approaches used in this project. The articles are in Turkish.

09Screenshots

Screenshots from the live demo (pafta.execore.cloud), unedited. The areas on the map are the demo’s sample data.

Selected area: hatching, corner handles and measurements
Screen Selected area: hatching, corner handles and measurements
Map sheet view: coordinate ticks, title block and saved areas
Screen Map sheet view: coordinate ticks, title block and saved areas
Wide view: areas and scale
Screen Wide view: areas and scale

Documentation (Turkish)All projects