var App_Dealer_Map = qs.createObject(); var appDealerMap; App_Dealer_Map.prototype = { _map:null, _canvasId:'dealer-map-canvas', _initialized:false, radius:0, bounds:{ southWest:{lat:null, lng:null}, northEast:{lat:null, lng:null} }, center:{lat:null, lng:null}, list: {}, /* {dealerId: {id, title, latitude, longitude, infoWindowHtml}, ...} */ _markers: {}, /* {dealerId: google.maps.Marker, ...} */ initialize:function (options) { this.setOptions(options); this._initMap(); // this.setPlaces(); // this.initResize(); }, initResize:function(){ var that = this; $(window).resize(function () { that.setPlaces(); }) }, setPlaces : function(){ if($(window).width() < 768){ $("#dealer .span4").insertAfter($("#dealer .span8")); }else{ $("#dealer .span4").insertBefore($("#dealer .span8")); } }, setOptions:function (options) { for (var name in options) { if (options.hasOwnProperty(name)) { this[name] = options[name]; } } }, _initMap:function () { if (this._initialized) { return; } var options = { zoom:7, center:new google.maps.LatLng(this.center.lat, this.center.lng), mapTypeId:google.maps.MapTypeId.ROADMAP }; this._map = new google.maps.Map(document.getElementById(this._canvasId), options); if (! this.list.empty) { var southWestLocation = new google.maps.LatLng(this.bounds.southWest.lat, this.bounds.southWest.lng, false); var northEastLocation = new google.maps.LatLng(this.bounds.northEast.lat, this.bounds.northEast.lng, false); var bounds = new google.maps.LatLngBounds(southWestLocation, northEastLocation); this._map.fitBounds(bounds); for (var dealerId in this.list) { if (this.list.hasOwnProperty(dealerId)) { this._initProperty(this.list[dealerId]); } } this._renderCircle(); } this._initialized = true; }, _renderCircle:function () { if (!this.radius) { return; } var options = { strokeColor:"#FF0000", strokeOpacity:0.8, strokeWeight:2, fillOpacity:0.08, map:this._map, center:new google.maps.LatLng(this.center.lat, this.center.lng), radius:this.radius * 1609.344 }; new google.maps.Circle(options); }, _initProperty:function (property) { var marker = new google.maps.Marker({ position:new google.maps.LatLng(property.latitude, property.longitude), map:this._map, title:property.title }); var infoWindow = new google.maps.InfoWindow({ content:property.infoWindowHtml }); marker.infoWindow = infoWindow; var self = this; this._markers[property.id] = marker; google.maps.event.addListener(marker, 'click', function () { infoWindow.open(self._map, marker); }); }, showDealer: function(dealerId) { /* hiding all opened info window */ for (var id in this._markers) { if (this._markers.hasOwnProperty(id)) { this._markers[id].infoWindow.close(); } } /* showing appropriate infoWindow */ if (this._markers[dealerId]) { google.maps.event.trigger(this._markers[dealerId], "click"); } return false; } };