From 0df30d9602d8611cf63fd0ed733577fa12364f75 Mon Sep 17 00:00:00 2001 From: oscar-sensornet <48438206+oscar-sensornet@users.noreply.github.com> Date: Mon, 15 Apr 2019 01:30:26 +0200 Subject: [PATCH] Make DivIcon html option accept HTMLElement (#6571) * Make DivIcon html option accept Element * Empty div with L.DomUtil.empty * Docstrings for passing `HTMLElement` to DivIcon --- src/layer/marker/DivIcon.js | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/layer/marker/DivIcon.js b/src/layer/marker/DivIcon.js index 4af9c2a5e70..1a51daaaa39 100644 --- a/src/layer/marker/DivIcon.js +++ b/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 @@ -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] @@ -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);