Created
October 17, 2023 09:14
-
-
Save usefulthink/02d33cd8ed35f75e35a902b014591f6d to your computer and use it in GitHub Desktop.
Skeleton for implementing a custom overlay for google maps.
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
class CustomOverlay { | |
constructor() { | |
this.overlay = new google.maps.OverlayView(); | |
this.overlay.onAdd = () => this.onAdd(); | |
this.overlay.onRemove = () => this.onRemove(); | |
this.overlay.draw = () => this.draw(); | |
} | |
onAdd() { /* ... */ } | |
onRemove() { /* ... */ } | |
draw() { | |
const p = this.overlay.getProjection(); | |
const pane = this.overlay.getPanes().floatPane; | |
// [...] | |
} | |
setMap(map) { this.overlay.setMap(map); } | |
getMap() { return this.overlay.getMap(); } | |
} | |
// ... somewhere else (when api is loaded): | |
const map = new google.maps.Map( /* ... */ ); | |
const overlay = new CustomOverlay(); | |
overlay.setMap(map); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment