#= require medivo/views ############### LabList view ############### class window.LabListView extends ListView constructor: (@list)-> super(@list, 'lab_list', 'lab_item_template') ############### Map view ############### ## the standard map view with lab icon ## class window.MapView el: $('#map_canvas') center_marker: null map: null markerBounds: new google.maps.LatLngBounds() markerBoundsZoomOut: 0.1 constructor: (@list, @center_point)-> this.render() map_view = this @list.tracker_elem.change( -> map_view.render() ) options: { mapTypeId: google.maps.MapTypeId.ROADMAP mapTypeControl: false } prepareMap: -> return unless document.getElementById("map_canvas") if !@map @map = new google.maps.Map(document.getElementById("map_canvas"), this.options) createCenterMarker: -> if @center_point point = new google.maps.LatLng(this.center_point.lat, this.center_point.lng) @center_marker = new google.maps.Marker({ position: point map: @map title: this.center_point.title icon: "/assets/medivo/arrow.png" }) this.markerBounds.extend(this.center_marker.position) if this.markerBounds and this.center_marker setMarkers: (map, markerBounds) -> $.each( @list.getList(), (index, model)-> model.setMarker(map, markerBounds) ) clear: -> @list.clearMarkers() if this.center_marker this.center_marker.setMap(null) this.center_marker = null this.markerBounds = new google.maps.LatLngBounds() render: -> return unless @list this.clear() this.prepareMap() return unless @map this.createCenterMarker() this.setMarkers(@map, this.markerBounds) # extend the bounds if its too small if (this.markerBounds.getNorthEast().equals(this.markerBounds.getSouthWest())) extendPoint = new google.maps.LatLng( this.markerBounds.getNorthEast().lat() + this.markerBoundsZoomOut, this.markerBounds.getNorthEast().lng() + this.markerBoundsZoomOut ) this.markerBounds.extend(extendPoint) @map.fitBounds(this.markerBounds)