-
-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
194 additions
and
93 deletions.
There are no files selected for viewing
86 changes: 86 additions & 0 deletions
86
apps/fxc-front/src/app/components/2d/adv-marker-element.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
import { LitElement } from 'lit'; | ||
import { customElement, property } from 'lit/decorators.js'; | ||
|
||
// Wrapper component for Advanced Markers. | ||
@customElement('adv-marker-element') | ||
export class AdvancedMarkerElement extends LitElement { | ||
@property({ attribute: false }) | ||
set lat(value: number) { | ||
this.lat_ = value; | ||
this.requestUpdate(); | ||
} | ||
|
||
get lat(): number { | ||
return this.lat_; | ||
} | ||
|
||
@property({ attribute: false }) | ||
set lng(value: number) { | ||
this.lng_ = value; | ||
this.requestUpdate(); | ||
} | ||
|
||
get lng(): number { | ||
return this.lng_; | ||
} | ||
|
||
@property({ attribute: false }) | ||
set title(value: string) { | ||
this.marker_.title = value; | ||
} | ||
|
||
get title(): string { | ||
return this.marker_.title; | ||
} | ||
|
||
@property({ attribute: false }) | ||
set zindex(value: number) { | ||
this.marker_.zIndex = value; | ||
} | ||
|
||
get zindex(): number { | ||
return this.marker_.zIndex ?? 0; | ||
} | ||
|
||
@property({ attribute: false }) | ||
set map(value: google.maps.Map | null | undefined) { | ||
this.marker_.map = value ?? null; | ||
} | ||
|
||
get map() { | ||
return this.marker_.map; | ||
} | ||
|
||
@property({ attribute: false }) | ||
set content(value: Node | null | undefined) { | ||
this.marker_.content = value; | ||
} | ||
|
||
get content() { | ||
return this.marker_.content; | ||
} | ||
|
||
private lat_ = 0; | ||
private lng_ = 0; | ||
private marker_ = new google.maps.marker.AdvancedMarkerElement(); | ||
|
||
connectedCallback(): void { | ||
super.connectedCallback(); | ||
this.marker_.addListener('click', () => this.dispatchEvent(new CustomEvent('click'))); | ||
} | ||
|
||
disconnectedCallback() { | ||
super.disconnectedCallback(); | ||
google.maps.event.clearInstanceListeners(this.marker_); | ||
// setTimeout is needed otherwise the marker isn't removed. | ||
setTimeout(() => (this.marker_.map = null), 0); | ||
} | ||
|
||
render() { | ||
this.marker_.position = { lat: this.lat_, lng: this.lng_ }; | ||
} | ||
|
||
protected createRenderRoot(): HTMLElement | DocumentFragment { | ||
return this; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters