Class: Pixel

ol.supermap.Pixel

This class represents a screen coordinate, in x and y coordinates (pixel).

new ol.supermap.Pixel(x, y, mode)

Pixel.js, line 3
Name Type Default Description
x number 0.0 optional

The x coordinate.

y number 0.0 optional

The y coordinate.

mode ol.supermap.Pixel.Mode ol.supermap.Pixel.Mode.LeftTop optional

Coordinate mode.

Example
//Create a single object
var pixcel = new ol.supermap.Pixel(100,50);

//Created by size
 var size = new ol.supermap.Size(21,25);
 var offset = new ol.supermap.Pixel(-(size.w/2), -size.h);

Members

(static, readonly) Modestring

mode.

Coordinate mode: top-left, top-right, button-left, button-right.

Default Value:
ol.supermap.Pixel.Mode.LeftTop

xnumber

he x coordinate.

Default Value:
0.0

ynumber

The y coordinate.

Default Value:
0.0

Methods

add(x, y){ol.supermap.Pixel}

Pixel.js, line 124

Based on the original pixel coordinates, the x value is added to the passed x parameter, and the y value is added to the passed y parameter.

Name Type Description
x number

x value.

y number

y value.

Returns:
Type Description
ol.supermap.Pixel Returns a new pixel object that is added by the current pixel and the passed x,y.
Example
var pixcel = new ol.supermap.Pixel(100,50);
//pixcel2 is a new object
var pixcel2 = pixcel.add(20,30);

clone(){ol.supermap.Pixel}

Pixel.js, line 74

Return a clone of this pixel object.

Returns:
Type Description
ol.supermap.Pixel Return a new pixel object with the same x, y coordinates.
Example
var pixcel = new ol.supermap.Pixel(100,50);
var pixcel2 = pixcel.clone();

destroy()

Pixel.js, line 163

Destroy the object. All properties of the object will be null after it is destroyed.

Example
var pixcel = new ol.supermap.Pixel(100,50);
pixcel.destroy();

distanceTo(px){float}

Pixel.js, line 106

Returns the distance of the two pixel points.

Name Type Description
px ol.supermap.Pixel

A pixel that is used to calculate.

Returns:
Type Description
float The distance between the incoming pixel and the current pixel.
Example
var pixcel = new ol.supermap.Pixel(100,50);
var pixcel2 = new ol.supermap.Pixel(110,30);
var distance = pixcel.distanceTo(pixcel2);

equals(px){boolean}

Pixel.js, line 86

Determine whether one pixel is equivalent to another.

Name Type Description
px ol.supermap.Pixel

The pixel object to be compared.

Returns:
Type Description
boolean The point passed in as parameter is equal to this. Note that if px passed in is null, returns false.
Example
var pixcel = new ol.supermap.Pixel(100,50);
var pixcel2 = new ol.supermap.Pixel(100,50);
var isEquals = pixcel.equals(pixcel2);

offset(px){ol.supermap.Pixel}

Pixel.js, line 143

Make offset to the coordinate according to the ol.supermap.Pixel passed in.

Name Type Description
px ol.supermap.Pixel

The passed in ol.supermap.Pixel object.

Returns:
Type Description
ol.supermap.Pixel Returns a new pixel that is obtained by adding the x,y value of the current pixel object to the x,y value of the incoming Pixel object.
Example
var pixcel = new ol.supermap.Pixel(100,50);
var pixcel2 = new ol.supermap.Pixel(130,20);
//pixcel3 is a new object
var pixcel3 = pixcel.offset(pixcel2);

toString(){string}

Pixel.js, line 60

Return the string format of this object.

Returns:
Type Description
string For example: "x=200.4,y=242.2".
Example
var pixcel = new ol.supermap.Pixel(100,50);
var str = pixcel.toString();