Skip to content

Commit

Permalink
Make DivIcon html option accept HTMLElement (#6571)
Browse files Browse the repository at this point in the history
* Make DivIcon html option accept Element

* Empty div with L.DomUtil.empty

* Docstrings for passing `HTMLElement` to DivIcon
  • Loading branch information
oscar-sensornet authored and IvanSanchez committed Apr 14, 2019
1 parent 3f5979b commit e079588
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions src/layer/marker/DivIcon.js
@@ -1,5 +1,6 @@
import {Icon} from './Icon';
import {toPoint as point} from '../../geometry/Point';
import {empty} from '../../dom/DomUtil';

/*
* @class DivIcon
Expand Down Expand Up @@ -29,8 +30,9 @@ export var DivIcon = Icon.extend({
// iconAnchor: (Point),
// popupAnchor: (Point),

// @option html: String = ''
// Custom HTML code to put inside the div element, empty by default.
// @option html: String|HTMLElement = ''
// Custom HTML code to put inside the div element, empty by default. Alternatively,
// an instance of `HTMLElement`.
html: false,

// @option bgPos: Point = [0, 0]
Expand All @@ -44,7 +46,12 @@ export var DivIcon = Icon.extend({
var div = (oldIcon && oldIcon.tagName === 'DIV') ? oldIcon : document.createElement('div'),
options = this.options;

div.innerHTML = options.html !== false ? options.html : '';
if (options.html instanceof Element) {
empty(div);
div.appendChild(options.html);
} else {
div.innerHTML = options.html !== false ? options.html : '';
}

if (options.bgPos) {
var bgPos = point(options.bgPos);
Expand Down

0 comments on commit e079588

Please sign in to comment.