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
map.Converter(map)
Parameters:
Parameter |
Default value |
Description |
|
— |
Type: Map Reference to the map. |
* Mandatory parameter/option.
Methods
Name |
Returns |
Description |
Number[] |
Converts global pixel coordinates of a point to local coordinates. |
|
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:
Parameter |
Default value |
Description |
— |
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:
Parameter |
Default value |
Description |
— |
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(', '));
});
Mandatory parameter/option.