LevelSelection

A collection of zero or more Level instances. A LevelSelection is returned by UnitMap.levels() and provides a chainable API for querying and manipulating levels.

🚧

Deprecated. LevelSelection is deprecated in favor of FloorSelection and the Floors API. Query floors with UnitMap.floors() instead.

map.on("ready", function () {
  // Get a level selection instance from the map:
  var levels = map.levels();

  // Show the levels tagged as floors:
  levels.where({ floor: true }).show();
});

LevelSelection.where([tags])

Get the Level instances in the collection which match the given tags.

Arguments

ArgumentRequiredTypeDefault ValueDescription
tagsNoObject{}An object of key-value pairs to filter by, where each key is the name of a tag and each value is the value of the tag. Defaults to an empty object, which returns all Levels.

Returns

A new LevelSelection instance.

LevelSelection.has([query])

Get a subset of the LevelSelection where the tags of each Level match the key-value query.

map.levels().has({
  floor: true
});

Arguments

ArgumentRequiredTypeDefault ValueDescription
queryNoObject{}An object where each key is the name of a tag and each value is a boolean of whether or not the tag exists. Defaults to an empty object, which results in a no-op.

Returns

A new LevelSelection instance.

LevelSelection.except([match])

Get a subset of the LevelSelection where the tags of each Level are not included in the given matches.

floors.except(floors.last().tags().only("floor")).hide();

Arguments

ArgumentRequiredTypeDefault ValueDescription
matchNoObject{}An object where each key is the name of a tag and each value is a value of the tag to match on. Defaults to an empty object, which results in a no-op.

Returns

A new LevelSelection instance.

LevelSelection.find(id)

Get all Level instances in the collection which match the given id or ids.

Arguments

ArgumentRequiredTypeDefault ValueDescription
idYesString | ArrayundefinedA single id or an array of ids to look for.

Returns

A new LevelSelection instance.

LevelSelection.select(selector)

Get a collection of the given entity within the LevelSelection.

Arguments

ArgumentRequiredTypeDefault ValueDescription
selectorYesStringundefinedThe entities to retrieve. Valid values are hitareas and units.

Returns

A HitAreaSelection or UnitSelection instance.

LevelSelection.first()

Get the first Level in the collection.

Returns

A new LevelSelection instance.

LevelSelection.last()

Get the last Level in the collection.

Returns

A new LevelSelection instance.

LevelSelection.at(index)

Get the Level at the given index.

Arguments

ArgumentRequiredTypeDefault ValueDescription
indexYesIntegerundefinedThe index of the desired Level.

Returns

A new LevelSelection instance.

LevelSelection.translate(x, y)

Move each Level in the collection by the given x and y. This method is chainable.

Arguments

ArgumentRequiredTypeDefault ValueDescription
xYesNumberundefinedThe value on the vertical axis.
yYesNumberundefinedThe value on the horizontal axis.

Returns

The object chain.

LevelSelection.scale(scale)

Set the scale of each Level in the collection. This method is chainable.

Arguments

ArgumentRequiredTypeDefault ValueDescription
scaleYesFloatundefinedA positive float value. 1 means a 1:1 ratio with the original scale of the level, 0.5 means half of the original scale, and 2 means double the original scale.

Returns

The object chain.

LevelSelection.each(iterator)

Iterate over each Level in the collection. This method is chainable.

Arguments

ArgumentRequiredTypeDefault ValueDescription
iteratorYesFunctionundefinedA function invoked with each Level in the collection.

Returns

The object chain.

LevelSelection.clone(id, [tags])

Get a new instance of the collection with identical attributes.

Arguments

ArgumentRequiredTypeDefault ValueDescription
idYesStringundefinedThe id for the cloned Level.
tagsNoObject{}An object of tags to apply to the cloned Level.

Returns

A new LevelSelection instance.

LevelSelection.remove()

Remove all Level instances in the collection from the map. This method is chainable.

Returns

The object chain.

LevelSelection.hide()

Hide the Level instances in the collection. This method is chainable.

Returns

The object chain.

LevelSelection.show()

Display the Level instances in the collection. This method is chainable.

Returns

The object chain.

LevelSelection.opacity(opacity)

Set the opacity of the Level instances in the collection. This method is chainable.

Arguments

ArgumentRequiredTypeDefault ValueDescription
opacityYesDecimalundefinedA number between 0 and 1. The transparency level, where 1 is not transparent at all, 0.5 is 50% see-through, and 0 is completely transparent.

Returns

The object chain.

LevelSelection.tags()

Get the tags of the Level instances in the collection.

Returns

A new TagsCollection instance.

LevelSelection.data()

Get the LevelSelection data as JSON.

Returns

A JSON object.


What’s Next