This project is not covered by Drupal’s security advisory policy.
Turf.js brings fast, client-side geospatial analysis to Drupal. It makes the Turf.js library available on your site, so maps and forms can measure areas and distances, find centroids, draw buffers and run other spatial operations directly in the visitor's browser, with no extra server load.
Turf.js is a widely used open source JavaScript library for spatial analysis. It works with standard GeoJSON data and includes measurement, transformation, aggregation, classification and helper functions. This module connects Turf.js to Drupal so site builders and developers can use it without managing script tags or build tools by hand.
Features
- Registers Turf.js as a standard Drupal library (
turf/turf) that any module or theme can attach. - Loads the library from a local copy in
/libraries/turfor from a CDN pinned to a specific major version, so a new Turf.js release cannot break your site without warning. - Exposes the global
turfobject to Drupal behaviors, so custom JavaScript can run spatial operations on map data, form input or GeoJSON delivered by Views. - Includes Geofield formatters that calculate area, length, centroid and bounding box in the browser and show the results next to (or instead of) the stored geometry.
When to use it:
- Showing the area of a parcel or the length of a route while a user draws it on a map widget.
- Checking whether a point falls inside a service area or administrative boundary without a round trip to the server.
- Drawing buffers around features (for example a 500 m zone around a school) for display.
- Simplifying or clipping large geometries before they are rendered on a map.
- Prototyping spatial features quickly before moving heavier analysis to the database.
Post-Installation
- Install the Turf.js library (see Additional Requirements) or choose the CDN option.
- Enable the module as usual.
- Go to Configuration > System > Turf.js settings to choose the library source (local or CDN) and the version to load.
- To use the formatters, go to Manage display on any entity type with a Geofield and choose one of the Turf.js formatters.
- Developers can attach the library in a render array with
'#attached' => ['library' => ['turf/turf']]or listturf/turfas a dependency in their own*.libraries.ymlfile.
The module adds no content types, text formats or database tables. All calculations run in the browser, so results are meant for display and interaction rather than for authoritative storage.
Additional Requirements
- Drupal 10.3 or 11.
- The Turf.js library (MIT licensed), version 7.x. With Composer and Asset Packagist configured, install it with
composer require npm-asset/turf--turf, or downloadturf.min.jsand place it at/libraries/turf/turf.min.js. You can also use the CDN option and skip the local copy.
Recommended modules/libraries
- Geofield: required for the included field formatters, and the most common way to store geometries in Drupal.
- Leaflet or OpenLayers: map display and drawing widgets that pair naturally with live Turf.js calculations.
- ECA Geofield: server-side PostGIS operations, for when results need to be stored or used in workflows.
Similar projects
Geofield uses geoPHP to process geometries on the server when content is saved or rendered. This module works in the browser instead, which suits interactive, instant feedback and avoids loading the server for display-only calculations.
PostGIS-based modules such as ECA Geofield run analysis in the database and are the right choice when results must be stored, queried or trusted. The two approaches complement each other: Turf.js for live interaction, the database for authoritative results.
Map modules such as Leaflet and OpenLayers display geometries and may offer basic measuring tools, but they do not provide a general-purpose spatial analysis API.
Supporting this Module
The best way to support this module is to test it, report bugs and contribute patches or merge requests in the issue queue. To support the Turf.js library itself, see its Open Collective page.
Community Documentation
Note: Turf.js expects coordinates in longitude, latitude order (WGS 84), as in the GeoJSON specification. Make sure data from other sources uses the same order before passing it to Turf.js functions.
Project information
- Project categories: Integrations
- Created by orkutmuratyilmaz on , updated
This project is not covered by the security advisory policy.
Use at your own risk! It may have publicly disclosed vulnerabilities.

