geojson-editor: a browser GeoJSON viewer, editor and RFC 7946 validator I built to learn
GeoJSON looks simple: it is JSON with coordinates in it. Then a file refuses to load somewhere, and you find out how many small rules sit behind that simplicity. A polygon ring that does not close. Latitude and longitude in the wrong order. A ring wound the wrong way. A crs member that the current specification no longer allows. To learn those rules properly, I built the tool I would want when a…
GeoJSON is a simple format that combines JSON with coordinate data. However, there are subtle rules that can cause issues when loading files. To understand these rules fully, I developed a browser-based tool called geojson-editor, which allows users to view, edit, and validate GeoJSON data. This tool, built with MapLibre GL JS and terra-draw, operates entirely in the browser without uploading any data.
The editor supports loading files from various sources, including files, URLs with CORS enabled, or pasting text. It also allows users to draw and edit points, lines, polygons, and rectangles. Users can add, rename, edit, and delete keys in the properties panel, and values are automatically typed based on the input. The editor validates the data against RFC 7946 and highlights any errors or warnings, such as ring closure, incorrect latitude and longitude order, and invalid feature members.
Users can export the final GeoJSON document, with an option to round coordinates and adjust precision. The editor also features autosave functionality, storing the current document in localStorage. To use the tool, simply visit the live demo at https://abdeldjalilchougui.github.io/geojson-editor/. If you prefer to run it locally, you can clone the repository, install dependencies, and start the development server.
The codebase is divided into two main parts: src/lib/ contains pure, DOM-free code that is thoroughly unit tested, while src/main.ts serves as the glue code connecting the components.
Rewritten by urgent.news; may contain errors — check the original.
Source: dev.to