diff --git a/src/label.test.ts b/src/label.test.ts index 06e4e4d..f9cfde1 100644 --- a/src/label.test.ts +++ b/src/label.test.ts @@ -39,7 +39,7 @@ test("should render the divs correctly with string content", () => { expect(label["labelDiv"]).toMatchInlineSnapshot(`
foo
@@ -47,7 +47,7 @@ test("should render the divs correctly with string content", () => { expect(label["eventDiv"]).toMatchInlineSnapshot(`
foo
@@ -60,7 +60,7 @@ test("should render the divs correctly with node content", () => { expect(label["labelDiv"]).toMatchInlineSnapshot(`
@@ -68,7 +68,7 @@ test("should render the divs correctly with node content", () => { expect(label["eventDiv"]).toMatchInlineSnapshot(`
@@ -91,7 +91,7 @@ test("should render the divs with options", () => { expect(label["labelDiv"]).toMatchInlineSnapshot(`
foo
@@ -99,26 +99,29 @@ test("should render the divs with options", () => { expect(label["eventDiv"]).toMatchInlineSnapshot(` `); }); -test("should render the event div based upon interactivity", () => { - const label = new Label({ - labelContent: "foo", - draggable: false, - clickable: false, - }); +test.each([ + [false, false, "none"], + [true, false, "block"], + [false, true, "block"], + [true, true, "block"], +])( + "should render the event div based upon interactivity %s %s %s", + (clickable, draggable, display) => { + const label = new Label({ + labelContent: "foo", + draggable: false, + clickable: false, + }); + + label.visible = true; - [ - [false, false, "none"], - [true, false, "block"], - [false, true, "block"], - [true, true, "block"], - ].map(([clickable, draggable, display]: [boolean, boolean, string]) => { label.clickable = clickable; label.draggable = draggable; label.draw(); @@ -126,5 +129,16 @@ test("should render the event div based upon interactivity", () => { expect(label["eventDiv"].style.cursor).toBe( display === "block" ? "pointer" : "inherit" ); - }); + } +); + +test("should not display event div if marker is not visible", () => { + const label = new Label({ labelContent: "foo" }); + + label.clickable = true; + label.draggable = true; + label.visible = false; + + label.draw(); + expect(label["eventDiv"].style.display).toBe("none"); }); diff --git a/src/label.ts b/src/label.ts index adfe7fe..0c7ed9e 100644 --- a/src/label.ts +++ b/src/label.ts @@ -49,6 +49,7 @@ export class Label extends OverlayViewSafe { opacity = 1, map, labelZIndexOffset = 1, + visible = true, zIndex = 0, }: LabelOptions) { super(); @@ -69,6 +70,7 @@ export class Label extends OverlayViewSafe { } this.opacity = opacity; + this.visible = visible; this.zIndex = zIndex; this.zIndexOffset = labelZIndexOffset; @@ -152,7 +154,9 @@ export class Label extends OverlayViewSafe { this.eventDiv.style.zIndex = String(zIndex); // If not interactive set display none on event div - this.eventDiv.style.display = this.isInteractive ? BLOCK : NONE; + this.eventDiv.style.display = this.isInteractive + ? this.eventDiv.style.display + : NONE; this.eventDiv.style.cursor = this.cursor; }