Skip to content

Navigation Menu

Sign up

Change handler behavior

Benjamin Roth edited this page Oct 21, 2013 · 10 revisions

Principles

You can inject whatever model / builder you want.

Let's see some examples

Rich Marker

Say you want to use Rich Markers. To do this, we need to change the way the marker is created.

So we'll change the marker builder:

class RichMarkerBuilder extends Gmaps.Google.Builders.Marker #inherit from builtin builder
 #override create_marker method
 create_marker: ->
 options = _.extend @marker_options(), @rich_marker_options()
 @serviceObject = new RichMarker options #assign marker to @serviceObject
 rich_marker_options: ->
 boxText = document.createElement("div")
 boxText.setAttribute("class", 'yellow')
 boxText.innerHTML = @args.infowindow
 _.extend(@marker_options(), { content: boxText })
handler = Gmaps.build 'Google', { builders: { Marker: RichMarkerBuilder} } #dependency injection
#then standard use
handler.buildMap { provider: {}, internal: {id: 'map'} }, ->
 markers = handler.addMarkers([
 {"lat": 0, "lng": 0}
 ])
 handler.bounds.extendWith(markers)
 handler.fitMapToBounds()

Of course, we'd need to have the rich marker javascript:

<script src='//google-maps-utility-library-v3.googlecode.com/svn/trunk/richmarker/src/richmarker-compiled.js' type='text/javascript'></script>

InfoBox

class InfoBoxBuilder extends Gmaps.Google.Builders.Marker # inherit from base builder
 # override method
 create_infowindow: ->
 return null unless _.isString @args.infowindow
 boxText = document.createElement("div")
 boxText.setAttribute("class", 'yellow') #to customize
 boxText.innerHTML = @args.infowindow
 @infowindow = new InfoBox(@infobox(boxText))
 @bind_infowindow()
 infobox: (boxText)->
 content: boxText
 pixelOffset: new google.maps.Size(-140, 0)
 boxStyle:
 width: "280px"
handler = Gmaps.build 'Google', { builders: { Marker: InfoBoxBuilder} }

Of course, we'd need to have the infobox javascript:

<script src='//google-maps-utility-library-v3.googlecode.com/svn/tags/infobox/1.1.9/src/infobox_packed.js' type='text/javascript'></script>

Clone this wiki locally

AltStyle によって変換されたページ (->オリジナル) /