var App_Property_Map = { _map:null, _canvasId:'property-map-canvas', _initialized:false, bounds:{ southWest:{lat:null, lng:null}, northEast:{lat:null, lng:null} }, center:{lat:null, lng:null}, radius:0, list:[], initialize:function (options) { this.setOptions(options); if ('collapsed' != $.cookie('propertyMapStatus')) { this._initMap(); } var obj = this; $('#btnHideShowMap').click(function(){ obj.showHideOnClick(this); }); }, setOptions:function (options) { for (var name in options) { this[name] = options[name]; } }, _initMap:function () { if (this._initialized) { return; } var options = { zoom:8, 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); 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 i = 0; i < this.list.length; i++) { this._initProperty(this.list[i]); } 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 }); var self = this; google.maps.event.addListener(marker, 'click', function () { infoWindow.open(self._map, marker); }); }, showHideOnClick:function (element) { var selector = $('#property-map-item'); selector.toggle(); var status = selector.is(':visible') ? 'expanded' : 'collapsed'; $.cookie('propertyMapStatus', status); this._initMap(); $(element).attr('class', 'btn_map_' + status); $(element).text((status == 'expanded' ? 'Hide' : 'Show') + ' Map'); return false; } }; var appPropertyMap; function initMap(options) { var appPropertyMap = App_Property_Map; appPropertyMap.initialize(options); }