Skip to content

Instantly share code, notes, and snippets.

@Scarysize
Created July 20, 2016 14:43
Show Gist options
  • Save Scarysize/5d88f66af98fc24a9160f31b0290791e to your computer and use it in GitHub Desktop.
Save Scarysize/5d88f66af98fc24a9160f31b0290791e to your computer and use it in GitHub Desktop.
function MeteoGroupInteractiveMap(domElement, options) {
constructor(domElement, options) {
// Do we want to hide this?
// We might need to hide this in closures for map functionalities (zoom, pan etc.)
// IMO we should definitly hide it.
this.map = new google.maps.Map(domElement, options);
// better:
const map = new google.maps.Map(domElement, options);
this.setupMapControls(map);
this.layers = [];
this.dataSources = [];
this.setupMapEvents(map);
}
setupMapEvents(map) {
map.addListener('click', event => {
this.layers.forEach(layer => dispatchEvent({
type: 'click',
detail: { ...event.coords } // lat, lng, pixel x/y
}))
});
// similar thing for :hover
}
addLayer(layer) {
// maybe do a check first to avoid duplicate layers
this.layers.push(layer);
}
setupMapControls(map) {
this.setZoom = zoom => map.setZoom(zoom);
//....
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment