Skip to content

Instantly share code, notes, and snippets.

@usefulthink
Created October 17, 2023 09:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save usefulthink/02d33cd8ed35f75e35a902b014591f6d to your computer and use it in GitHub Desktop.
Save usefulthink/02d33cd8ed35f75e35a902b014591f6d to your computer and use it in GitHub Desktop.
Skeleton for implementing a custom overlay for google maps.
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