Skip to main content

ShapeLayer

wemap-sdk-js


Class: ShapeLayer

Draws GeoJSON line and polygon geometries with per-feature simplestyle-spec styling. Each instance owns its own source and two data-driven layers (a fill for polygons and a line for line-strings and polygon outlines), so multiple ShapeLayer instances can coexist on one map (e.g. different hover styles).

Geometry is GeoJSON ([lng, lat]), not the SDK's lat-first Coordinates.

Interactive by default: hovering a shape highlights it (and shows a pointer cursor), and `on('click')` reports clicks. Pass { interactive: false } for decorative shapes.

WemapMap.remove() does not destroy this layer — call destroy explicitly (or remove({ layers: true })).

Constructors​

Constructor​

new ShapeLayer(wemapMap, options?): ShapeLayer

Parameters​

wemapMap​

WemapMap

options?​

ShapeLayerOptions = {}

Returns​

ShapeLayer

Methods​

clear()​

clear(): void

Remove every shape and the underlying source/layers.

Returns​

void


destroy()​

destroy(): void

Remove all shapes and detach listeners. Idempotent.

Returns​

void


drawLineString()​

drawLineString(geometry, properties?): string

Draw a line styled with simplestyle-spec properties (stroke, stroke-opacity, stroke-width).

Parameters​

geometry​

LineStringInput

properties?​

SimpleStyleProperties = {}

Returns​

string

The shape id, for remove.


drawPolygon()​

drawPolygon(geometry, properties?): string

Draw a polygon styled with simplestyle-spec properties (fill, fill-opacity, stroke, stroke-opacity, stroke-width).

Parameters​

geometry​

PolygonInput

properties?​

SimpleStyleProperties = {}

Returns​

string

The shape id, for remove.


on()​

on(event, listener): () => void

Subscribe to clicks on any shape. No-op when the layer was created with { interactive: false }.

Parameters​

event​

"click"

listener​

ShapeClickListener

Returns​

An unsubscribe function.

() => void


remove()​

remove(id): void

Remove a shape by the id returned from a draw* call. Unknown id is a no-op.

Parameters​

id​

string

Returns​

void