/**
* Google Maps
*/
google_maps : {
init: function(){
var scope = this,
map_el = $('.google-map');
if ( map_el.length < 1 )
return;
$('.google-map').each(function(){
scope.render_map( $(this) );
$(this).addClass('ready');
});
},
render_map : function( $el ){
var $markers = $('.map-markers');
// vars
var args = {
zoom : 13,
mapTypeId : google.maps.MapTypeId.ROADMAP,
mapTypeControl : false,
scaleControl: true,
streetViewControl: false,
draggable: true,
scrollwheel: false,
};
// create map
var map = new google.maps.Map( $el[0], args);
// add a markers reference
map.markers = [];
var infowindow = new google.maps.InfoWindow();
// add markers
$markers.each(function(){
//app.google_maps.add_marker( $(this), map );
var latlng = new google.maps.LatLng( $(this).attr('data-lat'), $(this).attr('data-lng'));
var url = $('.google-map').attr('data-pin');
// Custom pin
var pin = {
url: url,
size: new google.maps.Size(30, 45),
origin: new google.maps.Point(0, 0),
anchor: new google.maps.Point(15, 45)
}
// create marker
var marker = new google.maps.Marker({
position : latlng,
icon : pin,
map : map
});
var windowContent = $(this).html();
google.maps.event.addListener(marker, "click", function (e) {
//Wrap the content inside an HTML DIV in order to set height and width of InfoWindow.
infowindow.setContent(windowContent);
infowindow.open(map, marker);
var iwOuter = $('.gm-style-iw');
var iwCross = $('.gm-style-iw').next();
var iwBackground = iwOuter.prev();
iwCross.addClass('iwCross');
iwBackground.children(':nth-child(1)').css({'display' : 'none'});
iwBackground.children(':nth-child(2)').css({'display' : 'none'});
iwBackground.children(':nth-child(3)').css({'display' : 'none'});
iwBackground.children(':nth-child(4)').css({'display' : 'none'});
});
map.markers.push( marker );
});
// center map
app.google_maps.center_map( map );
},
center_map : function( map ){
var bounds = new google.maps.LatLngBounds();
$.each( map.markers, function( i, marker ){
var latlng = new google.maps.LatLng( marker.position.lat(), marker.position.lng() );
bounds.extend( latlng );
});
// only 1 marker?
if( map.markers.length == 1 ) {
// set center of map
map.setCenter( bounds.getCenter() );
map.setZoom( 15 );
} else {
// fit to bounds
map.fitBounds( bounds );
}
}
},