Merge all changes from the naturaldocs sandbox. This brings all the work that
has been done in the NaturalDocs branch back to trunk. Thanks to everyone who helped out in making this happen. (I could list people, but the list would be long, and I'm already mentally on vacation.) git-svn-id: http://svn.openlayers.org/trunk/openlayers@3545 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
@@ -1,78 +1,88 @@
|
||||
/* Copyright (c) 2006 MetaCarta, Inc., published under a modified BSD license.
|
||||
* See http://svn.openlayers.org/trunk/openlayers/repository-license.txt
|
||||
* for the full text of the license. */
|
||||
/**
|
||||
* @fileoverview Locator Map Control
|
||||
* @author Tim Schaub
|
||||
*/
|
||||
|
||||
/**
|
||||
* @class
|
||||
*
|
||||
* @requires OpenLayers/Control.js
|
||||
* @requires OpenLayers/BaseTypes.js
|
||||
* @requires OpenLayers/Events.js
|
||||
*
|
||||
* Class: OpenLayers.Control.OverviewMap
|
||||
* Create an overview map to display the extent of your main map and provide
|
||||
* additional navigation control. Create a new overview map with the
|
||||
* <OpenLayers.Control.OverviewMap> constructor.
|
||||
*
|
||||
* Inerits from:
|
||||
* - <OpenLayers.Control>
|
||||
*/
|
||||
OpenLayers.Control.OverviewMap = OpenLayers.Class.create();
|
||||
|
||||
OpenLayers.Control.OverviewMap.prototype =
|
||||
OpenLayers.Class.inherit( OpenLayers.Control, {
|
||||
|
||||
/** For div.id
|
||||
* @type String */
|
||||
/**
|
||||
* Property: id
|
||||
* {String} For div.id
|
||||
*/
|
||||
id: "OverviewMap",
|
||||
|
||||
/** @type DOMElement */
|
||||
/**
|
||||
* Property: element
|
||||
* {DOMElement} The DOM element that contains the overview map
|
||||
*/
|
||||
element: null,
|
||||
|
||||
/**
|
||||
* The overvew map itself.
|
||||
* @type OpenLayers.Map
|
||||
* APIProperty: ovmap
|
||||
* {<OpenLayers.Map>} A reference to the overvew map itself.
|
||||
*/
|
||||
ovmap: null,
|
||||
|
||||
/**
|
||||
* The overvew map size in pixels. Note that this is the size of the map
|
||||
* itself - the element that contains the map (default class name
|
||||
* olControlOverviewMapElement) may have padding or other style attributes
|
||||
* added via CSS.
|
||||
* @type OpenLayers.Size
|
||||
* APIProperty: size
|
||||
* {<OpenLayers.Size>} The overvew map size in pixels. Note that this is
|
||||
* the size of the map itself - the element that contains the map (default
|
||||
* class name olControlOverviewMapElement) may have padding or other style
|
||||
* attributes added via CSS.
|
||||
*/
|
||||
size: new OpenLayers.Size(180, 90),
|
||||
|
||||
/**
|
||||
* Ordered list of layers in the overview map. If none are sent at
|
||||
* construction, then the default below is used.
|
||||
*
|
||||
* @type Array(OpenLayers.Layer)
|
||||
* APIProperty: layers
|
||||
* {Array(<OpenLayers.Layer>)} Ordered list of layers in the overview map.
|
||||
* If none are sent at construction, the base layer for the main map is used.
|
||||
*/
|
||||
layers: null,
|
||||
|
||||
/**
|
||||
* The ratio of the overview map resolution to the main map resolution
|
||||
* at which to zoom farther out on the overview map.
|
||||
* @type Float
|
||||
* APIProperty: minRatio
|
||||
* {Numver} The ratio of the overview map resolution to the main map
|
||||
* resolution at which to zoom farther out on the overview map.
|
||||
*/
|
||||
minRatio: 8,
|
||||
|
||||
/**
|
||||
* The ratio of the overview map resolution to the main map resolution
|
||||
* at which to zoom farther in on the overview map.
|
||||
* @type Float
|
||||
* APIProperty: maxRatio
|
||||
* {Float} The ratio of the overview map resolution to the main map
|
||||
* resolution at which to zoom farther in on the overview map.
|
||||
*/
|
||||
maxRatio: 32,
|
||||
|
||||
/**
|
||||
* An object containing any non-default properties to be sent to the
|
||||
* overview map's map constructor. These should include any non-default
|
||||
* APIProperty: mapOptions
|
||||
* {Object} An object containing any non-default properties to be sent to
|
||||
* the overview map's map constructor. These should include any non-default
|
||||
* options that the main map was constructed with.
|
||||
* @type: Object
|
||||
*/
|
||||
mapOptions: null,
|
||||
|
||||
/**
|
||||
* @constructor
|
||||
* @param {Object} options Hashtable of options to set on the overview map
|
||||
* Constructor: OpenLayers.Control.OverviewMap
|
||||
* Create a new overview map
|
||||
*
|
||||
* Parameters:
|
||||
* object - {Object} Properties of this object will be set on the overview
|
||||
* map object. Note, to set options on the map object contained in this
|
||||
* control, set <mapOptions> as one of the options properties.
|
||||
*/
|
||||
initialize: function(options) {
|
||||
this.layers = new Array();
|
||||
@@ -80,7 +90,8 @@ OpenLayers.Control.OverviewMap.prototype =
|
||||
},
|
||||
|
||||
/**
|
||||
*
|
||||
* APIMethod: destroy
|
||||
* Deconstruct the control
|
||||
*/
|
||||
destroy: function() {
|
||||
if (!this.mapDiv) { // we've already been destroyed
|
||||
@@ -124,7 +135,8 @@ OpenLayers.Control.OverviewMap.prototype =
|
||||
},
|
||||
|
||||
/**
|
||||
* @type DOMElement
|
||||
* Method: draw
|
||||
* Render the control in the browser.
|
||||
*/
|
||||
draw: function() {
|
||||
OpenLayers.Control.prototype.draw.apply(this, arguments);
|
||||
@@ -249,14 +261,22 @@ OpenLayers.Control.OverviewMap.prototype =
|
||||
return this.div;
|
||||
},
|
||||
|
||||
/**
|
||||
* Method: baseLayerDraw
|
||||
* Draw the base layer - called if unable to complete in the initial draw
|
||||
*/
|
||||
baseLayerDraw: function() {
|
||||
this.draw();
|
||||
this.map.events.unregister("changebaselayer", this, this.baseLayerDraw);
|
||||
},
|
||||
|
||||
/**
|
||||
* @param {OpenLayers.Event} evt
|
||||
*/
|
||||
* Method: rectMouseOut
|
||||
* Handle browser events
|
||||
*
|
||||
* Parameters:
|
||||
* evt - {<OpenLayers.Event>} evt
|
||||
*/
|
||||
rectMouseOut: function (evt) {
|
||||
if(this.rectDragStart != null) {
|
||||
if(this.performedRectDrag) {
|
||||
@@ -278,8 +298,12 @@ OpenLayers.Control.OverviewMap.prototype =
|
||||
},
|
||||
|
||||
/**
|
||||
* @param {OpenLayers.Event} evt
|
||||
*/
|
||||
* Method: rectMouseDown
|
||||
* Handle browser events
|
||||
*
|
||||
* Parameters:
|
||||
* evt - {<OpenLayers.Event>} evt
|
||||
*/
|
||||
rectMouseDown: function (evt) {
|
||||
if(!OpenLayers.Event.isLeftClick(evt)) return;
|
||||
this.rectDragStart = evt.xy.clone();
|
||||
@@ -288,8 +312,12 @@ OpenLayers.Control.OverviewMap.prototype =
|
||||
},
|
||||
|
||||
/**
|
||||
* @param {OpenLayers.Event} evt
|
||||
*/
|
||||
* Method: rectMouseMove
|
||||
* Handle browser events
|
||||
*
|
||||
* Parameters:
|
||||
* evt - {<OpenLayers.Event>} evt
|
||||
*/
|
||||
rectMouseMove: function(evt) {
|
||||
if(this.rectDragStart != null) {
|
||||
var deltaX = this.rectDragStart.x - evt.xy.x;
|
||||
@@ -317,8 +345,12 @@ OpenLayers.Control.OverviewMap.prototype =
|
||||
},
|
||||
|
||||
/**
|
||||
* @param {OpenLayers.Event} evt
|
||||
*/
|
||||
* Method: rectMouseUp
|
||||
* Handle browser events
|
||||
*
|
||||
* Parameters:
|
||||
* evt - {<OpenLayers.Event>} evt
|
||||
*/
|
||||
rectMouseUp: function(evt) {
|
||||
if(!OpenLayers.Event.isLeftClick(evt)) return;
|
||||
if(this.performedRectDrag) {
|
||||
@@ -330,8 +362,12 @@ OpenLayers.Control.OverviewMap.prototype =
|
||||
},
|
||||
|
||||
/**
|
||||
* @param {OpenLayers.Event} evt
|
||||
*/
|
||||
* Method: rectDblClick
|
||||
* Handle browser events
|
||||
*
|
||||
* Parameters:
|
||||
* evt - {<OpenLayers.Event>} evt
|
||||
*/
|
||||
rectDblClick: function(evt) {
|
||||
this.performedRectDrag = false;
|
||||
OpenLayers.Event.stop(evt);
|
||||
@@ -339,8 +375,12 @@ OpenLayers.Control.OverviewMap.prototype =
|
||||
},
|
||||
|
||||
/**
|
||||
* @param {OpenLayers.Event} evt
|
||||
*/
|
||||
* Method: mapDivClick
|
||||
* Handle browser events
|
||||
*
|
||||
* Parameters:
|
||||
* evt - {<OpenLayers.Event>} evt
|
||||
*/
|
||||
mapDivClick: function(evt) {
|
||||
var pxBounds = this.getRectPxBounds();
|
||||
var pxCenter = pxBounds.getCenterPixel();
|
||||
@@ -362,9 +402,12 @@ OpenLayers.Control.OverviewMap.prototype =
|
||||
OpenLayers.Event.stop(evt);
|
||||
},
|
||||
|
||||
/** Set up the labels and divs for the control
|
||||
*
|
||||
* @param {OpenLayers.Event} e
|
||||
/**
|
||||
* Method: maximizeControl
|
||||
* Unhide the control. Called when the control is in the map viewport.
|
||||
*
|
||||
* Parameters:
|
||||
* e - {<OpenLayers.Event>}
|
||||
*/
|
||||
maximizeControl: function(e) {
|
||||
this.element.style.display = '';
|
||||
@@ -374,10 +417,13 @@ OpenLayers.Control.OverviewMap.prototype =
|
||||
}
|
||||
},
|
||||
|
||||
/** Hide all the contents of the control, shrink the size,
|
||||
* add the maximize icon
|
||||
/**
|
||||
* Method: minimizeControl
|
||||
* Hide all the contents of the control, shrink the size,
|
||||
* add the maximize icon
|
||||
*
|
||||
* @param {OpenLayers.Event} e
|
||||
* Parameters:
|
||||
* e - {<OpenLayers.Event>}
|
||||
*/
|
||||
minimizeControl: function(e) {
|
||||
this.element.style.display = 'none';
|
||||
@@ -387,12 +433,12 @@ OpenLayers.Control.OverviewMap.prototype =
|
||||
}
|
||||
},
|
||||
|
||||
/** Hide/Show all LayerSwitcher controls depending on whether we are
|
||||
* minimized or not
|
||||
*
|
||||
* @private
|
||||
*
|
||||
* @param {Boolean} minimize
|
||||
/**
|
||||
* Method: showToggle
|
||||
* Hide/Show the toggle depending on whether the control is minimized
|
||||
*
|
||||
* Parameters:
|
||||
* minimize - {Boolean}
|
||||
*/
|
||||
showToggle: function(minimize) {
|
||||
this.maximizeDiv.style.display = minimize ? '' : 'none';
|
||||
@@ -400,6 +446,7 @@ OpenLayers.Control.OverviewMap.prototype =
|
||||
},
|
||||
|
||||
/**
|
||||
* Method: update
|
||||
* Update the overview map after layers move.
|
||||
*/
|
||||
update: function() {
|
||||
@@ -416,6 +463,7 @@ OpenLayers.Control.OverviewMap.prototype =
|
||||
},
|
||||
|
||||
/**
|
||||
* Method: isSuitableOverview
|
||||
* Determines if the overview map is suitable given the extent and
|
||||
* resolution of the main map.
|
||||
*/
|
||||
@@ -433,6 +481,10 @@ OpenLayers.Control.OverviewMap.prototype =
|
||||
(this.ovmap.getExtent().containsBounds(testExtent)));
|
||||
},
|
||||
|
||||
/**
|
||||
* Method updateOverview
|
||||
* Called by <update> if <isSuitableOverview> returns true
|
||||
*/
|
||||
updateOverview: function() {
|
||||
var mapRes = this.map.getResolution();
|
||||
var targetRes = this.ovmap.getResolution();
|
||||
@@ -449,6 +501,10 @@ OpenLayers.Control.OverviewMap.prototype =
|
||||
this.updateRectToMap();
|
||||
},
|
||||
|
||||
/**
|
||||
* Method: createMap
|
||||
* Construct the map that this control contains
|
||||
*/
|
||||
createMap: function() {
|
||||
// create the overview map
|
||||
var options = OpenLayers.Util.extend(
|
||||
@@ -470,6 +526,7 @@ OpenLayers.Control.OverviewMap.prototype =
|
||||
},
|
||||
|
||||
/**
|
||||
* Method: updateRectToMap
|
||||
* Updates the extent rectangle position and size to match the map extent
|
||||
*/
|
||||
updateRectToMap: function() {
|
||||
@@ -487,6 +544,7 @@ OpenLayers.Control.OverviewMap.prototype =
|
||||
},
|
||||
|
||||
/**
|
||||
* Method: updateMapToRect
|
||||
* Updates the map extent to match the extent rectangle position and size
|
||||
*/
|
||||
updateMapToRect: function() {
|
||||
@@ -496,9 +554,12 @@ OpenLayers.Control.OverviewMap.prototype =
|
||||
},
|
||||
|
||||
/**
|
||||
* Method: getRectPxBounds
|
||||
* Get extent rectangle pixel bounds
|
||||
* @returns An OpenLayers.Bounds wich is the extent rectangle's pixel
|
||||
* bounds (relative to the parent element)
|
||||
*
|
||||
* Return:
|
||||
* {<OpenLayers.Bounds>} A bounds which is the extent rectangle's pixel
|
||||
* bounds (relative to the parent element)
|
||||
*/
|
||||
getRectPxBounds: function() {
|
||||
var top = parseInt(this.extentRectangle.style.top);
|
||||
@@ -509,8 +570,11 @@ OpenLayers.Control.OverviewMap.prototype =
|
||||
},
|
||||
|
||||
/**
|
||||
* Set extent rectangle pixel bounds.
|
||||
* @param {OpenLayers.Bounds} pxBounds
|
||||
* Method: setRectPxBounds
|
||||
* Set extent rectangle pixel bounds.
|
||||
*
|
||||
* Parameters:
|
||||
* pxBounds - {<OpenLayers.Bounds>}
|
||||
*/
|
||||
setRectPxBounds: function(pxBounds) {
|
||||
var top = Math.max(pxBounds.top, 0);
|
||||
@@ -526,12 +590,16 @@ OpenLayers.Control.OverviewMap.prototype =
|
||||
},
|
||||
|
||||
/**
|
||||
* @param {OpenLayers.Bounds} lonLatBounds
|
||||
*
|
||||
* @returns An OpenLayers.Bounds which is the passed-in map lon/lat extent
|
||||
* translated into pixel bounds for the overview map
|
||||
* @type OpenLayers.Bounds
|
||||
*/
|
||||
* Method: getRectBoundsFromMapBounds
|
||||
* Get the rect bounds from the map bounds.
|
||||
*
|
||||
* Parameters:
|
||||
* lonLatBounds - {<OpenLayers.Bounds>}
|
||||
*
|
||||
* Return:
|
||||
* {<OpenLayers.Bounds>}A bounds which is the passed-in map lon/lat extent
|
||||
* translated into pixel bounds for the overview map
|
||||
*/
|
||||
getRectBoundsFromMapBounds: function(lonLatBounds) {
|
||||
var leftBottomLonLat = new OpenLayers.LonLat(lonLatBounds.left,
|
||||
lonLatBounds.bottom);
|
||||
@@ -548,12 +616,16 @@ OpenLayers.Control.OverviewMap.prototype =
|
||||
},
|
||||
|
||||
/**
|
||||
* @param {OpenLayers.Bounds} pxBounds
|
||||
*
|
||||
* @returns An OpenLayers.Bounds which is the passed-in overview rect bounds
|
||||
* translated into lon/lat bounds for the overview map
|
||||
* @type OpenLayers.Bounds
|
||||
*/
|
||||
* Method: getMapBoundsFromRectBounds
|
||||
* Get the map bounds from the rect bounds.
|
||||
*
|
||||
* Parameters:
|
||||
* pxBounds - {<OpenLayers.Bounds>}
|
||||
*
|
||||
* Return:
|
||||
* {<OpenLayers.Bounds>} Bounds which is the passed-in overview rect bounds
|
||||
* translated into lon/lat bounds for the overview map
|
||||
*/
|
||||
getMapBoundsFromRectBounds: function(pxBounds) {
|
||||
var leftBottomPx = new OpenLayers.Pixel(pxBounds.left,
|
||||
pxBounds.bottom);
|
||||
@@ -566,12 +638,16 @@ OpenLayers.Control.OverviewMap.prototype =
|
||||
},
|
||||
|
||||
/**
|
||||
* @param {OpenLayers.Pixel} overviewMapPx
|
||||
*
|
||||
* @returns An OpenLayers.LonLat which is the passed-in overview map
|
||||
* OpenLayers.Pixel, translated into lon/lat by the overview map
|
||||
* @type OpenLayers.LonLat
|
||||
*/
|
||||
* Method: getLonLatFromOverviewPx
|
||||
* Get a map location from a pixel location
|
||||
*
|
||||
* Parameters:
|
||||
* overviewMapPx - {<OpenLayers.Pixel>}
|
||||
*
|
||||
* Return:
|
||||
* {<OpenLayers.LonLat>} Location which is the passed-in overview map
|
||||
* OpenLayers.Pixel, translated into lon/lat by the overview map
|
||||
*/
|
||||
getLonLatFromOverviewPx: function(overviewMapPx) {
|
||||
var size = this.ovmap.size;
|
||||
var res = this.ovmap.getResolution();
|
||||
@@ -585,12 +661,16 @@ OpenLayers.Control.OverviewMap.prototype =
|
||||
},
|
||||
|
||||
/**
|
||||
* @param {OpenLayers.LonLat} lonlat
|
||||
*
|
||||
* @returns An OpenLayers.Pixel which is the passed-in OpenLayers.LonLat,
|
||||
* translated into overview map pixels
|
||||
* @type OpenLayers.Pixel
|
||||
*/
|
||||
* Method: getOverviewPxFromLonLat
|
||||
* Get a pixel location from a map location
|
||||
*
|
||||
* Parameters:
|
||||
* lonlat - {<OpenLayers.LonLat>}
|
||||
*
|
||||
* Return:
|
||||
* {<OpenLayers.Pixel>} Location which is the passed-in OpenLayers.LonLat,
|
||||
* translated into overview map pixels
|
||||
*/
|
||||
getOverviewPxFromLonLat: function(lonlat) {
|
||||
var res = this.ovmap.getResolution();
|
||||
var extent = this.ovmap.getExtent();
|
||||
@@ -603,7 +683,10 @@ OpenLayers.Control.OverviewMap.prototype =
|
||||
return px;
|
||||
},
|
||||
|
||||
/** @final @type String */
|
||||
/**
|
||||
* Constant: CLASS_NAME
|
||||
* {String} Name of this class
|
||||
*/
|
||||
CLASS_NAME: 'OpenLayers.Control.OverviewMap'
|
||||
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user