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"
}Apply the filter before you style. If you skip it, your map shows features that the OrbGIS map hides.
op | Other fields | A feature passes when |
|---|---|---|
and, or | args: a list of nodes | Every node passes, or at least one does. |
not | arg: one node | That node does not pass. |
=, !=, >, >=, <, <= | field, and value or otherField | The property compares that way with value, or with the feature’s own otherField property. |
in | field, values | The property equals one of values. |
between | field, min, max | min ≤ the property ≤ max. Both ends count. |
isEmpty | field | The property has no value, or is an empty text. |
contains, startsWith, endsWith | field, value | The 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
nullare both “no value”. No value equals only no value, and never passes>,>=,<or<=. - A number equals a text that spells the same number:
5equals"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, orfalse,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
valueof the form{"relative": "date", "offsetDays": -30}is a moving date: today plus that many days, writtenYYYY-MM-DD. With"timestamp"it is the current time, writtenYYYY-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#
renderer | How to pick a feature’s colour |
|---|---|
single | Every feature uses symbol. |
categories | Find the entry in categories whose value equals the feature’s field value, compared as text. A value that is not listed uses symbol.color. |
graduated | Find 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. |
rules | Each 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#
| Field | Meaning |
|---|---|
symbol.fill.opacity | Polygon fill opacity, 0–1. |
symbol.fill.pattern | A hatch or dot pattern over the fill (id, color, spacing in pixels), or null for a solid fill. |
symbol.stroke.width, widthUnits | Line and outline width, in screen pixels (px) or metres on the ground (m). |
symbol.stroke.visible | false when the author switched polygon outlines off. |
symbol.stroke.dash, dashArray | solid, dashed or dotted. dashArray is dash then gap in multiples of the line width. |
symbol.stroke.position | Polygon outlines: outline (outside the edge), center or inline (inside it). |
symbol.stroke.casing, offset | A wider stroke under a line (width pixels on each side), and a sideways shift of the line in pixels. |
symbol.point.shape, radius, radiusUnits | The marker and its radius, in pixels or metres on the ground. |
symbol.point.zoomScaled | true: 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.outline | A rim around plain markers (color, width), or null. |
symbol.point.rotationField | A field that rotates each icon, in degrees clockwise from north. |
sizeBy | A 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. |
blendMode | normal, multiply, screen, overlay, darken or lighten. |
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 fromurland draw itsizepixels alongsizeAxis, the same at every zoom.anchoris the spot of the picture that sits on the point, as fractions from its top-left corner, andoffsetshifts it in pixels, right then up. Whensizeisnullthe layer sizes its points per feature: draw the picture at the feature’s point radius timessizePerRadius, and shift it byoffsetPerSizetimes that size instead ofoffset.builtin: one of the icons that come with OrbGIS.urlis 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 thecolorparameter to six hex digits without#.- When you call with an API key or user token,
urlfor a picture stored in your organization is a signed link. Anyone can open it untilurlExpiresAt, 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,urlis a plain link that works while the map is published, andurlExpiresAtisnull.
"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.fieldandlabel.fieldare 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
styleover time. Ignore fields you do not know.