-
Notifications
You must be signed in to change notification settings - Fork 7
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
1 parent
47799cb
commit 8dd4444
Showing
3 changed files
with
49 additions
and
43 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import type { ControlPosition, IControl } from "maplibre-gl"; | ||
import { | ||
nextTick, | ||
Ref, | ||
} from "vue"; | ||
import { | ||
Position, | ||
} from "@/lib/components/controls/position.enum"; | ||
|
||
export class CustomControl implements IControl { | ||
public static readonly CONTROL_CLASS = "maplibregl-ctrl"; | ||
public static readonly CONTROL_GROUP_CLASS = "maplibregl-ctrl-group"; | ||
|
||
public readonly container: HTMLDivElement; | ||
|
||
constructor( | ||
private isAdded: Ref<boolean>, | ||
noClasses: boolean, | ||
) { | ||
this.container = document.createElement("div"); | ||
this.setClasses(noClasses); | ||
} | ||
|
||
getDefaultPosition(): ControlPosition { | ||
return Position.TOP_LEFT; | ||
} | ||
|
||
onAdd(): HTMLElement { | ||
nextTick(() => (this.isAdded.value = true)); | ||
return this.container; | ||
} | ||
|
||
onRemove(): void { | ||
this.isAdded.value = false; | ||
this.container.remove(); | ||
} | ||
|
||
setClasses(noClasses: boolean) { | ||
if (noClasses) { | ||
this.container.classList.remove(CustomControl.CONTROL_CLASS); | ||
this.container.classList.remove(CustomControl.CONTROL_GROUP_CLASS); | ||
} else { | ||
this.container.classList.add(CustomControl.CONTROL_CLASS); | ||
this.container.classList.add(CustomControl.CONTROL_GROUP_CLASS); | ||
} | ||
} | ||
} |
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