Docs / Developers / Layer styles from a map

Layer styles from a map

Draw OrbGIS layers in your own map library with the colours, classes, icons and labels the map’s author chose.

Ask for the style#

GET /v1/maps/{id} lists a map’s layers. Add include=style and every feature layer also carries a style object: the filter, renderer, colours, classes, sizes, icons and labels the map’s author set in OrbGIS.

curl --fail-with-body \
  -H "Authorization: Bearer $ORBGIS_API_KEY" \
  "https://api.orbgis.se/v1/maps/MAP_ID?include=style"

Without include=style the response is unchanged. A layer that is not a feature layer has "style": null. A published map answers without a key.

What a layer looks like#

{
  "id": "feature-7a0d9f3e-3c1b-4f2e-9d8a-5c6e7f8a9b0c",
  "type": "feature",
  "collectionId": "7a0d9f3e-3c1b-4f2e-9d8a-5c6e7f8a9b0c",
  "title": "Trees",
  "visible": true,
  "opacity": 1,
  "minZoom": null,
  "maxZoom": null,
  "style": {
    "filter": null,
    "renderer": "categories",
    "field": "species",
    "symbol": {
      "color": "#6366f1",
      "fill": { "opacity": 0.6, "pattern": null },
      "stroke": {
        "color": "#6366f1", "width": 1.5, "widthUnits": "px", "opacity": 1,
        "visible": true, "dash": "solid", "dashArray": null,
        "position": "center", "casing": null, "offset": 0
      },
      "point": {
        "shape": "circle", "radius": 6, "radiusUnits": "px", "zoomScaled": true,
        "opacity": 1, "outline": { "color": "#ffffff", "width": 1.5 },
        "icon": null, "rotationField": null
      }
    },
    "categories": [
      { "value": "Oak", "color": "#16a34a", "strokeColor": "#16a34a", "icon": null },
      { "value": "Elm", "color": "#f59e0b", "strokeColor": "#f59e0b", "icon": null }
    ],
    "classes": null,
    "rules": null,
    "sizeBy": null,
    "label": {
      "field": "name", "template": null, "fontSize": 11,
      "fontFamily": "Inter, system-ui, sans-serif", "bold": false,
      "color": "#dae2fd", "haloColor": "#0b1326", "haloWidth": 1.5,
      "placement": "point", "anchor": "auto", "offset": [0, 0],
      "declutter": true, "minZoom": 0, "maxZoom": 24
    },
    "blendMode": "normal"
  }
}

Every field is always present, and every default is already filled in: a layer nobody has styled still returns the blue OrbGIS draws it in. You never need to know a default yourself.

Apply the filter first#

filter says which features the layer draws at all. It is null when the layer draws everything. Otherwise filter.tree is the filter as a tree of plain JSON nodes: keep the features that pass it.

"filter": {
  "tree": {
    "op": "and",
    "args": [
      { "op": "=", "field": "status", "value": "active" },
      { "op": "or", "args": [
        { "op": ">=", "field": "height_m", "value": 10 },
        { "op": "in", "field": "species", "values": ["Tilia", "Acer"] }
      ] },
      { "op": ">=", "field": "planted", "value": { "relative": "date", "offsetDays": -30 } }
    ]
  },
  "expression": "\"status\" = 'active' AND (\"height_m\" >= 10 OR \"species\" IN ('Tilia', 'Acer')) AND \"planted\" >= CURRENT_DATE - 30"
}
Heads up

Apply the filter before you style. If you skip it, your map shows features that the OrbGIS map hides.

opOther fieldsA feature passes when
and, orargs: a list of nodesEvery node passes, or at least one does.
notarg: one nodeThat node does not pass.
=, !=, >, >=, <, <=field, and value or otherFieldThe property compares that way with value, or with the feature’s own otherField property.
infield, valuesThe property equals one of values.
betweenfield, min, maxmin ≤ the property ≤ max. Both ends count.
isEmptyfieldThe property has no value, or is an empty text.
contains, startsWith, endsWithfield, valueThe property’s text contains, starts with or ends with value. Upper and lower case are treated alike, and value is already lower case.

To get the same answer as OrbGIS, compare values the way the tree’s rules below say. They follow how the database compares.

  • A property that is missing and one that is null are both “no value”. No value equals only no value, and never passes >, >=, < or <=.
  • A number equals a text that spells the same number: 5 equals "5" and "5.00". A text with a leading zero, such as "0114", is a code and stays text.
  • A boolean equals the texts true, t, yes, y, on, 1, or false, f, no, n, off, 0.
  • Two texts that both spell numbers compare as numbers. Other texts compare as text, which also orders ISO dates correctly.
  • A value of the form {"relative": "date", "offsetDays": -30} is a moving date: today plus that many days, written YYYY-MM-DD. With "timestamp" it is the current time, written YYYY-MM-DDTHH:mm:ss. Work it out in local time each time you apply the filter, then compare it as text.

filter.expression is the same filter as its author typed it, when it was typed as text. It is there for display. If tree is null while expression has text, OrbGIS could not read the text and its own map draws every feature, so do the same.

Zoom levels#

Every zoom number in the response is on the OrbGIS viewer’s scale, which counts with 256 pixel tiles: the layer’s minZoom and maxZoom, label.minZoom and label.maxZoom, and the zoom 10 that zoomScaled point sizes refer to. OpenLayers and Leaflet count the same way. MapLibre GL JS and Mapbox GL JS count with 512 pixel tiles, so on a Web Mercator map (crs is EPSG:3857) subtract 1: OrbGIS zoom 10 is MapLibre zoom 9.

On a map in another coordinate system (crs is EPSG:3006, 3035, 3067, 25832 or 25833), one pixel at zoom z covers 156 543 / 2^z metres on the ground, the same everywhere on the map. Web Mercator stretches with latitude, so the matching MapLibre zoom there is z − 1 + log2(cos latitude). That is about z − 1.8 in Malmö, z − 2 in Stockholm and Helsinki, and z − 2.4 in Kiruna.

The renderer decides the colour#

rendererHow to pick a feature’s colour
singleEvery feature uses symbol.
categoriesFind the entry in categories whose value equals the feature’s field value, compared as text. A value that is not listed uses symbol.color.
graduatedFind the entry in classes where min ≤ value < max. null means no bound. A value below the first class uses the first, a value above the last uses the last.
rulesEach entry in rules has a filterTree, a filter tree like the layer’s. When several match, the last one wins. The entry with "else": true draws what no other rule matches; without one, those features are not drawn.

Each entry has a color and a strokeColor. Fill polygons and points with color. Draw polygon outlines and lines with strokeColor. Everything else, such as widths, opacity and point shape, comes from symbol.

"renderer": "graduated",
"field": "population",
"classes": [
  { "min": 0,    "max": 1000, "color": "#bfdbfe", "strokeColor": "#bfdbfe", "size": null },
  { "min": 1000, "max": 5000, "color": "#3b82f6", "strokeColor": "#3b82f6", "size": null },
  { "min": 5000, "max": null, "color": "#1e3a8a", "strokeColor": "#1e3a8a", "size": null }
]

The symbol#

FieldMeaning
symbol.fill.opacityPolygon fill opacity, 0–1.
symbol.fill.patternA hatch or dot pattern over the fill (id, color, spacing in pixels), or null for a solid fill.
symbol.stroke.width, widthUnitsLine and outline width, in screen pixels (px) or metres on the ground (m).
symbol.stroke.visiblefalse when the author switched polygon outlines off.
symbol.stroke.dash, dashArraysolid, dashed or dotted. dashArray is dash then gap in multiples of the line width.
symbol.stroke.positionPolygon outlines: outline (outside the edge), center or inline (inside it).
symbol.stroke.casing, offsetA wider stroke under a line (width pixels on each side), and a sideways shift of the line in pixels.
symbol.point.shape, radius, radiusUnitsThe marker and its radius, in pixels or metres on the ground.
symbol.point.zoomScaledtrue: radius is the size at zoom 10, and OrbGIS draws radius × 1.18^(zoom − 10), with that factor kept between 0.4 and 6. false: draw radius as it is.
symbol.point.outlineA rim around plain markers (color, width), or null.
symbol.point.rotationFieldA field that rotates each icon, in degrees clockwise from north.
sizeByA second field that sets the point radius or line width. When it is set, use it instead of symbol.point.radius, symbol.stroke.width and class sizes.
blendModenormal, multiply, screen, overlay, darken or lighten.
Note

Opacity values are final. symbol.fill.opacity, symbol.stroke.opacity and symbol.point.opacity already include the layer’s own opacity, so do not multiply them again.

Icons#

A point is a plain marker when icon is null. Otherwise icon.kind says what to draw. Categories and rules carry their own icon; symbol.point.icon is the one for the layer as a whole.

"icon": {
  "kind": "image",
  "name": null,
  "url": "https://app.orbgis.se/storage/v1/object/sign/story-media/ORG_ID/map-icons/pin.png?token=…",
  "urlExpiresAt": "2026-11-26T13:00:00.000Z",
  "size": 32,
  "sizePerRadius": null,
  "sizeAxis": "height",
  "anchor": [0.5, 1],
  "offset": [0, 0],
  "offsetPerSize": null
}
  • image: a picture the author uploaded. Load it from url and draw it size pixels along sizeAxis, the same at every zoom. anchor is the spot of the picture that sits on the point, as fractions from its top-left corner, and offset shifts it in pixels, right then up. When size is null the layer sizes its points per feature: draw the picture at the feature’s point radius times sizePerRadius, and shift it by offsetPerSize times that size instead of offset.
  • builtin: one of the icons that come with OrbGIS. url is a public 24 × 24 SVG of it, already in the colour of its category or rule, which you can load without a key. Draw it at the point’s diameter, twice the radius. For another colour, such as each class of a graduated layer, change the color parameter to six hex digits without #.
  • When you call with an API key or user token, url for a picture stored in your organization is a signed link. Anyone can open it until urlExpiresAt, 24 hours later, so it works for unpublished maps too. Every picture in the map is signed, however many there are. Read the map again for fresh links. Without a credential, url is a plain link that works while the map is published, and urlExpiresAt is null.
"icon": {
  "kind": "builtin",
  "name": "tree",
  "url": "https://api.orbgis.se/v1/icons/tree.svg?color=16a34a",
  "urlExpiresAt": null,
  "size": null, "sizePerRadius": null, "sizeAxis": null,
  "anchor": null, "offset": null, "offsetPerSize": null
}

Labels#

label is null when the layer has no labels. Otherwise the text is the value of label.field, or label.template with its {field} tokens filled in when a template is set. anchor is auto (above a point, centred on anything else) or a fixed side, and placement: "line" means the text follows line features. minZoom and maxZoom are the zoom levels between which labels show.

Good to know#

  • The style describes what the OrbGIS viewer draws. Field names in field, sizeBy.field and label.field are the property names of the layer’s features and of its vector tiles.
  • Popups, clustering and 3D heights are not part of the style.
  • New fields can be added to style over time. Ignore fields you do not know.