Adding an option to avoid duplicate attribution.

Thanks Marc Jansen for this nice contribution.  Without wanting
to gush, I think this should be a model contribution because:

 1. it is a simple change
 2. with a nice example that clearly demonstrates the benefit
 3. it includes tests!
 4. and Marc wrote a note to the dev list with links to the ticket

r = me (closes #2266)



git-svn-id: http://svn.openlayers.org/trunk/openlayers@9720 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
Tim Schaub
2009-10-06 18:46:06 +00:00
parent 11b38e5419
commit d1cecf3be1
3 changed files with 110 additions and 2 deletions

View File

@@ -22,6 +22,12 @@ OpenLayers.Control.Attribution =
* {String} String used to seperate layers.
*/
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
@@ -81,9 +87,13 @@ 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()) {
attributions.push( layer.attribution );
// 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) {
attributions.push( layer.attribution );
}
}
}
}
this.div.innerHTML = attributions.join(this.separator);
}
},