Deprecate the theme map option, p=ahocevar, r=me (closes #2619)

git-svn-id: http://svn.openlayers.org/trunk/openlayers@10372 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
bartvde
2010-06-04 19:24:10 +00:00
parent 9bd7f02dbb
commit 744ee039bd
2 changed files with 10 additions and 101 deletions

View File

@@ -355,12 +355,13 @@ OpenLayers.Map = OpenLayers.Class({
/** /**
* APIProperty: theme * APIProperty: theme
* {String} Relative path to a CSS file from which to load theme styles. * {String} *Deprecated* Relative path to a CSS file from which to load
* Specify null in the map options (e.g. {theme: null}) if you * theme styles. Add a CSS resource in the HTML of your map page
* want to get cascading style declarations - by putting links to * instead, e.g.:
* stylesheets or style declarations directly in your page. * (code)
* <link rel="stylesheet" href="../theme/default/style.css" type="text/css" />
* (end)
*/ */
theme: null,
/** /**
* APIProperty: displayProjection * APIProperty: displayProjection
@@ -480,9 +481,6 @@ OpenLayers.Map = OpenLayers.Class({
this.paddingForPopups = new OpenLayers.Bounds(15, 15, 15, 15); this.paddingForPopups = new OpenLayers.Bounds(15, 15, 15, 15);
this.theme = OpenLayers._getScriptLocation() +
'theme/default/style.css';
// now override default options // now override default options
OpenLayers.Util.extend(this, options); OpenLayers.Util.extend(this, options);
@@ -545,29 +543,6 @@ OpenLayers.Map = OpenLayers.Class({
this.updateSizeDestroy); this.updateSizeDestroy);
} }
// only append link stylesheet if the theme property is set
if(this.theme) {
// check existing links for equivalent url
var addNode = true;
var nodes = document.getElementsByTagName('link');
for(var i=0, len=nodes.length; i<len; ++i) {
if(OpenLayers.Util.isEquivalentUrl(nodes.item(i).href,
this.theme)) {
addNode = false;
break;
}
}
// only add a new node if one with an equivalent url hasn't already
// been added
if(addNode) {
var cssNode = document.createElement('link');
cssNode.setAttribute('rel', 'stylesheet');
cssNode.setAttribute('type', 'text/css');
cssNode.setAttribute('href', this.theme);
document.getElementsByTagName('head')[0].appendChild(cssNode);
}
}
if (this.controls == null) { if (this.controls == null) {
if (OpenLayers.Control != null) { // running full or lite? if (OpenLayers.Control != null) { // running full or lite?
this.controls = [ new OpenLayers.Control.Navigation(), this.controls = [ new OpenLayers.Control.Navigation(),

View File

@@ -83,9 +83,9 @@
function test_Map_setOptions(t) { function test_Map_setOptions(t) {
t.plan(2); t.plan(2);
map = new OpenLayers.Map('map', {maxExtent: new OpenLayers.Bounds(100, 200, 300, 400)}); map = new OpenLayers.Map('map', {maxExtent: new OpenLayers.Bounds(100, 200, 300, 400)});
map.setOptions({theme: 'foo'}); map.setOptions({projection: 'EPSG:900913'});
t.eq(map.theme, 'foo', "theme is correctly set by setOptions"); t.eq(map.projection, 'EPSG:900913', "projection is correctly set by setOptions");
t.ok(map.maxExtent.equals(new OpenLayers.Bounds(100, 200, 300, 400)), t.ok(map.maxExtent.equals(new OpenLayers.Bounds(100, 200, 300, 400)),
"maxExtent is correct after calling setOptions"); "maxExtent is correct after calling setOptions");
@@ -128,10 +128,10 @@
function test_Map_options(t) { function test_Map_options(t) {
t.plan(3); t.plan(3);
map = new OpenLayers.Map('map', {numZoomLevels: 6, maxResolution: 3.14159, theme: 'foo'}); map = new OpenLayers.Map('map', {numZoomLevels: 6, maxResolution: 3.14159, projection: 'EPSG:900913'});
t.eq( map.numZoomLevels, 6, "map.numZoomLevels 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" );
t.eq( map.theme, 'foo', "map theme set correctly." ); t.eq( map.projection, 'EPSG:900913', "map projection set correctly." );
map.destroy(); map.destroy();
} }
@@ -855,72 +855,6 @@
map.destroy(); map.destroy();
} }
function test_Map_defaultTheme(t) {
t.plan(5);
var links = document.getElementsByTagName('link');
map = new OpenLayers.Map('map');
var gotNodes = 0;
var themeNode = null;
for(var i=0; i<links.length; ++i) {
if(OpenLayers.Util.isEquivalentUrl(map.theme, links.item(i).href)) {
gotNodes += 1;
themeNode = links.item(i);
}
}
t.eq(gotNodes, 1, "by default, a single link node is added to document");
t.ok(themeNode != null, "a link node with the theme href was added");
t.eq(themeNode.rel, "stylesheet", "node added has rel set to stylesheet");
t.eq(themeNode.type, "text/css", "node added has type set to text/css");
// reconstruct the map to prove that another link is not added
map = new OpenLayers.Map('map');
t.eq(links.length, document.getElementsByTagName('link').length,
"calling the map constructor twice with the same theme doesn't add duplicate link nodes");
map.destroy();
}
function test_Map_customTheme(t) {
t.plan(5);
var customTheme = 'foo';
var options = {theme: customTheme};
map = new OpenLayers.Map('map', options);
var links = document.getElementsByTagName('link');
var gotNodes = 0;
var themeNode = null;
for(var i=0; i<links.length; ++i) {
if(OpenLayers.Util.isEquivalentUrl(map.theme, links.item(i).href)) {
gotNodes += 1;
themeNode = links.item(i);
}
}
t.eq(map.theme, customTheme, "map theme is properly set");
t.eq(gotNodes, 1, "with custom theme, a single link node is added to document");
t.ok(themeNode != null, "a link node with the theme href was added");
t.eq(themeNode.rel, "stylesheet", "node added has rel set to stylesheet");
t.eq(themeNode.type, "text/css", "node added has type set to text/css");
map.destroy();
}
function test_Map_noTheme(t) {
t.plan(1);
var head = document.getElementsByTagName('head')[0];
var nodeCount = head.childNodes.length;
var options = {theme: null};
map = new OpenLayers.Map('map', options);
t.eq(nodeCount, head.childNodes.length, "with no theme, a node is not added to document head" );
map.destroy();
}
function test_Map_addControls(t) { function test_Map_addControls(t) {
t.plan(5); t.plan(5);
var map = new OpenLayers.Map('map', { var map = new OpenLayers.Map('map', {