Class: LonLat

ol.supermap.LonLat

This class represents a longitude and latitude pair.

new ol.supermap.LonLat(lon, lat, location)

LonLat.js, line 3
Name Type Default Description
lon number 0.0 optional

The x-axis coordinate in map units. If your map is in a geographic projection, this will be the Longitude. Otherwise, it will be the x coordinate of the map location in your map units.

lat number 0.0 optional

The y-axis coordinate in map units. If your map is in a geographic projection, this will be the Latitude. Otherwise, it will be the y coordinate of the map location in your map units.

location Array.<float> optional

If you want to set it at the same time, use an array combined by the lon and lat.

Example
var lonLat = new ol.supermap.LonLat(30,45);

Members

latfloat

The y-axis coordinate in map units. The default value is 0.0

Default Value:
0.0

lonfloat

The x-axis coordinate in map units.

Default Value:
0.0

Methods

static fromArray(arr){ol.supermap.LonLat}

LonLat.js, line 167

Get a ol.supermap.LonLat object by a array.

Name Type Description
arr Array.<float>

The format of the array.It's length must be 2:[Lon,Lat]. For example: [5,-42]

Returns:
Type Description
ol.supermap.LonLat Return to a ol.supermap.LonLat object.

static fromString(str){ol.supermap.LonLat}

LonLat.js, line 153

Get a ol.supermap.LonLat object by a string.

Name Type Description
str string

The format of the string:Lon+","+Lat. For instance:"100,50"

Returns:
Type Description
ol.supermap.LonLat Return to a ol.supermap.LonLat object.
Example
var str = "100,50";
var lonLat = ol.supermap.LonLat.fromString(str);

add(lon, lat){ol.supermap.LonLat}

LonLat.js, line 71

Returns a new LonLat object with the lon and lat passed-in added to this’s.

Name Type Description
lon float

The x-axis coordinate in map units.

lat float

The y-axis coordinate in map units.

Returns:
Type Description
ol.supermap.LonLat Return a new LonLat object with the lon and lat passed-in added to this’s.
Example
var lonLat1 = new ol.supermap.LonLat(100,50);
var lonLat2 = lonLat1.add(100,50);

clone(){ol.supermap.LonLat}

LonLat.js, line 59

Copy the LonLat object, and returns new LonLat object with the same lon and lat values.

Returns:
Type Description
ol.supermap.LonLat Return new LonLat object with the same lon and lat values.
Example
var lonLat1 = new ol.supermap.LonLat(100,50);
var lonLat2 = lonLat1.clone();

destroy()

LonLat.js, line 140

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

Example
var lonLat = new ol.supermap.LonLat(100,50);
lonLat.destroy();

equals(ll){boolean}

LonLat.js, line 89

Determines whether the two LonLat objects are identical or not.

Name Type Description
ll ol.supermap.LonLat

The coordinate object needs to compare.

Returns:
Type Description
boolean Boolean value indicating whether the passed-in LonLat object has the same lon and lat components as this. Note: if ll passed in is null, returns false.
Example
var lonLat1 = new ol.supermap.LonLat(100,50);
var lonLat2 = new ol.supermap.LonLat(100,50);
var isEquals = lonLat1.equals(lonLat2);

toShortString(){string}

LonLat.js, line 47

Transform the LonLat object into a shortened string.

Returns:
Type Description
string Shortened String representation of LonLat object. For example: "100,50".
Example
var lonLat = new ol.supermap.LonLat(100,50);
var str = lonLat.toShortString();

toString(){string}

LonLat.js, line 35

Return the string format of this object.

Returns:
Type Description
string For example: "lon=100,lat=50"
Example
var lonLat = new ol.supermap.LonLat(100,50);
var str = lonLat.toString();

wrapDateLine(maxExtent){ol.supermap.LonLat}

LonLat.js, line 108

Convert coordinates to within the specified range object and return new coordinates. If the longitude is less than the minimum precision of the given range, the range width is added to the original longitude until the precision is within the range, and if the longitude is greater than the given range, the range width is subtracted from the original longitude. It means converting coordinates that are not in the longitude range to within the range (only convert lon, not convert lat, mainly for shifting to the date line).

Name Type Description
maxExtent ol.supermap.Bounds

The maximum extent for the layer.

Returns:
Type Description
ol.supermap.LonLat Return new coordinates.
Example
var lonLat1 = new ol.supermap.LonLat(420,50);
var lonLat2 = lonLat1.wrapDateLine(
     new ol.supermap.Bounds(-180,-90,180,90)
 );