Remove the concept of min/max zoom level from Map. Replace it with concept of num zoom levels. Bit of rearrangement in the initResolutions() function in HTTPRequest.js. Adapt all of OL to deal with numZoomLevels instead of min/max. Fix PanZoomBar so that it listens for change of baselayer and redraws itself. fix all tests so they pass. Add zoomLevels.html example for playing around with different methods of setting zoomlevels.
git-svn-id: http://svn.openlayers.org/branches/openlayers/2.0@1302 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
@@ -11,15 +11,15 @@
|
|||||||
<script type="text/javascript">
|
<script type="text/javascript">
|
||||||
<!--
|
<!--
|
||||||
function init(){
|
function init(){
|
||||||
var map = new OpenLayers.Map('map', {'maxResolution': 1.6, maxZoomLevel:20});
|
var mapOptions = { maxResolution: 1.6, numZoomLevels: 21};
|
||||||
|
var map = new OpenLayers.Map('map', mapOptions);
|
||||||
|
|
||||||
var ol_wms = new OpenLayers.Layer.WMS( "OpenLayers WMS",
|
var ol_wms = new OpenLayers.Layer.WMS( "OpenLayers WMS",
|
||||||
"http://labs.metacarta.com/wms/vmap0?", {layers: 'basic'} );
|
"http://labs.metacarta.com/wms/vmap0?", {layers: 'basic'} );
|
||||||
|
|
||||||
var ww = new OpenLayers.Layer.WorldWind( "Urban",
|
var ww = new OpenLayers.Layer.WorldWind( "Urban",
|
||||||
"http://worldwind25.arc.nasa.gov/tile/tile.aspx?", .8, 9,
|
"http://worldwind25.arc.nasa.gov/tile/tile.aspx?", .8, 9,
|
||||||
{T:"104"});
|
{T:"104"}, { tileSize: new OpenLayers.Size(512,512) });
|
||||||
ww.setTileSize(new OpenLayers.Size(512,512));
|
|
||||||
|
|
||||||
|
|
||||||
map.addLayers([ol_wms, ww]);
|
map.addLayers([ol_wms, ww]);
|
||||||
|
|||||||
51
examples/zoomLevels.html
Normal file
51
examples/zoomLevels.html
Normal file
@@ -0,0 +1,51 @@
|
|||||||
|
<html xmlns="http://www.w3.org/1999/xhtml">
|
||||||
|
<head>
|
||||||
|
<meta http-equiv="imagetoolbar" content="no"> <!--ie image gizmo OFF!-->
|
||||||
|
<style type="text/css">
|
||||||
|
#map {
|
||||||
|
width: 800px;
|
||||||
|
height: 475px;
|
||||||
|
border: 1px solid black;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
<script src="../lib/OpenLayers.js"></script>
|
||||||
|
<script type="text/javascript">
|
||||||
|
<!--
|
||||||
|
var lon = 50;
|
||||||
|
var lat = 0;
|
||||||
|
var zoom = 0;
|
||||||
|
var map, layer;
|
||||||
|
|
||||||
|
function init(){
|
||||||
|
|
||||||
|
var options = {
|
||||||
|
// resolutions: [1.40625,0.703125,0.3515625,0.17578125,0.087890625,0.0439453125,0.02197265625,0.010986328125,0.0054931640625,0.00274658203125,0.00137329101],
|
||||||
|
// scales: [50000000, 10000000],
|
||||||
|
// maxResolution: 0.17578125,
|
||||||
|
// minResolution: 0.0439453125,
|
||||||
|
// maxScale: 10000000,
|
||||||
|
// minScale: 50000000,
|
||||||
|
maxResolution: "auto",
|
||||||
|
maxExtent: new OpenLayers.Bounds(4, -90, 90, 90),
|
||||||
|
controls: []
|
||||||
|
};
|
||||||
|
|
||||||
|
map = new OpenLayers.Map( $('map') , options);
|
||||||
|
|
||||||
|
map.addControl(new OpenLayers.Control.PanZoomBar());
|
||||||
|
|
||||||
|
layer = new OpenLayers.Layer.WMS( "OpenLayers WMS",
|
||||||
|
"http://labs.metacarta.com/wms/vmap0", {layers: 'basic'});
|
||||||
|
map.addLayer(layer);
|
||||||
|
|
||||||
|
|
||||||
|
map.setCenter(new OpenLayers.LonLat(lon, lat), zoom);
|
||||||
|
}
|
||||||
|
|
||||||
|
// -->
|
||||||
|
</script>
|
||||||
|
</head>
|
||||||
|
<body onload="init()">
|
||||||
|
<div id="map"></div>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
@@ -28,9 +28,28 @@ OpenLayers.Control.PanZoomBar.prototype =
|
|||||||
|
|
||||||
// put code here to catch "changebaselayer" event from map, because
|
// put code here to catch "changebaselayer" event from map, because
|
||||||
// we are going to have to redraw this thing each time, because
|
// we are going to have to redraw this thing each time, because
|
||||||
// maxZoom will/might change.
|
// numZoomLevels will/might change.
|
||||||
},
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {OpenLayers.Map} map
|
||||||
|
*/
|
||||||
|
setMap: function(map) {
|
||||||
|
OpenLayers.Control.PanZoom.prototype.setMap.apply(this, arguments);
|
||||||
|
|
||||||
|
this.map.events.register("changebaselayer", this, this.redraw);
|
||||||
|
},
|
||||||
|
|
||||||
|
/** clear the div and start over.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
redraw: function() {
|
||||||
|
if (this.div != null) {
|
||||||
|
this.div.innerHTML = "";
|
||||||
|
}
|
||||||
|
this.draw();
|
||||||
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {OpenLayers.Pixel} px
|
* @param {OpenLayers.Pixel} px
|
||||||
*/
|
*/
|
||||||
@@ -65,7 +84,7 @@ OpenLayers.Control.PanZoomBar.prototype =
|
|||||||
var id = "OpenLayers_Control_PanZoomBar_Slider" + this.map.id;
|
var id = "OpenLayers_Control_PanZoomBar_Slider" + this.map.id;
|
||||||
var slider = OpenLayers.Util.createAlphaImageDiv(id,
|
var slider = OpenLayers.Util.createAlphaImageDiv(id,
|
||||||
centered.add(-1,
|
centered.add(-1,
|
||||||
(this.map.getMaxZoomLevel())*this.zoomStopHeight),
|
(this.map.getNumZoomLevels()-1) * this.zoomStopHeight),
|
||||||
new OpenLayers.Size(20,9),
|
new OpenLayers.Size(20,9),
|
||||||
imgLocation+"slider.png",
|
imgLocation+"slider.png",
|
||||||
"absolute");
|
"absolute");
|
||||||
@@ -79,7 +98,7 @@ OpenLayers.Control.PanZoomBar.prototype =
|
|||||||
this.sliderEvents.register("click", this, this.doubleClick);
|
this.sliderEvents.register("click", this, this.doubleClick);
|
||||||
|
|
||||||
sz = new OpenLayers.Size();
|
sz = new OpenLayers.Size();
|
||||||
sz.h = this.zoomStopHeight*(this.map.getMaxZoomLevel()+1);
|
sz.h = this.zoomStopHeight * this.map.getNumZoomLevels();
|
||||||
sz.w = this.zoomStopWidth;
|
sz.w = this.zoomStopWidth;
|
||||||
var div = null
|
var div = null
|
||||||
|
|
||||||
@@ -115,7 +134,7 @@ OpenLayers.Control.PanZoomBar.prototype =
|
|||||||
this.map.events.register("zoomend", this, this.moveZoomBar);
|
this.map.events.register("zoomend", this, this.moveZoomBar);
|
||||||
|
|
||||||
centered = centered.add(0,
|
centered = centered.add(0,
|
||||||
this.zoomStopHeight*(this.map.getMaxZoomLevel()+1));
|
this.zoomStopHeight * this.map.getNumZoomLevels());
|
||||||
return centered;
|
return centered;
|
||||||
},
|
},
|
||||||
/*
|
/*
|
||||||
@@ -136,7 +155,7 @@ OpenLayers.Control.PanZoomBar.prototype =
|
|||||||
var y = evt.xy.y;
|
var y = evt.xy.y;
|
||||||
var top = Position.page(evt.object)[1];
|
var top = Position.page(evt.object)[1];
|
||||||
var levels = Math.floor((y - top)/this.zoomStopHeight);
|
var levels = Math.floor((y - top)/this.zoomStopHeight);
|
||||||
this.map.zoomTo(this.map.getMaxZoomLevel() - levels);
|
this.map.zoomTo((this.map.getNumZoomLevels() -1) - levels);
|
||||||
Event.stop(evt);
|
Event.stop(evt);
|
||||||
},
|
},
|
||||||
|
|
||||||
@@ -198,8 +217,8 @@ OpenLayers.Control.PanZoomBar.prototype =
|
|||||||
*/
|
*/
|
||||||
moveZoomBar:function() {
|
moveZoomBar:function() {
|
||||||
var newTop =
|
var newTop =
|
||||||
(this.map.getMaxZoomLevel() - this.map.getZoom()) * this.zoomStopHeight
|
((this.map.getNumZoomLevels()-1) - this.map.getZoom()) *
|
||||||
+ this.startTop + 1;
|
this.zoomStopHeight + this.startTop + 1;
|
||||||
this.slider.style.top = newTop + "px";
|
this.slider.style.top = newTop + "px";
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|||||||
@@ -51,10 +51,7 @@ OpenLayers.Layer.prototype = {
|
|||||||
maxResolution: null,
|
maxResolution: null,
|
||||||
|
|
||||||
/** @type int */
|
/** @type int */
|
||||||
minZoomLevel: null,
|
numZoomLevels: null,
|
||||||
|
|
||||||
/** @type int */
|
|
||||||
maxZoomLevel: null,
|
|
||||||
|
|
||||||
/** @type float */
|
/** @type float */
|
||||||
minScale: null,
|
minScale: null,
|
||||||
@@ -178,12 +175,12 @@ OpenLayers.Layer.prototype = {
|
|||||||
this.map = map;
|
this.map = map;
|
||||||
|
|
||||||
var properties = new Array(
|
var properties = new Array(
|
||||||
'projection', 'minExtent', 'maxExtent',
|
'projection', 'units',
|
||||||
'minScale', 'maxScale',
|
'scales', 'resolutions',
|
||||||
|
'maxScale', 'minScale',
|
||||||
'maxResolution', 'minResolution',
|
'maxResolution', 'minResolution',
|
||||||
'minZoomLevel', 'maxZoomLevel', 'units',
|
'minExtent', 'maxExtent',
|
||||||
'scales', 'resolutions'
|
'numZoomLevels'
|
||||||
|
|
||||||
);
|
);
|
||||||
for(var i=0; i < properties.length; i++) {
|
for(var i=0; i < properties.length; i++) {
|
||||||
if (this[properties[i]] == null) {
|
if (this[properties[i]] == null) {
|
||||||
@@ -251,19 +248,11 @@ OpenLayers.Layer.prototype = {
|
|||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @returns The minimum zoom level that can be reached in this layer
|
* @returns The total number of zoom levels this layer can reach
|
||||||
* @type int
|
* @type int
|
||||||
*/
|
*/
|
||||||
getMinZoomLevel: function() {
|
getNumZoomLevels: function() {
|
||||||
return this.minZoomLevel;
|
return this.numZoomLevels;
|
||||||
},
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @returns The maximum zoom level that can be reached in this layer
|
|
||||||
* @type int
|
|
||||||
*/
|
|
||||||
getMaxZoomLevel: function() {
|
|
||||||
return this.maxZoomLevel;
|
|
||||||
},
|
},
|
||||||
|
|
||||||
/********************************************************/
|
/********************************************************/
|
||||||
|
|||||||
@@ -49,10 +49,7 @@ OpenLayers.Layer.Google.prototype =
|
|||||||
// OPTIONS
|
// OPTIONS
|
||||||
|
|
||||||
/** @type int */
|
/** @type int */
|
||||||
minZoomLevel: -1,
|
numZoomLevels: 16,
|
||||||
|
|
||||||
/** @type int */
|
|
||||||
maxZoomLevel: 16,
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -444,12 +444,9 @@ OpenLayers.Layer.Grid.prototype =
|
|||||||
|
|
||||||
var zoom = Math.floor( (Math.log(maxRes/degPerPixel)) / Math.log(2) );
|
var zoom = Math.floor( (Math.log(maxRes/degPerPixel)) / Math.log(2) );
|
||||||
|
|
||||||
var maxZoomLevel = this.map.getMaxZoomLevel();
|
|
||||||
var minZoomLevel = this.map.getMinZoomLevel();
|
|
||||||
|
|
||||||
//make sure zoom is within bounds
|
//make sure zoom is within bounds
|
||||||
zoom = Math.min( Math.max(zoom, minZoomLevel),
|
zoom = Math.min( Math.max(zoom, 0),
|
||||||
maxZoomLevel );
|
this.getNumZoomLevels() - 1);
|
||||||
|
|
||||||
return zoom;
|
return zoom;
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -36,10 +36,17 @@ OpenLayers.Layer.HTTPRequest.prototype =
|
|||||||
this.params = Object.extend( new Object(), params);
|
this.params = Object.extend( new Object(), params);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
/** When the layer is added to the map, once it has taken all the
|
||||||
|
* relevant properties from the map (in Layer.setMap()), we will
|
||||||
|
* make the call to initialize the layer's resolutions array.
|
||||||
|
*
|
||||||
|
* @param {OpenLayers.Map} map
|
||||||
|
*/
|
||||||
setMap: function(map) {
|
setMap: function(map) {
|
||||||
OpenLayers.Layer.prototype.setMap.apply(this, arguments);
|
OpenLayers.Layer.prototype.setMap.apply(this, arguments);
|
||||||
this.initResolutions();
|
this.initResolutions();
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
@@ -131,31 +138,78 @@ OpenLayers.Layer.HTTPRequest.prototype =
|
|||||||
return requestString;
|
return requestString;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
/** This method's responsibility is to set up the 'resolutions' array
|
||||||
|
* for the layer -- this array is what the layer will use to interface
|
||||||
|
* between the zoom levels of the map and the resolution display of the
|
||||||
|
* layer.
|
||||||
|
*
|
||||||
|
* The user has several options that determine how the array is set up.
|
||||||
|
*
|
||||||
|
* For a detailed explanation, see the following wiki from the
|
||||||
|
* openlayers.org homepage:
|
||||||
|
*
|
||||||
|
* http://trac.openlayers.org/wiki/SettingZoomLevels
|
||||||
|
*
|
||||||
|
* @private
|
||||||
|
*/
|
||||||
initResolutions: function() {
|
initResolutions: function() {
|
||||||
if (this.scales != null) {
|
|
||||||
this.resolutions = new Array();
|
if ((this.scales != null) || (this.resolutions != null)) {
|
||||||
for(var i = 0; i < this.scales.length; i++)
|
//preset levels
|
||||||
this.resolutions[i] = OpenLayers.Util.getResolutionFromScale(this.scales[i], this.units);
|
if (this.scales != null) {
|
||||||
this.maxZoomLevel = this.resolutions.length;
|
this.resolutions = new Array();
|
||||||
} else if (this.resolutions != null) {
|
for(var i = 0; i < this.scales.length; i++) {
|
||||||
this.maxZoomLevel = this.resolutions.length;
|
this.resolutions[i] =
|
||||||
|
OpenLayers.Util.getResolutionFromScale(this.scales[i],
|
||||||
|
this.units);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
this.numZoomLevels = this.resolutions.length;
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
//maxResolution and numZoomLevels
|
||||||
|
|
||||||
this.resolutions = new Array();
|
this.resolutions = new Array();
|
||||||
if (this.minScale)
|
|
||||||
this.maxResolution = OpenLayers.Util.getResolutionFromScale(this.minScale, this.units);
|
// determine maxResolution
|
||||||
var maxRes = this.getMaxResolution();
|
if (this.minScale) {
|
||||||
if (this.maxScale) {
|
this.maxResolution =
|
||||||
/* This will cause this.map.getMaxZoomLevel() to be set the next time
|
OpenLayers.Util.getResolutionFromScale(this.minScale,
|
||||||
* it is called, which means that the next portion here will succeed. */
|
this.units);
|
||||||
var minRes = OpenLayers.Util.getResolutionFromScale(this.maxScale);
|
} else if (this.maxResolution == "auto") {
|
||||||
this.maxZoomLevel = Math.floor(Math.log(maxRes/minRes) / Math.log(2));
|
var maxExtent = this.getMaxExtent();
|
||||||
}
|
var viewSize = this.map.getSize();
|
||||||
for (var i=this.getMinZoomLevel(); i <= this.getMaxZoomLevel(); i++) {
|
var wRes = maxExtent.getWidth() / viewSize.w;
|
||||||
this.resolutions.push(maxRes / Math.pow(2, i));
|
var hRes = maxExtent.getHeight()/ viewSize.h;
|
||||||
|
this.maxResolution = Math.max(wRes, hRes);
|
||||||
|
}
|
||||||
|
|
||||||
|
// determine numZoomLevels
|
||||||
|
|
||||||
|
if (this.maxScale != null) {
|
||||||
|
this.minResolution =
|
||||||
|
OpenLayers.Util.getResolutionFromScale(this.maxScale);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.minResolution != null) {
|
||||||
|
var ratio = this.maxResolution / this.minResolution;
|
||||||
|
this.numZoomLevels =
|
||||||
|
Math.floor(Math.log(ratio) / Math.log(2)) + 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
// now we have numZoomLevels and maxResolution,
|
||||||
|
// we can populate the resolutions array
|
||||||
|
for (var i=0; i < this.numZoomLevels; i++) {
|
||||||
|
this.resolutions.push(this.maxResolution / Math.pow(2, i));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @returns The currently selected resolution of the map, taken from the
|
||||||
|
* resolutions array, indexed by current zoom level.
|
||||||
|
* @type float
|
||||||
|
*/
|
||||||
getResolution: function() {
|
getResolution: function() {
|
||||||
var zoom = this.map.getZoom();
|
var zoom = this.map.getZoom();
|
||||||
|
|
||||||
|
|||||||
@@ -14,6 +14,9 @@ OpenLayers.Layer.VirtualEarth.prototype =
|
|||||||
/** @type VEMap */
|
/** @type VEMap */
|
||||||
vemap: null,
|
vemap: null,
|
||||||
|
|
||||||
|
/** @type int */
|
||||||
|
numZoomLevels: 17,
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @constructor
|
* @constructor
|
||||||
*
|
*
|
||||||
@@ -211,12 +214,9 @@ OpenLayers.Layer.VirtualEarth.prototype =
|
|||||||
|
|
||||||
var zoom = Math.floor( (Math.log(maxRes/degPerPixel)) / Math.log(2) );
|
var zoom = Math.floor( (Math.log(maxRes/degPerPixel)) / Math.log(2) );
|
||||||
|
|
||||||
var maxZoomLevel = this.map.getMaxZoomLevel();
|
|
||||||
var minZoomLevel = this.map.getMinZoomLevel();
|
|
||||||
|
|
||||||
//make sure zoom is within bounds
|
//make sure zoom is within bounds
|
||||||
zoom = Math.min( Math.max(zoom, minZoomLevel),
|
zoom = Math.min( Math.max(zoom, 0),
|
||||||
maxZoomLevel );
|
this.numZoomLevels-1);
|
||||||
|
|
||||||
return zoom;
|
return zoom;
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -78,33 +78,38 @@ OpenLayers.Map.prototype = {
|
|||||||
|
|
||||||
// Options
|
// Options
|
||||||
|
|
||||||
|
/** @type OpenLayers.Size */
|
||||||
|
tileSize: null,
|
||||||
|
|
||||||
/** @type String */
|
/** @type String */
|
||||||
projection: "EPSG:4326",
|
projection: "EPSG:4326",
|
||||||
|
|
||||||
/** @type OpenLayers.Bounds */
|
/** @type String */
|
||||||
maxExtent: null,
|
units: 'degrees',
|
||||||
|
|
||||||
/** default max is 360 deg / 256 px, which corresponds to
|
/** default max is 360 deg / 256 px, which corresponds to
|
||||||
* zoom level 0 on gmaps
|
* zoom level 0 on gmaps
|
||||||
*
|
*
|
||||||
* @type float */
|
* @type float */
|
||||||
maxResolution: 1.40625,
|
maxResolution: 1.40625,
|
||||||
|
|
||||||
/** @type int */
|
/** @type float */
|
||||||
minZoomLevel: 0,
|
minResolution: null,
|
||||||
|
|
||||||
/** @type int */
|
|
||||||
maxZoomLevel: 16,
|
|
||||||
|
|
||||||
/** @type OpenLayers.Size */
|
/** @type float */
|
||||||
tileSize: null,
|
maxScale: null,
|
||||||
|
|
||||||
/** @type String */
|
/** @type float */
|
||||||
units: 'degrees',
|
|
||||||
|
|
||||||
/** @type Float */
|
|
||||||
minScale: null,
|
minScale: null,
|
||||||
|
|
||||||
|
/** @type OpenLayers.Bounds */
|
||||||
|
maxExtent: null,
|
||||||
|
|
||||||
|
/** @type OpenLayers.Bounds */
|
||||||
|
minExtent: null,
|
||||||
|
|
||||||
|
/** @type int */
|
||||||
|
numZoomLevels: 16,
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -207,16 +212,6 @@ OpenLayers.Map.prototype = {
|
|||||||
// now add the options declared by the user
|
// now add the options declared by the user
|
||||||
// (these will override defaults)
|
// (these will override defaults)
|
||||||
Object.extend(this, options);
|
Object.extend(this, options);
|
||||||
|
|
||||||
// if maxResolution is specified as "auto", calculate it
|
|
||||||
// based on the maxExtent and the viewSize
|
|
||||||
//
|
|
||||||
if (this.maxResolution == "auto" || this.maxResolution == null) {
|
|
||||||
var maxExtent = this.getMaxExtent();
|
|
||||||
var viewSize = this.getSize();
|
|
||||||
this.maxResolution = Math.max(maxExtent.getWidth() / viewSize.w,
|
|
||||||
maxExtent.getHeight() / viewSize.h );
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -647,8 +642,8 @@ OpenLayers.Map.prototype = {
|
|||||||
*/
|
*/
|
||||||
isValidZoomLevel: function(zoomLevel) {
|
isValidZoomLevel: function(zoomLevel) {
|
||||||
return ( (zoomLevel != null) &&
|
return ( (zoomLevel != null) &&
|
||||||
(zoomLevel >= this.getMinZoomLevel()) &&
|
(zoomLevel >= 0) &&
|
||||||
(zoomLevel <= this.getMaxZoomLevel()) );
|
(zoomLevel < this.getNumZoomLevels()) );
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -684,15 +679,9 @@ OpenLayers.Map.prototype = {
|
|||||||
*/
|
*/
|
||||||
getProjection: function() {
|
getProjection: function() {
|
||||||
var projection = null;
|
var projection = null;
|
||||||
|
|
||||||
if (this.baseLayer != null) {
|
if (this.baseLayer != null) {
|
||||||
projection = this.baseLayer.getProjection();
|
projection = this.baseLayer.getProjection();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (projection == null) {
|
|
||||||
projection = this.projection;
|
|
||||||
}
|
|
||||||
|
|
||||||
return projection;
|
return projection;
|
||||||
},
|
},
|
||||||
|
|
||||||
@@ -702,15 +691,9 @@ OpenLayers.Map.prototype = {
|
|||||||
*/
|
*/
|
||||||
getMaxResolution: function() {
|
getMaxResolution: function() {
|
||||||
var maxResolution = null;
|
var maxResolution = null;
|
||||||
|
|
||||||
if (this.baseLayer != null) {
|
if (this.baseLayer != null) {
|
||||||
maxResolution = this.baseLayer.getMaxResolution();
|
maxResolution = this.baseLayer.getMaxResolution();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (maxResolution == null) {
|
|
||||||
maxResolution = this.maxResolution;
|
|
||||||
}
|
|
||||||
|
|
||||||
return maxResolution;
|
return maxResolution;
|
||||||
},
|
},
|
||||||
|
|
||||||
@@ -719,55 +702,25 @@ OpenLayers.Map.prototype = {
|
|||||||
*/
|
*/
|
||||||
getMaxExtent: function () {
|
getMaxExtent: function () {
|
||||||
var maxExtent = null;
|
var maxExtent = null;
|
||||||
|
|
||||||
if (this.baseLayer != null) {
|
if (this.baseLayer != null) {
|
||||||
maxExtent = this.baseLayer.getMaxExtent();
|
maxExtent = this.baseLayer.getMaxExtent();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (maxExtent == null) {
|
|
||||||
maxExtent = this.maxExtent;
|
|
||||||
}
|
|
||||||
|
|
||||||
return maxExtent;
|
return maxExtent;
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @returns The maximum zoom level that can be reached in the map
|
* @returns The total number of zoom levels that can be displayed by the
|
||||||
|
* current baseLayer.
|
||||||
* @type int
|
* @type int
|
||||||
*/
|
*/
|
||||||
getMaxZoomLevel: function() {
|
getNumZoomLevels: function() {
|
||||||
var maxZoomLevel = null;
|
var numZoomLevels = null;
|
||||||
|
|
||||||
if (this.baseLayer != null) {
|
if (this.baseLayer != null) {
|
||||||
maxZoomLevel = this.baseLayer.getMaxZoomLevel();
|
numZoomLevels = this.baseLayer.getNumZoomLevels();
|
||||||
}
|
}
|
||||||
|
return numZoomLevels;
|
||||||
if (maxZoomLevel == null) {
|
|
||||||
maxZoomLevel = this.maxZoomLevel;
|
|
||||||
}
|
|
||||||
|
|
||||||
return maxZoomLevel;
|
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
|
||||||
* @returns The minimum zoom level that can be reached in the map
|
|
||||||
* @type int
|
|
||||||
*/
|
|
||||||
getMinZoomLevel: function() {
|
|
||||||
var minZoomLevel = null;
|
|
||||||
|
|
||||||
if (this.baseLayer != null) {
|
|
||||||
minZoomLevel = this.baseLayer.getMinZoomLevel();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (minZoomLevel == null) {
|
|
||||||
minZoomLevel = this.minZoomLevel;
|
|
||||||
}
|
|
||||||
|
|
||||||
return minZoomLevel;
|
|
||||||
},
|
|
||||||
|
|
||||||
|
|
||||||
/********************************************************/
|
/********************************************************/
|
||||||
/* */
|
/* */
|
||||||
/* Baselayer Functions */
|
/* Baselayer Functions */
|
||||||
@@ -787,7 +740,6 @@ OpenLayers.Map.prototype = {
|
|||||||
*/
|
*/
|
||||||
getExtent: function () {
|
getExtent: function () {
|
||||||
var extent = null;
|
var extent = null;
|
||||||
|
|
||||||
if (this.baseLayer != null) {
|
if (this.baseLayer != null) {
|
||||||
extent = this.baseLayer.getExtent();
|
extent = this.baseLayer.getExtent();
|
||||||
}
|
}
|
||||||
@@ -801,7 +753,6 @@ OpenLayers.Map.prototype = {
|
|||||||
*/
|
*/
|
||||||
getResolution: function () {
|
getResolution: function () {
|
||||||
var resolution = null;
|
var resolution = null;
|
||||||
|
|
||||||
if (this.baseLayer != null) {
|
if (this.baseLayer != null) {
|
||||||
resolution = this.baseLayer.getResolution();
|
resolution = this.baseLayer.getResolution();
|
||||||
}
|
}
|
||||||
@@ -815,7 +766,6 @@ OpenLayers.Map.prototype = {
|
|||||||
*/
|
*/
|
||||||
getScale: function () {
|
getScale: function () {
|
||||||
var scale = null;
|
var scale = null;
|
||||||
|
|
||||||
if (this.baseLayer != null) {
|
if (this.baseLayer != null) {
|
||||||
var res = this.getResolution();
|
var res = this.getResolution();
|
||||||
var units = this.baseLayer.units;
|
var units = this.baseLayer.units;
|
||||||
@@ -835,7 +785,6 @@ OpenLayers.Map.prototype = {
|
|||||||
*/
|
*/
|
||||||
getZoomForExtent: function (bounds) {
|
getZoomForExtent: function (bounds) {
|
||||||
zoom = null;
|
zoom = null;
|
||||||
|
|
||||||
if (this.baseLayer != null) {
|
if (this.baseLayer != null) {
|
||||||
zoom = this.baseLayer.getZoomForExtent(bounds);
|
zoom = this.baseLayer.getZoomForExtent(bounds);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -89,19 +89,17 @@
|
|||||||
|
|
||||||
function test_04_Layer_StandardOptionsAccessors (t) {
|
function test_04_Layer_StandardOptionsAccessors (t) {
|
||||||
|
|
||||||
t.plan( 5 );
|
t.plan( 4 );
|
||||||
|
|
||||||
var projection = "chicken";
|
var projection = "chicken";
|
||||||
var maxExtent = new OpenLayers.Bounds(50,50,100,100);
|
var maxExtent = new OpenLayers.Bounds(50,50,100,100);
|
||||||
var maxResolution = 1.5726;
|
var maxResolution = 1.5726;
|
||||||
var minZoomLevel = 5;
|
var numZoomLevels = 11;
|
||||||
var maxZoomLevel = 15;
|
|
||||||
|
|
||||||
var options = { projection: projection,
|
var options = { projection: projection,
|
||||||
maxExtent: maxExtent,
|
maxExtent: maxExtent,
|
||||||
maxResolution: maxResolution,
|
maxResolution: maxResolution,
|
||||||
minZoomLevel: minZoomLevel,
|
numZoomLevels: numZoomLevels,
|
||||||
maxZoomLevel: maxZoomLevel
|
|
||||||
};
|
};
|
||||||
|
|
||||||
var layer = new OpenLayers.Layer('Test Layer', options);
|
var layer = new OpenLayers.Layer('Test Layer', options);
|
||||||
@@ -109,8 +107,7 @@
|
|||||||
t.eq(layer.getProjection(), projection, "getProjection() works");
|
t.eq(layer.getProjection(), projection, "getProjection() works");
|
||||||
t.ok(layer.getMaxExtent().equals(maxExtent), "getMaxExtent() works");
|
t.ok(layer.getMaxExtent().equals(maxExtent), "getMaxExtent() works");
|
||||||
t.eq(layer.getMaxResolution(), maxResolution, "getMaxResolution() works");
|
t.eq(layer.getMaxResolution(), maxResolution, "getMaxResolution() works");
|
||||||
t.eq(layer.getMinZoomLevel(), minZoomLevel, "getMinZoomLevel() works");
|
t.eq(layer.getNumZoomLevels(), numZoomLevels, "getNumZoomLevels() works");
|
||||||
t.eq(layer.getMaxZoomLevel(), maxZoomLevel, "getMaxZoomLevel() works");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function test_05_Layer_visibility(t) {
|
function test_05_Layer_visibility(t) {
|
||||||
|
|||||||
@@ -27,7 +27,7 @@
|
|||||||
t.ok( map.controls instanceof Array, "map.controls is an Array" );
|
t.ok( map.controls instanceof Array, "map.controls is an Array" );
|
||||||
t.ok( map.events instanceof OpenLayers.Events, "map.events is an OpenLayers.Events" );
|
t.ok( map.events instanceof OpenLayers.Events, "map.events is an OpenLayers.Events" );
|
||||||
t.ok( map.getMaxExtent() instanceof OpenLayers.Bounds, "map.maxExtent is an OpenLayers.Bounds" );
|
t.ok( map.getMaxExtent() instanceof OpenLayers.Bounds, "map.maxExtent is an OpenLayers.Bounds" );
|
||||||
t.ok( map.getMaxZoomLevel() > 0, "map.maxZoomLevel is set" );
|
t.ok( map.getNumZoomLevels() > 0, "map has a default numZoomLevels" );
|
||||||
}
|
}
|
||||||
function test_02_Map_center(t) {
|
function test_02_Map_center(t) {
|
||||||
t.plan(3);
|
t.plan(3);
|
||||||
@@ -63,8 +63,8 @@
|
|||||||
}
|
}
|
||||||
function test_04_Map_options(t) {
|
function test_04_Map_options(t) {
|
||||||
t.plan(2);
|
t.plan(2);
|
||||||
map = new OpenLayers.Map($('map'), {maxZoomLevel: 5, maxResolution: 3.14159});
|
map = new OpenLayers.Map($('map'), {numZoomLevels: 6, maxResolution: 3.14159});
|
||||||
t.eq( map.maxZoomLevel, 5, "map.maxZoomLevel set correctly via options hashtable" );
|
t.eq( map.numZoomLevels, 6, "map.numZoomLevels set correctly via options hashtable" );
|
||||||
t.eq( map.maxResolution, 3.14159, "map.maxResolution set correctly via options hashtable" );
|
t.eq( map.maxResolution, 3.14159, "map.maxResolution set correctly via options hashtable" );
|
||||||
}
|
}
|
||||||
function test_05_Map_center(t) {
|
function test_05_Map_center(t) {
|
||||||
@@ -151,14 +151,6 @@
|
|||||||
}
|
}
|
||||||
t.ok(!found, "popup.div successfully removed from the map's viewPort");
|
t.ok(!found, "popup.div successfully removed from the map's viewPort");
|
||||||
}
|
}
|
||||||
function test_10_Map_auto_res(t) {
|
|
||||||
t.plan(2);
|
|
||||||
map = new OpenLayers.Map($('map'), {maxZoomLevel: 5, maxResolution: 'auto'});
|
|
||||||
t.eq( map.maxResolution, 1/3, "map.maxResolution set correctly via auto" );
|
|
||||||
map = new OpenLayers.Map($('map'), {maxZoomLevel: 5, maxResolution: null});
|
|
||||||
t.eq( map.maxResolution, 1/3, "map.maxResolution set correctly via null" );
|
|
||||||
}
|
|
||||||
|
|
||||||
/*** THIS IS A GOOD TEST, BUT IT SHOULD BE MOVED TO WMS.
|
/*** THIS IS A GOOD TEST, BUT IT SHOULD BE MOVED TO WMS.
|
||||||
* Also, it won't work until we figure out the viewSize bug
|
* Also, it won't work until we figure out the viewSize bug
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user