Skip to content

Feature styles ​

A feature style is an object of the style keys below. layer.style holds the feature styles a layer uses:

  • default applies to every feature. Without it the MAPP library warns and uses a white fill with a dark stroke, or a dot icon on a cluster layer.[1]
  • highlight applies to the feature under the pointer. It is drawn on top (zIndex Infinity); its scale becomes highlightScale.
  • selected replaces the whole style, including theme and label, of features whose location is open.
  • cluster applies to features which stand for several locations. It defaults to a dot icon with clusterScale 1, which grows the icon with the cluster size, or with its natural log with logScale.[2]
  • opacity sets the opacity of the whole layer, 0 to 1; 0 is treated as 1.
  • cache reuses the style computed for a feature; highlight, theme and label changes are then not drawn until the features are reloaded.

Themes, labels and hovers add to these; see themes and labels and hovers.

Feature style keys ​

fillColor, fillOpacity, strokeColor, strokeWidth (1) and strokeOpacity style lines and polygons; lineDash dashes the stroke. Opacities, 0 to 1, are only applied to 4 or 7 character hex colours. zIndex orders the styles within the layer. A point needs an icon; see point icons.[3]

Style panel ​

The ui shows a style drawer in the layer view unless hidden.[4]elements orders its controls, by default labels, label, hovers, hover, themes, theme, icon_scaling and opacitySlider. An element is only shown when layer.style has its key, so opacitySlider: true adds the opacity slider.[5] drawer is disableOnHide (disabled while the layer is hidden), or false for a panel without drawer; popout, dialog and classList change how it is shown.

Pitfalls ​

  • A cluster layer keeps only icon and scale in style.default; other keys are removed with a warning.
  • layer.style.zIndex, layer.hover and layer.icon_scaling are legacy; use layer.zIndex, layer.style.hover and layer.style.icon_scaling. layer.style.zIndex only warns and has no effect.
  • A style object inside style.default is unwrapped with a warning.
  • layer.style.zoomInScale and zoomOutScale are meant to scale icons with the zoom level. The parser moves a cluster style's keys there, but the feature style function reads them from style.cluster, so they currently do not change the render (#3154).

Examples ​

Grey dashed countries with a yellow highlight and an opacity slider.

json
{
  "dbs": "DEVDB",
  "locale": {
    "layers": {
      "countries": {
        "display": true,
        "format": "geojson",
        "table": "naturalearth.countries",
        "geom": "geom_4326",
        "srid": "4326",
        "qID": "id",
        "style": {
          "default": { "fillColor": "#d9d9d9", "fillOpacity": 0.5, "strokeColor": "#555", "lineDash": [4, 2] },
          "highlight": { "fillColor": "#dbd56e", "fillOpacity": 0.7 },
          "opacitySlider": true
        }
      }
    }
  }
}

  1. styleParser.mjs warnings and clusterChecks ↩︎

  2. featureStyle.mjs clusterStyle ↩︎

  3. utils/olStyle.mjs ↩︎

  4. ui/layers/panels/style.mjs ↩︎

  5. ui/elements/layerStyle.mjs panel() ↩︎

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