Skip to content

Shapes

Overview

The utils.shapes.js module provides tools for generating HTML/SVG map marker shapes with optional icon, text, and HTML overlays. It is used throughout KDK to render styled point symbols for maps and legends.

Shapes

A catalog of predefined SVG shape definitions. Each entry contains a viewBox array, an SVG content string, and optional radiusToSize, icon/text translation defaults, and anchor properties.

NameDescription
circleA filled circle.
rectA square rectangle.
rounded-rectA rectangle with rounded corners.
diamondA rotated square.
triangleAn upward-pointing triangle.
triangle-downA downward-pointing triangle.
triangle-leftA left-pointing triangle.
triangle-rightA right-pointing triangle.
starA five-pointed star.
marker-pinA map pin (teardrop) shape. Anchor: bottom-center.
square-pinA rounded speech-bubble pin. Anchor: bottom-center.

Functions

createShape(options)

Generates an HTML string representing a styled SVG shape with optional overlays, suitable for use as a Leaflet DivIcon or any inline HTML context.

  • Parameters:
OptionTypeDefaultDescription
shapestring | ObjectPredefined shape name (from Shapes) or a custom shape object with viewBox, content, and optional translation, rotation.
sizeArray[width, height] in pixels. Overrides radius.
radiusnumberUsed to compute size via the shape's radiusToSize function (default: radius * 2). Ignored if size is set.
colorstringnoneFill color. Accepts Quasar palette names, HTML color names, or CSS color values.
opacitynumberFill opacity (0–1).
strokeObjectStroke style: { color, width, opacity, cap, join, dashArray, dashOffset }.
iconObjectIcon overlay: { classes, url, symbol, color, opacity, size, translation, rotation }. Provide classes for font icons, url for image icons, or symbol for SVG <use> references.
textObjectText overlay: { label, classes, color, size, translation, rotation }.
htmlstringArbitrary HTML overlay centered within the shape.
extraStylestring''Additional CSS style string applied to the container div.
idstringOptional id attribute for the container div.
  • Returns: Object with:
    • html (string): The complete HTML string.
    • size (Object): { width, height } in pixels.
    • anchor (string): The anchor point descriptor (e.g. 'middle-center', 'bottom-center').

Usage

javascript
import { createShape } from '@kalisio/kdk/core.client'

const { html, size, anchor } = createShape({
  shape: 'marker-pin',
  radius: 16,
  color: 'red',
  icon: { classes: 'las la-fire', color: 'white', size: 12 }
})