Documentation
Reference
2.1.53 (current version)
collection
interactivityModel
Interfaces

map.Converter

Class for converting global pixel coordinates of a point (calculated from the upper-left corner of the world) to local coordinates (calculated from the upper-left corner of the window) and back. Each map already has its own converter, available as map.converter. Don't instantiate new instances of this class unless necessary.

See Map.converter

Constructor | Methods

Constructor

map.Converter(map)

Parameters:

ParameterDefault valueDescription
map *
[no-highlight[

* Mandatory parameter/option.

]no-highlight]

Type: Map

Reference to the map.

* Mandatory parameter/option.

Methods

NameReturnsDescription
globalToPage(globalPixelPoint)

Number[]

Converts global pixel coordinates of a point to local coordinates.

pageToGlobal(pagePixelPoint)

Number[]

Converts local pixel coordinates of a point to global coordinates.

Methods details

globalToPage

{Number[]} globalToPage(globalPixelPoint)

Converts global pixel coordinates of a point to local coordinates.

Returns the converted coordinates.

Parameters:

ParameterDefault valueDescription
globalPixelPoint*
[no-highlight[

* Mandatory parameter/option.

]no-highlight]

Type: Number[]

Pixel coordinates of a point that need to be converted.

* Mandatory parameter/option.

Example:

// Converting geographical coordinates to browser window pixels
var projection = map.options.get('projection');
console.log(map.converter.globalToPage(
    projection.toGlobalPixels(
        // geographical coordinates
        [55, 37],
        map.getZoom()
    )
));

pageToGlobal

{Number[]} pageToGlobal(pagePixelPoint)

Converts local pixel coordinates of a point to global coordinates.

Returns the converted coordinates.

Parameters:

ParameterDefault valueDescription
pagePixelPoint*
[no-highlight[

* Mandatory parameter/option.

]no-highlight]

Type: Number[]

Pixel coordinates of a point that need to be converted.

* Mandatory parameter/option.

Example:

// Converting mouse cursor coordinates to geocoordinates
var projection = map.options.get('projection');
$('#map').bind('click', function (e) {
    console.log(projection.fromGlobalPixels(
        map.converter.pageToGlobal([e.pageX, e.pageY]), map.getZoom()
    ).join(', ');
});