Documentation improvements provided by Glen Stampoultzis. (Thanks Glen!) Closes

#825, #836.


git-svn-id: http://svn.openlayers.org/trunk/openlayers@3728 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
crschmidt
2007-07-13 11:14:46 +00:00
parent 53ed14c379
commit 4f70df0029
6 changed files with 191 additions and 65 deletions

View File

@@ -15,6 +15,7 @@ Tim Schaub
Christopher Schmidt Christopher Schmidt
Cameron Shorter Cameron Shorter
Paul Spencer Paul Spencer
Glen Stampoultzis
James Stembridge James Stembridge
Erik Uzureau Erik Uzureau
Bill Woodall Bill Woodall

View File

@@ -5,7 +5,49 @@
/** /**
* Class: OpenLayers.Control * Class: OpenLayers.Control
* Controls affect the display or behavior of the map. They allow everything * Controls affect the display or behavior of the map. They allow everything
* from panning and zooming to displaying a scale indicator. * from panning and zooming to displaying a scale indicator. Controls by
* default are added to the map they are contained within however it is
* possible to add a control to an external div by passing the div in the
* options parameter.
*
* Example:
* The following example shows how to add many of the common controls
* to a map.
*
* > var map = new OpenLayers.Map('map', { controls: [] });
* >
* > map.addControl(new OpenLayers.Control.PanZoomBar());
* > map.addControl(new OpenLayers.Control.MouseToolbar());
* > map.addControl(new OpenLayers.Control.LayerSwitcher({'ascending':false}));
* > map.addControl(new OpenLayers.Control.Permalink());
* > map.addControl(new OpenLayers.Control.Permalink('permalink'));
* > map.addControl(new OpenLayers.Control.MousePosition());
* > map.addControl(new OpenLayers.Control.OverviewMap());
* > map.addControl(new OpenLayers.Control.KeyboardDefaults());
*
* The next code fragment is a quick example of how to intercept
* shift-mouse click to display the extent of the bounding box
* dragged out by the user. Usually controls are not created
* in exactly this manner. See the source for a more complete
* example:
*
* > var control = new OpenLayers.Control();
* > OpenLayers.Util.extend(control, {
* > draw: function () {
* > // this Handler.Box will intercept the shift-mousedown
* > // before Control.MouseDefault gets to see it
* > this.box = new OpenLayers.Handler.Box( control,
* > {"done": this.notice},
* > {keyMask: OpenLayers.Handler.MOD_SHIFT});
* > this.box.activate();
* > },
* >
* > notice: function (bounds) {
* > alert(bounds);
* > }
* > });
* > map.addControl(control);
*
*/ */
OpenLayers.Control = OpenLayers.Class.create(); OpenLayers.Control = OpenLayers.Class.create();
@@ -63,7 +105,12 @@ OpenLayers.Control.prototype = {
/** /**
* Constructor: OpenLayers.Control * Constructor: OpenLayers.Control
* Create an OpenLayers Control. * Create an OpenLayers Control. The options passed as a parameter
* directly extend the control. For example passing the following:
*
* > var control = new OpenLayers.Control({div: myDiv});
*
* Overrides the default div attribute value of null.
* *
* Parameters: * Parameters:
* options - {Object} * options - {Object}
@@ -81,6 +128,9 @@ OpenLayers.Control.prototype = {
/** /**
* Method: destroy * Method: destroy
* The destroy method is used to perform any clean up before the control
* is dereferenced. Typically this is where event listeners are removed
* to prevent memory leaks.
*/ */
destroy: function () { destroy: function () {
// eliminate circular references // eliminate circular references
@@ -108,9 +158,14 @@ OpenLayers.Control.prototype = {
/** /**
* Method: draw * Method: draw
* The draw method is called when the control is ready to be displayed
* on the page. If a div has not been created one is created. Controls
* with a visual component will almost always want to override this method
* to customize the look of control.
* *
* Parameters: * Parameters:
* px - {<OpenLayers.Pixel>} * px - {<OpenLayers.Pixel>} The top-left pixel position of the control
* or null.
* *
* Return: * Return:
* {DOMElement} A reference to the DIV DOMElement containing the control * {DOMElement} A reference to the DIV DOMElement containing the control
@@ -130,6 +185,8 @@ OpenLayers.Control.prototype = {
/** /**
* Method: moveTo * Method: moveTo
* Sets the left and top style attributes to the passed in pixel
* coordinates.
* *
* Parameters: * Parameters:
* px - {<OpenLayers.Pixel>} * px - {<OpenLayers.Pixel>}
@@ -143,9 +200,13 @@ OpenLayers.Control.prototype = {
/** /**
* Method: activate * Method: activate
* Explicitly activates a control and it's associated
* handler if one has been set. Controls can be
* deactivated by calling the deactivate() method.
* *
* Return: * Return:
* {Boolean} * {Boolean} True if the control was successfully activated or
* false if the control was already active.
*/ */
activate: function () { activate: function () {
if (this.active) { if (this.active) {
@@ -160,9 +221,12 @@ OpenLayers.Control.prototype = {
/** /**
* Method: deactivate * Method: deactivate
* Deactivates a control and it's associated handler if any. The exact
* effect of this depends on the control itself.
* *
* Return: * Return:
* {Boolean} * {Boolean} True if the control was effectively deactivated or false
* if the control was already inactive.
*/ */
deactivate: function () { deactivate: function () {
if (this.active) { if (this.active) {

View File

@@ -5,6 +5,15 @@
/** /**
* Class: OpenLayers.Icon * Class: OpenLayers.Icon
*
* The icon represents a graphical icon on the screen. Typically used in
* conjunction with a <OpenLayers.Marker> to represent markers on a screen.
*
* An icon has a url, size and position. It also contains an offset which
* allows the center point to be represented correctly. This can be
* provided either as a fixed offset or a function provided to calculate
* the desired offset.
*
*/ */
OpenLayers.Icon = OpenLayers.Class.create(); OpenLayers.Icon = OpenLayers.Class.create();
OpenLayers.Icon.prototype = { OpenLayers.Icon.prototype = {
@@ -65,7 +74,8 @@ OpenLayers.Icon.prototype = {
/** /**
* Method: destroy * Method: destroy
* nullify references to prevent circular references and memory leaks * Nullify references and remove event listeners to prevent circular
* references and memory leaks
*/ */
destroy: function() { destroy: function() {
OpenLayers.Event.stopObservingElement(this.imageDiv.firstChild); OpenLayers.Event.stopObservingElement(this.imageDiv.firstChild);

View File

@@ -10,6 +10,10 @@
* Class: OpenLayers.Map * Class: OpenLayers.Map
* Instances of OpenLayers.Map are interactive maps embedded in a web page. * Instances of OpenLayers.Map are interactive maps embedded in a web page.
* Create a new map with the <OpenLayers.Map> constructor. * Create a new map with the <OpenLayers.Map> constructor.
*
* On their own maps do not provide much functionality. To extend a map
* it's necessary to add controls (<OpenLayers.Control>) and
* layers (<OpenLayers.Layer>) to the map.
*/ */
OpenLayers.Map = OpenLayers.Class.create(); OpenLayers.Map = OpenLayers.Class.create();
/** /**

View File

@@ -10,13 +10,28 @@
* Class: OpenLayers.Marker * Class: OpenLayers.Marker
* Instances of OpenLayers.Marker are a combination of a * Instances of OpenLayers.Marker are a combination of a
* <OpenLayers.LonLat> and an <OpenLayers.Icon>. * <OpenLayers.LonLat> and an <OpenLayers.Icon>.
*
* Markers are generally added to a special layer called
* <OpenLayers.Layer.Makers>.
*
* Example:
* (code)
* var markers = new OpenLayers.Layer.Markers( "Markers" );
* map.addLayer(markers);
*
* var size = new OpenLayers.Size(10,17);
* var offset = new OpenLayers.Pixel(-(size.w/2), -size.h);
* var icon = new OpenLayers.Icon('http://boston.openguides.org/markers/AQUA.png',size,offset);
* markers.addMarker(new OpenLayers.Marker(new OpenLayers.LonLat(0,0),icon));
*
* (end)
*/ */
OpenLayers.Marker = OpenLayers.Class.create(); OpenLayers.Marker = OpenLayers.Class.create();
OpenLayers.Marker.prototype = { OpenLayers.Marker.prototype = {
/** /**
* Property: icon * Property: icon
* {<OpenLayers.Icon>} * {<OpenLayers.Icon>} The icon used by this marker.
*/ */
icon: null, icon: null,
@@ -28,21 +43,21 @@ OpenLayers.Marker.prototype = {
/** /**
* Property: events * Property: events
* {<OpenLayers.Events>} * {<OpenLayers.Events>} the event handler.
*/ */
events: null, events: null,
/** /**
* Property: map * Property: map
* {<OpenLayers.Map>} * {<OpenLayers.Map>} the map this marker is attached to
*/ */
map: null, map: null,
/** /**
* Constructor: OpenLayers.Marker * Constructor: OpenLayers.Marker
* Paraemeters: * Paraemeters:
* icon - {<OpenLayers.Icon>} * icon - {<OpenLayers.Icon>} the icon for this marker
* lonlat - {<OpenLayers.LonLat>} * lonlat - {<OpenLayers.LonLat>} the position of this marker
*/ */
initialize: function(lonlat, icon) { initialize: function(lonlat, icon) {
this.lonlat = lonlat; this.lonlat = lonlat;
@@ -91,7 +106,7 @@ OpenLayers.Marker.prototype = {
* Move the marker to the new location. * Move the marker to the new location.
* *
* Parameters: * Parameters:
* px - {<OpenLayers.Pixel>} * px - {<OpenLayers.Pixel>} the pixel position to move to
*/ */
moveTo: function (px) { moveTo: function (px) {
if ((px != null) && (this.icon != null)) { if ((px != null) && (this.icon != null)) {
@@ -118,9 +133,11 @@ OpenLayers.Marker.prototype = {
/** /**
* Method: inflate * Method: inflate
* Englarges the markers icon by the specified ratio.
* *
* Parameters: * Parameters:
* inflate - {float} * inflate - {float} the ratio to enlarge the marker by (passing 2
* will double the size).
*/ */
inflate: function(inflate) { inflate: function(inflate) {
if (this.icon) { if (this.icon) {

View File

@@ -5,6 +5,23 @@
/** /**
* Class: OpenLayers.Popup * Class: OpenLayers.Popup
*
* A popup is a small div that can opened and closed on the map.
* Typically opened in response to clicking on a marker.
* See <OpenLayers.Marker>. Popup's don't require their own
* layer and are added the the map using the <OpenLayers.Map.addPopup>
* method.
*
* Example:
* (code)
* popup = new OpenLayers.Popup("chicken",
* new OpenLayers.LonLat(5,40),
* new OpenLayers.Size(200,200),
* "example popup",
* true);
*
* map.addPopup(popup);
* (end)
*/ */
OpenLayers.Popup = OpenLayers.Class.create(); OpenLayers.Popup = OpenLayers.Class.create();
@@ -18,72 +35,73 @@ OpenLayers.Popup.prototype = {
/** /**
* Property: events * Property: events
* {<OpenLayers.Events>} * {<OpenLayers.Events>} custom event manager
*/ */
events: null, events: null,
/** Property: id /** Property: id
* {String} * {String} the unique identifier assigned to this popup.
*/ */
id: "", id: "",
/** /**
* Property: lonlat * Property: lonlat
* {<OpenLayers.LonLat>} * {<OpenLayers.LonLat>} the position of this popup on the map
*/ */
lonlat: null, lonlat: null,
/** /**
* Property: div * Property: div
* {DOMElement} * {DOMElement} the div that contains this popup.
*/ */
div: null, div: null,
/** /**
* Property: size * Property: size
* {<OpenLayers.Size>} * {<OpenLayers.Size>} the width and height of the popup.
*/ */
size: null, size: null,
/** /**
* Property: contentHTML * Property: contentHTML
* {String} * {String} The HTML that this popup displays.
*/ */
contentHTML: "", contentHTML: "",
/** /**
* Property: backgroundColor * Property: backgroundColor
* {String} * {String} the background color used by the popup.
*/ */
backgroundColor: "", backgroundColor: "",
/** /**
* Property: opacity * Property: opacity
* {float} * {float} the opacity of this popup (between 0.0 and 1.0)
*/ */
opacity: "", opacity: "",
/** /**
* Property: border * Property: border
* {String} * {String} the border size of the popup. (eg 2px)
*/ */
border: "", border: "",
/** /**
* Property: contentDiv * Property: contentDiv
* {DOMElement} * {DOMElement} a reference to the element that holds the content of
* the div.
*/ */
contentDiv: null, contentDiv: null,
/** /**
* Property: groupDiv * Property: groupDiv
* {DOMElement} * {DOMElement} the parent of <OpenLayers.Popup.contentDiv>
*/ */
groupDiv: null, groupDiv: null,
/** /**
* Property: padding * Property: padding
* {int} * {int} the internal padding of the content div.
*/ */
padding: 5, padding: 5,
@@ -99,11 +117,15 @@ OpenLayers.Popup.prototype = {
* Create a popup. * Create a popup.
* *
* Parameters: * Parameters:
* id - {String} * id - {String} a unqiue identifier for this popup. If null is passed
* lonlat - {<OpenLayers.LonLat>} * an identifier will be automatically generated.
* size - {<OpenLayers.Size>} * lonlat - {<OpenLayers.LonLat>} The position on the map the popup will
* contentHTML - {String} * be shown.
* closeBox - {Boolean} * size - {<OpenLayers.Size>} The size of the popup.
* contentHTML - {String} The HTML content to display inside the
* popup.
* closeBox - {Boolean} Whether to display a close box inside
* the popup.
*/ */
initialize:function(id, lonlat, size, contentHTML, closeBox) { initialize:function(id, lonlat, size, contentHTML, closeBox) {
if (id == null) { if (id == null) {
@@ -178,10 +200,11 @@ OpenLayers.Popup.prototype = {
}, },
/** /**
* method: draw * Method: draw
* Constructs the elements that make up the popup.
* *
* Parameters: * Parameters:
* px - {<OpenLayers.Pixel>} * px - {<OpenLayers.Pixel>} the position the popup in pixels.
* *
* Return: * Return:
* {DOMElement} Reference to a div that contains the drawn popup * {DOMElement} Reference to a div that contains the drawn popup
@@ -219,7 +242,7 @@ OpenLayers.Popup.prototype = {
* Method: moveTo * Method: moveTo
* *
* Parameters: * Parameters:
* px - {<OpenLayers.Pixel>} * px - {<OpenLayers.Pixel>} the top and left position of the popup div.
*/ */
moveTo: function(px) { moveTo: function(px) {
if ((px != null) && (this.div != null)) { if ((px != null) && (this.div != null)) {
@@ -229,7 +252,7 @@ OpenLayers.Popup.prototype = {
}, },
/** /**
* method: visible * Method: visible
* *
* Returns: * Returns:
* {Boolean} Boolean indicating whether or not the popup is visible * {Boolean} Boolean indicating whether or not the popup is visible
@@ -240,6 +263,7 @@ OpenLayers.Popup.prototype = {
/** /**
* Method: toggle * Method: toggle
* Toggles visibility of the popup.
*/ */
toggle: function() { toggle: function() {
OpenLayers.Element.toggle(this.div); OpenLayers.Element.toggle(this.div);
@@ -247,6 +271,7 @@ OpenLayers.Popup.prototype = {
/** /**
* Method: show * Method: show
* Makes the popup visible.
*/ */
show: function() { show: function() {
OpenLayers.Element.show(this.div); OpenLayers.Element.show(this.div);
@@ -254,6 +279,7 @@ OpenLayers.Popup.prototype = {
/** /**
* Method: hide * Method: hide
* Makes the popup invisible.
*/ */
hide: function() { hide: function() {
OpenLayers.Element.hide(this.div); OpenLayers.Element.hide(this.div);
@@ -261,9 +287,10 @@ OpenLayers.Popup.prototype = {
/** /**
* Method: setSize * Method: setSize
* Used to adjust the size of the popup.
* *
* Parameters: * Parameters:
* size - {<OpenLayers.Size>} * size - {<OpenLayers.Size>} the new size of the popup in pixels.
*/ */
setSize:function(size) { setSize:function(size) {
if (size != undefined) { if (size != undefined) {
@@ -282,9 +309,9 @@ OpenLayers.Popup.prototype = {
/** /**
* Method: setBackgroundColor * Method: setBackgroundColor
* * Sets the background color of the popup.
* Parameters: * Parameters:
* color - {String} * color - {String} the background color. eg "#FFBBBB"
*/ */
setBackgroundColor:function(color) { setBackgroundColor:function(color) {
if (color != undefined) { if (color != undefined) {
@@ -298,9 +325,10 @@ OpenLayers.Popup.prototype = {
/** /**
* Method: setOpacity * Method: setOpacity
* Sets the opacity of the popup.
* *
* Parameters: * Parameters:
* opacity - {float} * opacity - {float} A value between 0.0 (transparent) and 1.0 (solid).
*/ */
setOpacity:function(opacity) { setOpacity:function(opacity) {
if (opacity != undefined) { if (opacity != undefined) {
@@ -318,9 +346,10 @@ OpenLayers.Popup.prototype = {
/** /**
* Method: setBorder * Method: setBorder
* Sets the border style of the popup.
* *
* Parameters: * Parameters:
* border - {int} * border - {String} The border style value. eg 2px
*/ */
setBorder:function(border) { setBorder:function(border) {
if (border != undefined) { if (border != undefined) {
@@ -334,9 +363,10 @@ OpenLayers.Popup.prototype = {
/** /**
* Method: setContentHTML * Method: setContentHTML
* Allows the user to set the HTML content of the popup.
* *
* Parameters: * Parameters:
* contentHTML - {String} * contentHTML - {String} HTML for the div.
*/ */
setContentHTML:function(contentHTML) { setContentHTML:function(contentHTML) {
if (contentHTML != null) { if (contentHTML != null) {