The common tool class.
Members
-
SuperMap.Util.DEFAULT_PRECISIONnumber
-
Valid digits reserved to avoid floating-point accuracy errors.
- Default Value: 14
SuperMap.Util.isSupportCanvas
Whether the browser supports Canvas.
SuperMap.Util.lastSeqIDnumber
Increasing count variables to generate unique ID.
- Default Value: 0
Methods
-
SuperMap.Util.applyDefaults(to, from){Object}
Util.js, line 234 -
Takes an object and copies any properties that don't exist from another properties, by analogy with SuperMap.Util.extend() from Prototype.js.
Name Type Description to
Object optional The destination object.
from
Object The source object. Any properties of this object that are undefined in the to object will be set on the to object.
Returns:
Type Description Object A reference to the to object. Note that the to argument is modified in place and returned by this function. -
SuperMap.Util.calculateDpi(viewBounds, viewer, scale, coordUnit, datumAxis){number}
Util.js, line 739 -
Calculating the display resolution of the REST layer on the iServer service,Five parameters, viewBounds, viewer, scale, coordUnit, datumAxis, are required to be calculated from the REST layer representation of iServer.
Name Type Default Description viewBounds
SuperMap.Bounds The reference visual range of a map, that is, the default map display range when the map is initialized.
viewer
SuperMap.Size The size of the default map tile when the map is initialized.
scale
number The default display scale when the map is initialized.
coordUnit
string 'degrees' optional The map unit of the projection coordinate system.
datumAxis
number 6378137 optional Ellipsoid long half axis of the geo coordinate system. When user custom maps are Options, if the value of the parameter is not specified, the system is defaults to the ellipsoid long half axis 6378137 of the WGS84 reference system.
Returns:
Type Description number Return the resolution of the layer display. -
SuperMap.Util.cloneObject(obj){Object}
Util.js, line 963 -
Clone an object.
Name Type Description obj
Object An object that needs to be cloned.
Returns:
Type Description Object To return to the object's copy object, note that it is a new object, not pointing to the object. -
SuperMap.Util.copy(des, soc)
Util.js, line 62 -
Copy object.
Name Type Description des
Object optional Target object.
soc
Object source object.
-
SuperMap.Util.copyAttributes(destination, source)
Util.js, line 911 -
copy attributes, don't copy method name(CLASS_NAME).
Name Type Description destination
Object optional The target object need to copy.
source
Object The source object.
-
SuperMap.Util.copyAttributesWithClip(destination, source, clip)
Util.js, line 931 -
Copy attributes in the source object to the target object. (don't copy CLASS_NAME and function)
Name Type Description destination
Object optional the target object.
source
Object the source object.
clip
Array.<string> Properties that are forbidden to be copied to the target object in the source object. The purpose is to prevent the tampering of the non - modifiable attributes on the target object.
-
SuperMap.Util.createUniqueID(prefix){string}
Util.js, line 415 -
Create a unique ID value.
Name Type Description prefix
string optional prefix.
Returns:
Type Description string The unique ID value. -
SuperMap.Util.extend(destination, source){Object}
Util.js, line 25 -
Copy all properties of the source object to the target object. The undefined property that on the source object will not be set on the target object.
Name Type Description destination
Object optional Target object.
source
Object source object. It's property will be set to the target object.
Returns:
Type Description Object Target object. Example
To copy all the properties of the SuperMap.Size object to the custom object, the use method is as follows: var size = new SuperMap.Size(100, 100); var obj = {}; SuperMap.Util.extend(obj, size);
-
SuperMap.Util.getBrowser(){Object}
Util.js, line 633 -
Get browser related information. Supported browsers include: Opera, Internet Explorer, Safari and Firefox.
Returns:
Type Description Object Get the name, the version, and the device name of the browser. The corresponding attributes are name, version, device. -
SuperMap.Util.getElement(){Array.<HTMLElement>}
Util.js, line 103 -
Get array of the HTML element.
Returns:
Type Description Array.<HTMLElement> Array of the HTML element. -
SuperMap.Util.getParameters(url){Object}
Util.js, line 354 -
Parsing the parameter objects from the URL string.
Name Type Description url
string URL。
Returns:
Type Description Object Parsed parameter object. -
SuperMap.Util.getParameterString(params){string}
Util.js, line 270 -
Transform the parameter object to the parameter string in the GEI request of HTTP. For example: "key1=value1&key2=value2&key3=value3"。
Name Type Description params
Object parameter object.
Returns:
Type Description string The parameter string in the GEI request of HTTP. -
SuperMap.Util.getResolutionFromScale(scale, units){number}
Util.js, line 547 -
Transform the scale to the resolution.
Name Type Default Description scale
number The scale.
units
string 'degrees' optional The unit of the scale.
Returns:
Type Description number resolution. -
SuperMap.Util.getResolutionFromScaleDpi(scale, dpi, coordUnit, datumAxis){number}
Util.js, line 846 -
Calculation the screen resolution according to scale and DPI.
Name Type Default Description scale
number Scale.
dpi
number Image resolution, representing the number of pixels per inch.
coordUnit
string optional The map unit of the projection coordinate system.
datumAxis
number 6378137 optional Ellipsoid long half axis of the geo coordinate system. When user custom maps are Options, if the value of the parameter is not specified, the system is defaults to the ellipsoid long half axis 6378137 of the WGS84 reference system.
Returns:
Type Description number Return to the current scale of screen resolution. -
SuperMap.Util.getScaleFromResolution(resolution, units){number}
Util.js, line 566 -
Turn the scale into a resolution.
Name Type Default Description resolution
number resolution.
units
string 'degrees' optional The unit of the resolution.
Returns:
Type Description number scale. -
SuperMap.Util.getScaleFromResolutionDpi(resolution, dpi, coordUnit, datumAxis){number}
Util.js, line 874 -
Calculation of scale according to resolution, dpi, coordUnit and datumAxis.
Name Type Default Description resolution
number Map resolution used to calculate scale.
dpi
number Image resolution, representing the number of pixels per inch.
coordUnit
string optional The map unit of the projection coordinate system.
datumAxis
number 6378137 optional Ellipsoid long half axis of the geo coordinate system. When user custom maps are Options, if the value of the parameter is not specified, the system is defaults to the ellipsoid long half axis 6378137 of the WGS84 reference system.
Returns:
Type Description number Returns the scale of current screen resolution. -
SuperMap.Util.getTextBounds(style, text, element){Object}
Util.js, line 1049 -
Get width and height of the text's outer rectangle.
Name Type Description style
SuperMap.ThemeStyle Text style.
text
string text content.
element
Object DOM element.
Returns:
Type Description Object Return to the width and height information after cut. -
SuperMap.Util.indexOf(array, obj){number}
Util.js, line 160 -
Get the index value of an object in an array.
Name Type Description array
Array array.
obj
Object object.
Returns:
Type Description number the index value of an object in an array. -
SuperMap.Util.isArray(a){boolean}
Util.js, line 133 -
Determine whether an object is an array.
Name Type Description a
Object object.
Returns:
Type Description boolean Whether it is an array. -
SuperMap.Util.isElement(o){boolean}
Util.js, line 124 -
The "instance of" cross browser implementation.
Name Type Description o
Object object.
Returns:
Type Description boolean Whether it is a page element. -
SuperMap.Util.isInTheSameDomain(url){boolean}
Util.js, line 684 -
Determine whether a URL request is in the current domain.
Name Type Description url
string URL request string.
Returns:
Type Description boolean whether a URL request is in the current domain. -
SuperMap.Util.lineIntersection(a1, a2, b1, b2){Object}
Util.js, line 1004 -
Judge whether there is a intersection between the two lines.
Name Type Description a1
SuperMap.Geometry.Point The starting node of the first line segment.
a2
SuperMap.Geometry.Point The end node of the first line segment.
b1
SuperMap.Geometry.Point The starting node of the second line segment.
b2
SuperMap.Geometry.Point The end node of the second line segment.
Returns:
Type Description Object If the intersection returns to the intersection, if the disjoint is not intersected to return to the position relation of two line segments. -
SuperMap.Util.modifyDOMElement(element, id, px, sz, position, border, overflow, opacity)
Util.js, line 190 -
Modify many of the attributes of a DOM element.
Name Type Description element
HTMLElement DOM elements to be modified.
id
string optional ID of the DOM element.
px
SuperMap.Pixel optional The left and top attributes that be contained on the style attribute of the DOM element.
sz
SuperMap.Size optional The width and height attributes that be contained on the style attribute of the DOM element.
position
string optional The position attribute of the DOM element.
border
string optional The border attribute on the style of the DOM element.
overflow
string optional The overflow attribute on the style of the DOM element.
opacity
number optional Opacity value. The range of value is (0.0 - 1.0).
-
SuperMap.Util.normalizeScale(scale){number}
Util.js, line 536 -
Name Type Description scale
number scale
Returns:
Type Description number Return to the normal scale value. -
SuperMap.Util.rad(x){number}
Util.js, line 345 -
Transform degree to radian.
Name Type Description x
number The degree.
Returns:
Type Description number The radian. -
SuperMap.Util.removeItem(array, item){Array}
Util.js, line 144 -
Delete one item from the array.
Name Type Description array
Array array.
item
Object An item that is to be deleted in an array.
Returns:
Type Description Array The array after the execution of the delete operation. -
SuperMap.Util.reset(obj)
Util.js, line 78 -
Disposes the resource. The property that references resource is set to null.
Name Type Description obj
Object optional Target object.
-
SuperMap.Util.supportCanvas(){boolean}
Util.js, line 666 -
Determine whether the browser supports Canvas.
Returns:
Type Description boolean Whether the current browser supports HTML5 Canvas. -
SuperMap.Util.toFloat(number, precision){number}
Util.js, line 329 -
The string is converted to a number with accuracy.
Name Type Default Description number
string string.
precision
number 14 optional precision.
Returns:
Type Description number Number. -
SuperMap.Util.toJSON(obj){string}
Util.js, line 771 -
Transform the object to the JSON string.
Name Type Description obj
Object The object turned to the JSON.
Returns:
Type Description string The JSON string. -
SuperMap.Util.transformResult(result){Object}
Util.js, line 898 -
Transform the query result
Name Type Description result
Object the query result
Returns:
Type Description Object The query results after the conversion. -
SuperMap.Util.urlAppend(url, paramStr){string}
Util.js, line 305 -
Additional arguments to URL.
Name Type Description url
string URL strings to be added to parameters.
paramStr
string The parameters to be added.
Returns:
Type Description string The new URL.