map.margin.Manager

Extends IEventEmitter.

Map margins manager.

A manager for calculating the optimal margins from the edge of the map container.

As input, the manager accepts a definition of rectangular areas in screen coordinates, which designate the occupied areas of the map container.

Margins can be used when setting the current map viewport, in order to get the best display of data on the map. The data on the map never ends up under the occupied areas of the map container. Map#setBound.

Don't instantiate new instances of this class unless necessary.

Constructor | Fields | Events | Methods

Constructor

map.margin.Manager()

Parameters:

Parameter

Default value

Description

map*

Type: Map

* Mandatory parameter/option.

Fields

Name

Type

Description

events

IEventManager

Event manager.

Inherited from IEventEmitter.

Events

Name

Description

change

Changes to map margins.

Methods

Name

Returns

Description

addArea(screenArea)

map.margin.Accessor

Adding a new rectangular area.

destroy()

map.margin.Manager

Destroying the margins manager.

getMargin()

Number[]

Returns the current margins from the map edges. Values in the array are ordered as: upper margin, right margin, lower margin, left margin.

getOffset()

Number[]

Returns the difference (in pixels) between the geometric center of the map (without margins) and the logical center (with consideration for the margins).

setDefaultMargin(margin)

Sets the default margins from the map edges.

Events details

change

Changes to map margins.

Methods details

addArea

{map.margin.Accessor} addArea(screenArea)

Adding a new rectangular area.

Returns the object that provides access to the added area. To delete the added rectangular area, you must use this object.

Parameters:

Parameter

Default value

Description

screenArea*

Type: Object

The rectangular area, which is set in local coordinates. This area is defined as an object containing information about the margins from the map edges (left, top, right, bottom) and the dimensions of the area (width, height). The values can be set as percentages of the width/height of the map container.

* Mandatory parameter/option.

Examples:

1.

// Offset from the upper-left corner.
map.margin.addArea({
    left: 0,
    top: 0,
    width: 78,
    height: 101
});
console.log(map.margin.getMargin()); // [0, 0, 0, 78]

2.

// Offset from the lower-right corner.
map.margin.addArea({
    right: 50,
    bottom: 50,
    width: 26,
    height: 25
});
console.log(map.margin.getMargin()); // [0, 0, 75, 0]

3.

// Setting the margins as a percentage.
map.margin.addArea({
    left: 50,
    bottom: '1%',
    width: 20,
    height: 20
});
console.log(map.margin.getMargin()); // [0, 0, 26, 0]

4.

// Setting the sizes as a percentage.
map.margin.addArea({
    left: 0,
    top: 50,
    width: '100%',
    height: 25
});
console.log(map.margin.getMargin()); // [75, 0, 0, 0]

5.

// Setting multiple areas.
map.margin.addArea({
    top: 10,
    left: 10,
    width: 20,
    height: 20
});
map.margin.addArea({
    top: 20,
    right: 40,
    width: 100,
    height: 100
});
map.margin.addArea({
    bottom: 20,
    left: 30,
    width: 120,
    height: 30
});
console.log(map.margin.getMargin()); // [120, 0, 50, 0]

destroy

{map.margin.Manager} destroy()

Destroying the margins manager.

Returns self-reference.

getMargin

{Number[]} getMargin()

Returns the current margins from the map edges. Values in the array are ordered as: upper margin, right margin, lower margin, left margin.

getOffset

{Number[]} getOffset()

Returns the difference (in pixels) between the geometric center of the map (without margins) and the logical center (with consideration for the margins).

setDefaultMargin

{} setDefaultMargin(margin)

Sets the default margins from the map edges.

Parameters:

Parameter

Default value

Description

margin*

Type: Number

Number[]

Margin values in the form of one, two, or four numbers (similar to setting margins in CSS).

* Mandatory parameter/option.