Unit

A Unit is represented as a single shape object.

Unit.color(color)

Set the fill color for the Unit.

// Color all units:
map.units().color("#ff00ff");

// Color units with an ID of `1`, `2`, or `3`:
map.units().find([1, 2, 3]).color("#ff00ff");

// Color a unit when moused over:
map.on("unit:mouseover", function (unit) {
  unit.color("rgb(255, 0, 0)");
});

Arguments

ArgumentsRequiredTypeDefault ValueDescription
colorYesStringundefinedA valid CSS color value.

Returns

The object chain.

Unit.center()

Returns the position in map space which will center the Unit within the viewport (screen space).

// Translate the map to center over the unit with an ID of `1`.

map.panTo(map.units().find("1").center());

Returns

An [x, y] coordinates Array.


What’s Next