Repository navigation
Change handler behavior
JPN edited this page Nov 7, 2013
·
10 revisions
You can inject whatever model / builder you want.
Let's see some examples.
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', 'marker_container' boxText.innerHTML = @args.marker # _.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, 'marker': '<span>Here!</span>'} ]) 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>
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>