util.hd

Static object.

Allows working with HD screens on various devices.

Methods

Methods

Name

Returns

Description

getPixelRatio()

Number

Returns ratio of virtual and physical pixels on the screen.

selectRatio(hash)

Number

Returns result of selection — either the pixel ratio, or 1 if, for example, a string was passed.

selectValue(hash)

Object

Returns an object from the passed hash that is equal to or closest to the pixel ratio key. If something other than a hash was passed, such as a string or function, then it is returned.

Methods details

getPixelRatio

{Number} getPixelRatio()

Returns ratio of virtual and physical pixels on the screen.

selectRatio

{Number} selectRatio(hash)

Returns result of selection — either the pixel ratio, or 1 if, for example, a string was passed.

Parameters:

Parameter

Default value

Description

hash*

Type: IRatioMap

Object of type IRatioMap for screens with different pixel ratios.

* Mandatory parameter/option.

selectValue

{Object} selectValue(hash)

Returns an object from the passed hash that is equal to or closest to the pixel ratio key. If something other than a hash was passed, such as a string or function, then it is returned.

Parameters:

Parameter

Default value

Description

hash*

Type: Object|IRatioMap

Object of type IRatioMap for screens with different pixel ratios.

* Mandatory parameter/option.

Example:

// We need to add a picture to the balloon so it looks good on HD screens.
var balloonImages = {
   // Normal picture.
    "1": "100x100.png",
   // Picture for Retina.
    "2": "200x200.png"
};
var img = ymaps.util.hd.selectValue(balloonImages);
// Adding the point to the map.
myMap.geoObjects.add(new ymaps.GeoObject({
    geometry: "Point",
    coordinates: [55, 37],
    properties: {
        balloonContent:
            '<img src="' + img + '" width="100" alt="" >'
    }
});