The attribution control no longer shows duplicate attribution text. r=crschmidt (closes #2300)

git-svn-id: http://svn.openlayers.org/trunk/openlayers@9731 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
Tim Schaub
2009-10-08 17:00:40 +00:00
parent ab2b2356f1
commit bff91d251c
3 changed files with 10 additions and 98 deletions

View File

@@ -1,78 +0,0 @@
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>OpenLayers Attribution Example (attribute eliminateDuplicates)</title>
<link rel="stylesheet" href="../theme/default/style.css" type="text/css" />
<link rel="stylesheet" href="style.css" type="text/css" />
<script src="../lib/OpenLayers.js"></script>
<script type="text/javascript">
// making this a global variable so that it is accessible for
// debugging/inspecting in Firebug
var map = null;
function init(){
map = new OpenLayers.Map('map', {controls: []});
map2 = new OpenLayers.Map('map2', {controls: []});
var ol_wms = new OpenLayers.Layer.WMS(
"OpenLayers WMS",
"http://labs.metacarta.com/wms/vmap0",
{layers: 'basic'},
{attribution: '&copy; MetaCarta'}
);
var ol_wms2 = new OpenLayers.Layer.WMS(
"OpenLayers WMS",
"http://labs.metacarta.com/wms/vmap0",
{layers: 'basic', transparent: 'true'},
{attribution: '&copy; MetaCarta'}
);
var ol_wms3 = new OpenLayers.Layer.WMS(
"OpenLayers WMS",
"http://labs.metacarta.com/wms/vmap0",
{layers: 'basic', transparent: 'true'},
{attribution: '&copy; other company'}
);
var ol_wms4 = new OpenLayers.Layer.WMS(
"OpenLayers WMS",
"http://labs.metacarta.com/wms/vmap0",
{layers: 'basic', transparent: 'true'},
{attribution: '&copy; other company'}
);
var ol_wms5 = new OpenLayers.Layer.WMS(
"OpenLayers WMS",
"http://labs.metacarta.com/wms/vmap0",
{layers: 'basic', transparent: 'true'},
{attribution: '&copy; MetaCarta'}
);
map.addLayers([ol_wms, ol_wms2, ol_wms3, ol_wms4, ol_wms5]);
map2.addLayers([ol_wms.clone(), ol_wms2.clone(), ol_wms3.clone(), ol_wms4.clone(), ol_wms5.clone()]);
var attrWithDuplicates = new OpenLayers.Control.Attribution();
var attrWithoutDuplicates = new OpenLayers.Control.Attribution( {
eliminateDuplicates: true
} );
map.addControl(attrWithDuplicates);
map.addControl(new OpenLayers.Control.LayerSwitcher());
map.zoomToMaxExtent();
map2.addControl(attrWithoutDuplicates);
map2.addControl(new OpenLayers.Control.LayerSwitcher());
map2.zoomToMaxExtent();
}
</script>
</head>
<body onload="init()">
<h1 id="title">OpenLayers Attribution Example (attribute <code>eliminateDuplicates</code>)</h1>
<div id="tags"></div>
<p id="shortdesc">
Demonstrates the use of the attribute <code>eliminateDuplicates</code> for Attribution-controls
</p>
<h2>Standard Usage of the control</h2>
<div id="map" class="smallmap"></div>
<h2>Use the attribute <code>eliminateDuplicates</code> to get rid of redundant Information</h2>
<div id="map2" class="smallmap"></div>
<div id="docs"></div>
</body>
</html>

View File

@@ -23,12 +23,6 @@ OpenLayers.Control.Attribution =
*/
separator: ", ",
/**
* APIProperty: eliminateDuplicates
* {Boolean} shall already present attribution strings be eliminated when other layers have the same attribution string?
*/
eliminateDuplicates: false,
/**
* Constructor: OpenLayers.Control.Attribution
*
@@ -87,9 +81,9 @@ OpenLayers.Control.Attribution =
for(var i=0, len=this.map.layers.length; i<len; i++) {
var layer = this.map.layers[i];
if (layer.attribution && layer.getVisibility()) {
// add attribution if duplicates shall be ignored generally
// or if the current attribution string is unique
if (!this.eliminateDuplicates || OpenLayers.Util.indexOf(attributions, layer.attribution) === -1) {
// add attribution only if attribution text is unique
if (OpenLayers.Util.indexOf(
attributions, layer.attribution) === -1) {
attributions.push( layer.attribution );
}
}

View File

@@ -36,24 +36,20 @@
}
function test_Control_Attribution_Propertry_eliminateDuplicates(t) {
t.plan(3);
function test_Control_Attribution_no_duplicates(t) {
t.plan(2);
control = new OpenLayers.Control.Attribution();
map = new OpenLayers.Map("map");
map.addControl(control);
map.addLayer(new OpenLayers.Layer("Company A: 1",{'attribution':'company A'}));
map.addLayer(new OpenLayers.Layer("Company A: 2",{'attribution':'company A'}));
t.eq(control.div.innerHTML, 'company A, company A', "Attribution correct with two layers and eliminateDuplicates = false.");
control.destroy();
control = new OpenLayers.Control.Attribution({eliminateDuplicates:true});
control = new OpenLayers.Control.Attribution();
map.addControl(control);
t.eq(control.div.innerHTML, 'company A', "Attribution correct with two layers and eliminateDuplicates = true.");
t.eq(control.div.innerHTML, 'company A', "Attribution not duplicated.");
map.addLayer(new OpenLayers.Layer("Company B: 1",{'attribution':'company B'}));
map.addLayer(new OpenLayers.Layer("Company A: 3",{'attribution':'company A'}));
t.eq(control.div.innerHTML, 'company A, company B', "Attribution correct with four layers (3 with same attribution) and eliminateDuplicates = true.");
t.eq(control.div.innerHTML, 'company A, company B', "Attribution correct with four layers (3 with same attribution).");
}
</script>
</head>