Files
openlayers/tests/test_Layer.html
euzuro f582775d11 - Removed unnecessary accessors from OpenLayers.Layer: getProjection(),
getMaxExtent(), getMaxResolution(), and getNumZoomLevels(). They were just 
   wrapping around the properties. better to just access the property directly. 
   Needed to update for these removals in many different files. 

- Improved initResolutions() functionality. It is now I believe both thorough
   and complete. The only exception is that we should maybe allow a way for 
   the user to set up resolutions[] array using only minResolution and 
   numZoomLevels instead of only maxResolution and numZoomLevels... but I'm not
   really sure anyone would ever really want to use that. And at any rate, I
   don't know the math for how to do it. I'm sure schuyler or Dr. 5 would.
   Oh. for a summary of how initResolutions works, see:
   http://trac.openlayers.org/wiki/SettingZoomLevels

- Move getResolution(), initResolutions() out of HTTPRequest and into Layer. On 
   thinking this through (and trying to write documentation), I realized that 
   the real, true, GENERIC case for a layer will be using this awesome 
   resolutions[] array that allows for setting number of zoom levels, default 
   max resolutions, special scale arrays, etc. 

- Updated code for getZoomForExtent() to work with resolutions[] array, instead 
   of using the the log 2 equation. 

- Move standard getZoomForExtent() and getExtent() out of Grid and into 
   Layer. Like above, there is no reason for these methods to be found so far
   down in the food chain. They are part of the generic calculations for 
   generic layers, so they belong in Layer. 



git-svn-id: http://svn.openlayers.org/trunk/openlayers@1379 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
2006-08-26 02:51:38 +00:00

164 lines
5.4 KiB
HTML

<html>
<head>
<script src="../lib/OpenLayers.js"></script>
<script type="text/javascript"><!--
var layer;
function test_01_Layer_constructor (t) {
t.plan( 14 );
var options = { chicken: 151, foo: "bar", projection: "none" };
var layer = new OpenLayers.Layer('Test Layer', options);
t.ok( layer instanceof OpenLayers.Layer, "new OpenLayers.Layer returns object" );
t.eq( layer.CLASS_NAME, "OpenLayers.Layer", "CLASS_NAME variable set correctly");
t.eq( layer.name, "Test Layer", "layer.name is correct" );
t.ok( layer.id != null, "Layer is given an id");
t.ok( layer.id.startsWith("Layer_"), "layer id starts correctly");
t.ok( layer.projection, "none", "default layer projection correctly set");
t.ok( ((layer.chicken == 151) && (layer.foo == "bar")), "layer.options correctly set to Layer Object" );
t.ok( ((layer.options["chicken"] == 151) && (layer.options["foo"] == "bar")), "layer.options correctly backed up" );
options.chicken = 552;
t.eq( layer.options["chicken"], 151 , "layer.options correctly made fresh copy" );
t.eq( layer.isBaseLayer, false, "Default layer is not base layer" );
layer = new OpenLayers.Layer('Test Layer');
t.ok( layer instanceof OpenLayers.Layer, "new OpenLayers.Layer returns object" );
t.eq( layer.name, "Test Layer", "layer.name is correct" );
t.ok( layer.projection == null, "default layer projection correctly set");
t.ok( layer.options instanceof Object, "layer.options correctly initialized as a non-null Object" );
}
function test_02_Layer_clone (t) {
t.plan( 6 );
var map = new OpenLayers.Map('map');
var options = { chicken: 151, foo: "bar" };
var layer = new OpenLayers.Layer('Test Layer', options);
map.addLayer(layer);
// randomly assigned property
layer.chocolate = 5;
var clone = layer.clone();
t.ok( clone instanceof OpenLayers.Layer, "new OpenLayers.Layer returns object" );
t.eq( clone.name, "Test Layer", "default clone.name is correct" );
t.ok( ((clone.options["chicken"] == 151) && (clone.options["foo"] == "bar")), "clone.options correctly set" );
t.eq(clone.chocolate, 5, "correctly copied randomly assigned property");
layer.addOptions({chicken:152});
t.eq(clone.options["chicken"], 151, "made a clean copy of options");
t.ok( clone.map == null, "cloned layer has map property set to null")
}
function test_03_Layer_setName (t) {
t.plan( 1 );
layer = new OpenLayers.Layer('Test Layer');
layer.setName("chicken");
t.eq(layer.name, "chicken", "setName() works")
}
function test_04_Layer_addOptions (t) {
t.plan( 4 );
var options = { chicken: 151, foo: "bar" };
var layer = new OpenLayers.Layer('Test Layer', options);
layer.addOptions({bark:55, chicken: 171});
t.eq(layer.bark, 55, "addOptions() assigns new option correctly to Layer");
t.eq(layer.options.bark, 55, "addOptions() adds new option correctly to backup");
t.eq(layer.chicken, 171, "addOptions() overwrites option correctly to Layer");
t.eq(layer.options.chicken, 171, "addOptions() overwrites option correctly to backup");
}
function test_04_Layer_StandardOptionsAccessors (t) {
t.plan( 4 );
var projection = "chicken";
var maxExtent = new OpenLayers.Bounds(50,50,100,100);
var maxResolution = 1.5726;
var numZoomLevels = 11;
var options = { projection: projection,
maxExtent: maxExtent,
maxResolution: maxResolution,
numZoomLevels: numZoomLevels
};
var layer = new OpenLayers.Layer('Test Layer', options);
t.eq(layer.projection, projection, "projection set correctly");
t.ok(layer.maxExtent.equals(maxExtent), "maxExtent set correctly");
t.eq(layer.maxResolution, maxResolution, "maxResolution set correctly");
t.eq(layer.numZoomLevels, numZoomLevels, "numZoomLevels set correctly");
}
function test_05_Layer_visibility(t) {
t.plan(3)
var layer = new OpenLayers.Layer('Test Layer');
t.eq(layer.getVisibility(), true, "default for layer creation is visible");
layer.setVisibility(false);
t.eq(layer.getVisibility(), false, "setVisibility false works");
layer.setVisibility(true);
t.eq(layer.getVisibility(), true, "setVisibility true works");
}
/******
*
*
* HERE IS WHERE SOME TESTS SHOULD BE PUT TO CHECK ON THE LONLAT-PX TRANSLATION
* FUNCTIONS AND RESOLUTION AND GETEXTENT GETZOOMLEVEL, ETC
*
*
*/
function test_99_Layer_destroy (t) {
t.plan( 4 );
var map = new OpenLayers.Map('map');
layer = new OpenLayers.Layer('Test Layer');
map.addLayer(layer);
layer.destroy();
t.eq( layer.name, null, "layer.name is null after destroy" );
t.eq( layer.div, null, "layer.div is null after destroy" );
t.eq( layer.map, null, "layer.map is null after destroy" );
t.eq( layer.options, null, "layer.options is null after destroy" );
}
// -->
</script>
</head>
<body>
<div id="map"></div>
</body>
</html>