Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make DivIcon html option accept Element #6571

Merged
merged 3 commits into from Apr 14, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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