Skip to content
gaopengbinPublic

About

AI-friendly toolkit for map styling — schema, compiler, and prompt manual for SLD (and beyond).

Resources

Contributing

Stars

1 star

Watchers

0 watching

Forks

Repository files navigation

OpenStyle — A shared grammar for AI cartography

OpenStyle

A shared map grammar. Controlled edits. Explicit renderer capabilities.
Structured styles · Deterministic compilation · Evidence-based review

CI MIT License v0.7.0 prerelease

简体中文 · Runnable example · Download · GeoStyle


OpenStyle is an open-source TypeScript toolkit for AI-assisted cartography. It separates map representation, deterministic compilation and review utilities so applications can design, edit and inspect styles over real geographic data.

Early alpha · v0.7.0 prerelease — Download the eight-package installation bundle from GitHub Releases. npm publication is not complete; APIs may change.

Why

Map styling should be grammar-checked before it leaves the model. openstyle gives AI agents a bounded shape to fill in, a deterministic compiler that turns that shape into standards-compliant SLD, and a curated prompt manual so the model doesn't have to invent OGC XML from memory.

The toolkit separates map representation, compilation and creation policies:

  1. Schema (@openstyle/schema) — the JSON shape (with zod runtime validation) that an LLM must produce. Small, opinionated, complete for real cartography needs (scale layering, classification, labels, symbolizers).
  2. Compiler (@openstyle/compiler) — turns a validated StyleModel into strict OGC SLD 1.0 XML. No LLM ever touches <sld:...>.
  3. Manual + AI helpers (@openstyle/manual, @openstyle/ai) — a distilled version of the GeoServer SLD Cookbook, plus system-prompt builders and field-reference validators, so any AI agent can pick up the format quickly.
  4. Cartography (@openstyle/cartography) — canonical map patches, classification-aware road casing, compact review context, pixel diagnostics and bounded repair decisions. Applications bring their own renderer capture, model transport and persistence.

One grammar, explicit adapter boundaries

flowchart LR
    A[Application / AI agent] --> V[Schema validation]
    V --> S[StyleModel: one layer]
    V --> M[OpenStyle: whole map]
    S --> C[SLD compiler]
    C --> G[GeoServer]
    S --> O[OpenLayers adapter]
    M --> O
    M --> L[MapLibre adapter]
    M <--> P[Controlled edits and review]
Loading

Adapters declare their capabilities and report unsupported expressions; rendering parity is not assumed. Applications supply data, captures, model transport, accounts and persistence. Successful compilation and pixel diagnostics are not visual acceptance.

Used in a real product

GeoStyle Yangshuo field atlas, actual map render
Yangshuo · Field atlas
GeoStyle Gardiner atlas, actual map render
Gardiner · Yellowstone River atlas

GeoStyle uses OpenStyle for structured 2D styles and reusable cartography logic. These are actual application renders, including application-specific materials and human review, not outputs of a standalone compiler call. Image credits · Explore GeoStyle

Packages

Package Description
@openstyle/schema StyleModel TypeScript type + zod schema + validators
@openstyle/compiler compileToSld / formatSld — deterministic SLD 1.0 emitter
@openstyle/cartography Atomic map edits, casing, render diagnostics and review contracts
@openstyle/adapter Renderer capability declarations and negotiation
@openstyle/openlayers compileToOpenLayers — deterministic OpenLayers StyleFunction adapter
@openstyle/maplibre compileOpenStyleToMapLibre — deterministic MapLibre Style Specification adapter with explicit capability negotiation
@openstyle/manual Cookbook-distilled prompt manual (scale ladders, palettes, few-shot)
@openstyle/ai Prompts, validators, request policies and output-budget decisions

The reusable GeoStyle creation functions are implemented in this repository and consumed by GeoStyle. Version 0.7.0 is distributed as a GitHub prerelease; npm publication is separate and has not been completed. See the extraction record, offline workflow example, and release instructions.

Quick start

Download and try

Download openstyle-0.7.0-bundle.zip from the v0.7.0 release, extract it, and run pnpm install inside its directory. The bundle pins all eight OpenStyle packages to included tarballs; external dependencies still need registry access or a populated pnpm cache. Then import the packages normally:

import { StyleModelSchema } from "@openstyle/schema";
import { compileToSld } from "@openstyle/compiler";

const model = StyleModelSchema.parse({
  name: "population_choropleth",
  geom: "polygon",
  classification: {
    field: "POP_DENS",
    classes: [
      { label: "Low",  filter: { op: "lt",  value: 100  }, symbolizer: { kind: "polygon", fill: "#f7fbff" } },
      { label: "High", filter: { op: "gte", value: 100 }, symbolizer: { kind: "polygon", fill: "#08306b" } },
    ],
  },
});

const sld = compileToSld(model);
// -> "<StyledLayerDescriptor ...>...</StyledLayerDescriptor>"

Run a complete example without model credentials

After installing and building from source, run:

node examples/cartography-workflow/run.mjs

The example replays two real style edits, checks road casing, compiles two renderer targets and exercises review and request policies. It makes no model or map-service requests. Pixel checks use a labeled calibration pattern, not browser acceptance of a real map. Inspect the inputs, assertions and output.

Repo layout

openstyle/
├── packages/
│   ├── schema/     # zod schema + types
│   ├── compiler/   # SLD 1.0 XML emitter
│   ├── cartography/ # controlled edits, evidence and workflow contracts
│   ├── adapter/    # renderer capability negotiation
│   ├── maplibre/   # MapLibre whole-map adapter
│   ├── manual/     # AI prompt manual & few-shot library
│   ├── ai/         # system-prompt builder + validators
│   └── openlayers/ # OpenLayers StyleFunction adapter
├── apps/
│   └── docs/       # VitePress documentation site
├── skills/         # Claude Code skills (sld-generator, sld-review, sld-cookbook)
├── examples/       # end-to-end demos
└── .changeset/     # release notes

Develop from source

git clone https://github.com/gaopengbin/openstyle.git
cd openstyle
pnpm install --frozen-lockfile
pnpm build
pnpm typecheck
pnpm test

Requires Node ≥ 18.18; the repository pins pnpm 10.32.1. The release workflow uses Node 22. Build first so downstream packages can resolve the generated type declarations.

References

Contributing

See CONTRIBUTING.md. Issues and PRs welcome once the schema stabilizes.

License

MIT © 2026 gaopengbin and openstyle contributors


Built by Laogao · GeoStyle · Issues & feedback

About

AI-friendly toolkit for map styling — schema, compiler, and prompt manual for SLD (and beyond).

Resources

Contributing

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages