Browse Source

feat: allow setting class on marker label (#129)

main
Justin Poehnelt 4 years ago committed by GitHub
parent
commit
80318ddaab
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 14
      src/label.ts
  2. 7
      src/marker.test.ts
  3. 8
      src/marker.ts

14
src/label.ts

@ -91,6 +91,20 @@ export class Label extends OverlayViewSafe { @@ -91,6 +91,20 @@ export class Label extends OverlayViewSafe {
}
}
/**
* Get the class of the label div elements.
*
* **Note**: This will always return the default `marker-label`.
*/
get className(): string {
return this.labelDiv.className;
}
/**
* Set the class of the label div elements.
*
* **Note**: The default `marker-label` will additionaly be added.
*/
set className(className: string) {
this.labelDiv.className = className;
this.labelDiv.classList.add(LABEL_CLASS);

7
src/marker.test.ts

@ -100,3 +100,10 @@ test("should not have interactive listeners if no map", () => { @@ -100,3 +100,10 @@ test("should not have interactive listeners if no map", () => {
0
);
});
test("should set class on label", () => {
const marker = new MarkerWithLabel({ labelContent: "foo" });
const className = "bar baz";
marker.labelClass = className;
expect(marker.labelClass).toMatch(className);
});

8
src/marker.ts

@ -89,6 +89,14 @@ export class MarkerWithLabel extends MarkerSafe { @@ -89,6 +89,14 @@ export class MarkerWithLabel extends MarkerSafe {
return this.getClickable() || this.getDraggable();
}
get labelClass() {
return this.label.className;
}
set labelClass(className: string) {
this.label.className = className;
}
setMap(map: google.maps.Map | google.maps.StreetViewPanorama | null): void {
super.setMap(map);
setTimeout(() => {

Loading…
Cancel
Save