Skip to content

Instantly share code, notes, and snippets.

@benshimmin
Last active October 5, 2015 14:18
Show Gist options
  • Save benshimmin/2820024 to your computer and use it in GitHub Desktop.
Save benshimmin/2820024 to your computer and use it in GitHub Desktop.
Custom labels for Google Maps
class Label extends google.maps.OverlayView
constructor : (options) ->
@setValues options
@span = document.createElement "span"
@div = document.createElement "div"
@div.appendChild @span
# helpful for styling later
$(@div).addClass "label"
onRemove : =>
@div.parentNode.removeChild @div
draw : =>
proj = @getProjection()
pos = proj.fromLatLngToDivPixel(@get("position"))
text = @get "text"
$(@div).css({
left : pos.x
top : pos.y
zIndex : @get "zIndex"
})
$(@span).html text
onAdd : =>
pane = @getPanes().overlayImage
pane.appendChild @div
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment