Browse Source

feat: set and get label content (#328)

main
Jonas Engberg 3 years ago committed by GitHub
parent
commit
9d9f93b2ab
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 4
      src/label.ts
  2. 7
      src/marker.test.ts
  3. 8
      src/marker.ts

4
src/label.ts

@ -79,6 +79,10 @@ export class Label extends OverlayViewSafe {
} }
} }
get content(): string | HTMLElement {
return this.labelDiv.innerHTML;
}
set content(content: string | HTMLElement) { set content(content: string | HTMLElement) {
if (typeof content === "string") { if (typeof content === "string") {
this.labelDiv.innerHTML = content; this.labelDiv.innerHTML = content;

7
src/marker.test.ts

@ -116,3 +116,10 @@ test("should set class on label", () => {
marker.labelClass = className; marker.labelClass = className;
expect(marker.labelClass).toMatch(className); expect(marker.labelClass).toMatch(className);
}); });
test("should set content on label", () => {
const marker = new MarkerWithLabel({ labelContent: "foo" });
const newConent = "bar";
marker.labelContent = newConent;
expect(marker.labelContent).toMatch(newConent);
});

8
src/marker.ts

@ -97,6 +97,14 @@ export class MarkerWithLabel extends MarkerSafe {
return this.getClickable() || this.getDraggable(); return this.getClickable() || this.getDraggable();
} }
get labelContent(): string | HTMLElement {
return this.label.content;
}
set labelContent(content: string | HTMLElement) {
this.label.content = content;
}
get labelClass() { get labelClass() {
return this.label.className; return this.label.className;
} }

Loading…
Cancel
Save