Skip to content

Labels and hovers ​

Labels ​

style.label draws the value of label.field next to each feature, while label.display is true. The ui offers a toggle titled label.title. On a cluster layer, count shows the number of locations on cluster features instead. Without the field the feature's label property is drawn; the text is always taken from the feature, never from the configuration.[1] minZoom and maxZoom limit the zoom range.

The text is styled with font (12px sans-serif), fillColor (#000), a halo of strokeColor and strokeWidth, offsetX/offsetY in pixels, and overflow to draw labels which exceed their polygon.[2]

Hovers ​

style.hover shows an infotip for the feature under the pointer while hover.display is true.[3]

  • If the feature already has the hover.field property, it is shown directly.
  • Otherwise the MAPP library queries the hover.query template, infotip by default, with field, the feature id, the layer table and the layer queryparams, and shows the returned label. Responses are cached unless hover.dynamic is set.

label.hidden and hover.hidden remove their toggles and dropdowns from the style panel, and hide an entry of labels or hovers from the dropdown.[4]

Several labels or hovers ​

style.labels and style.hovers are maps of named configurations; the key is the default title. style.label or style.hover may name one of them, or the first is used.[5] A theme's setLabel and setHover switch them with the theme; see themes.

Label, hover, theme and icon scaling fields are added to the layer query's fields automatically; see layer data source.

Pitfalls ​

  • A label or hover without display: true is configured but not shown.
  • A hover field must be a column of the current table, or a template the infotip query can use.

Examples ​

Retail point labels from zoom 12 and an infotip with the store name.

json
{
  "dbs": "DEVDB",
  "locale": {
    "layers": {
      "retail_points": {
        "display": true,
        "format": "wkt",
        "table": "geodata.uk_glx_open_retail_points",
        "geom": "geom_p_4326",
        "srid": "4326",
        "qID": "id",
        "style": {
          "default": { "icon": { "type": "dot", "fillColor": "#e66" } },
          "label": {
            "title": "Store names",
            "field": "store_name",
            "display": true,
            "minZoom": 12,
            "strokeColor": "#fff",
            "strokeWidth": 3
          },
          "hover": { "field": "store_name", "display": true }
        }
      }
    }
  }
}

  1. featureStyle.mjs labelStyle ↩︎

  2. utils/olStyle.mjs ↩︎

  3. featureHover.mjs ↩︎

  4. ui/elements/layerStyle.mjs label() and hover() ↩︎

  5. styleParser.mjs handleHovers ↩︎

XYZ v5.1.0. Generated from knowledge/ at dd7a6fa27736502733499c1bf485f15659b10338. Concepts marked draft are not reviewed.