Learning about openlayers and introducing openlayers related classes! Recently, I like to study open-source foreign technologies.

Source: Internet
Author: User
(3) basetypes: defines underlying classes and custom JS built-in classes
Let's talk about the "own" class built by openlyers under the basetypes of the base type. They are: openlayers. lonlat, openlayers. pixel, openlayers. Size, openlayers. element, openlayers. bounds, and openlayers. Class. The following sections describe:
Openlayers. lonlat: longitude and latitude class. Its instance provides a map with a longitude and latitude pair, that is, a location. There are two attributes: Lon (x-axis coodinate) and lat (Y-axis coordinate ). Here we will explain how the latitude and longitude are entangled with the x-axis and Y-axis coordinates? Yes: When a map is projected by geographical coordinates, It is the latitude and longitude; otherwise, it is the x/y axis coordinate of the map. In addition to constructors, five functions are implemented:
Toshortstring: function () converts coordinates to strings;
Clone: function () copies a lonlat object;
Add: function (Lon, Lat) changes the location of an existing map;
Return new openlayers. lonlat (this. Lon + Lon, this. LAT + LAT );
Equals: function (LL) determines whether the incoming Lon and lat pairs are equal to the current ones;
Wrapdateline: function (maxextent) Copy (Lon, Lat), which is specified as the maximum range of the boundary.
Openlayers. pixel: pixel class, which presents the pixel position on the display in the form of (x, y) coordinates. There are two attributes: X coordinate and Y coordinate. Four member functions are provided:
Clone: function () Copies pixels;
Equals: function (PX) determines whether two pixels are equal;
Add: function (x, y) changes (x, y) to form a new pixel;
Return new openlayers. pixel (this. x + X, this. Y + y );
Offset: function (PX) calls add () to offset the pixel position.
Newpx = This. Add (PX. X, PX. y );
Openlayers. Size: it also has two attributes: width and height. Two member functions are implemented: Clone: function () and equals: function (sz.
Openlayers. element: In this namespace, developers write a lot of APIS, including visible, toggle, hide, show, remove, getheight, getdimensions, and getstyle, to display, hide, delete, gain height, and obtain the range of elements. Take the getheight function as an example. Let's look at its Code :
/**
* Apifunction: getheight
*
* Parameters:
* Element-{domelement}
*
* Returns:
* {INTEGER} the offset height of the element passed in
*/
Getheight: function (element ){
Element = openlayers. util. getelement (element );
Return element. offsetheight;
}
The Document Object Model Dom is involved here. The function itself is very simple and returns the height of the element.
Openlayers. bounds: in this class, data is stored in four floating-point numbers: Left, bottom, right, and top. It is a box-like range. It implements three functions to describe a bound: tostring, toarray, and tobbox. The code for tostring is as follows: Copy content to clipboard
Code:

/**
* Apimethod: tostring
*
* Returns:
* {String} string representation of bounds object.
* (Ex. <I> "left-Bottom = (5, 42) Right-Top = (10, 45)" </I>)
*/
Tostring: function (){
Return ("left-Bottom = (" + this. Left + "," + this. Bottom + ")"
+ "Right-Top = (" + this. Right + "," + this. Top + ")");
}

The result is similar to "left-Bottom = (5, 42) Right-Top = (10, 45 )"
Three bound data source functions: fromstring, fromarray, and fromsize;
Five functions for retrieving object attributes: getwidth, getheight, getsize, getcenterpixel, and getcenterlonlat;
There are also: Add: function (x, y), extend: function (object), containslonlat, containspixel, contains, intersectsbounds, containsbounds, determinequadrant, wrapdateline. Take the extend function as an example to look at the source code.Copy content to clipboard
Code:

Extend: function (object ){
VaR bounds = NULL;
If (object ){
Switch (object. class_name ){
Case "openlayers. lonlat ":
Bounds = new openlayers. bounds (object. Lon, object. Lat, object. Lon, object. LAT );
Break;
Case "openlayers. Geometry. Point ":
Bounds = new openlayers. bounds (object. X, object. Y, object. X, object. y );
Break;
Case "openlayers. bounds ":
Bounds = object;
Break;
}
If (bounds ){
If (this. Left = NULL) | (bounds. Left <thi s. Left )){
This. Left = bounds. Left ;}
If (this. Bottom = NULL) | (bounds. Bottom <this. Bottom )){
This. Bottom = bounds. Bottom ;}
If (this. Right = NULL) | (bounds. Right> T his. Right )){
This. Right = bounds. Right ;}
If (this. Top = NULL) | (bounds. Top> This. Top )){
This. Top = bounds. Top ;}
}
}
}

We can see that bounds can be extended in three forms: Point, lonlat, or bounds. The condition is that the zero coordinate is in the upper left corner of the screen.
Openlayers. Class: this class is the "everyone" in openlayers. You only need to create other classes and implement multiple inheritance. The usage is as follows:
Create a single inheritance: class = openlayers. Class (prototype );
Create multiple inheritance: class = openlayers. Class (class1, class2, prototype );
The bottom-layer class is mentioned, and the extension of the built-in JS class is written back.

You are welcome to reprint it. Please indicate the source.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.