Created
March 29, 2015 06:16
-
-
Save zpratt/7ed18be2573e1bb194cc to your computer and use it in GitHub Desktop.
Complete Custom Overlay
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
'use strict'; | |
var google = global.google; | |
function positionOverlayByDimensions(projectedLatLng) { | |
var offsetHeight = this.el.offsetHeight, | |
offsetWidth = this.el.offsetWidth; | |
this.el.style.top = projectedLatLng.y - offsetHeight + 'px'; | |
this.el.style.left = projectedLatLng.x - Math.floor(offsetWidth / 2) + 'px'; | |
} | |
function draw() { | |
var projection = this.getProjection(), | |
projectedLatLng = projection.fromLatLngToDivPixel(this.point); | |
positionOverlayByDimensions.call(this, projectedLatLng); | |
} | |
function onAdd() { | |
var panes = this.getPanes(); | |
panes.overlayLayer.appendChild(this.el); | |
} | |
function BaseOverlay(options) { | |
var point = options.point; | |
this.el = options.el; | |
this.point = new google.maps.LatLng(point.lat, point.lng); | |
this.el.style.position = 'absolute'; | |
} | |
BaseOverlay.prototype = Object.create(google.maps.OverlayView.prototype); | |
BaseOverlay.prototype.constructor = BaseOverlay; | |
BaseOverlay.prototype.onAdd = onAdd; | |
BaseOverlay.prototype.draw = draw; | |
module.exports = BaseOverlay; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment