Allow using elements in logo attribution options
This commit lets the user use an element object instead of a {src: href} object for an attribution logo when creating a map. This opens a lot of possibilities for that logo, for example setting the target to force the logo to open in a new tab when clicked.
This commit is contained in:
@@ -309,6 +309,9 @@ ol.control.Attribution.prototype.insertLogos_ = function(frameState) {
|
||||
var logoValue = logos[logoKey];
|
||||
if (logoValue === '') {
|
||||
logoElement = image;
|
||||
} else if (goog.dom.isElement(logoValue)) {
|
||||
goog.asserts.assertElement(logoValue);
|
||||
logoElement = logoValue;
|
||||
} else {
|
||||
logoElement = goog.dom.createDom('A', {
|
||||
'href': logoValue
|
||||
|
||||
@@ -1450,7 +1450,7 @@ ol.Map.prototype.unskipFeature = function(feature) {
|
||||
* @typedef {{controls: ol.Collection.<ol.control.Control>,
|
||||
* interactions: ol.Collection.<ol.interaction.Interaction>,
|
||||
* keyboardEventTarget: (Element|Document),
|
||||
* logos: Object.<string, string>,
|
||||
* logos: (Object.<string, (string|Element)>),
|
||||
* overlays: ol.Collection.<ol.Overlay>,
|
||||
* rendererConstructor:
|
||||
* function(new: ol.renderer.Map, Element, ol.Map),
|
||||
@@ -1490,6 +1490,8 @@ ol.Map.createOptionsInternal = function(options) {
|
||||
var logo = options.logo;
|
||||
if (typeof logo === 'string') {
|
||||
logos[logo] = '';
|
||||
} else if (goog.dom.isElement(logo)) {
|
||||
logos['logo'] = logo;
|
||||
} else if (goog.isObject(logo)) {
|
||||
goog.asserts.assertString(logo.href, 'logo.href should be a string');
|
||||
goog.asserts.assertString(logo.src, 'logo.src should be a string');
|
||||
|
||||
Reference in New Issue
Block a user