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.LevelSelectionis deprecated in favor of FloorSelection and the Floors API. Query floors withUnitMap.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
| Argument | Required | Type | Default Value | Description |
|---|---|---|---|---|
| tags | No | Object | {} | 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
| Argument | Required | Type | Default Value | Description |
|---|---|---|---|---|
| query | No | Object | {} | 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
| Argument | Required | Type | Default Value | Description |
|---|---|---|---|---|
| match | No | Object | {} | 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
| Argument | Required | Type | Default Value | Description |
|---|---|---|---|---|
| id | Yes | String | Array | undefined | A 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
| Argument | Required | Type | Default Value | Description |
|---|---|---|---|---|
| selector | Yes | String | undefined | The 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
| Argument | Required | Type | Default Value | Description |
|---|---|---|---|---|
| index | Yes | Integer | undefined | The 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
| Argument | Required | Type | Default Value | Description |
|---|---|---|---|---|
| x | Yes | Number | undefined | The value on the vertical axis. |
| y | Yes | Number | undefined | The 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
| Argument | Required | Type | Default Value | Description |
|---|---|---|---|---|
| scale | Yes | Float | undefined | A 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
| Argument | Required | Type | Default Value | Description |
|---|---|---|---|---|
| iterator | Yes | Function | undefined | A 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
| Argument | Required | Type | Default Value | Description |
|---|---|---|---|---|
| id | Yes | String | undefined | The id for the cloned Level. |
| tags | No | Object | {} | 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
| Argument | Required | Type | Default Value | Description |
|---|---|---|---|---|
| opacity | Yes | Decimal | undefined | A 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.
Updated 3 days ago
