/**
* Created by JetBrains PhpStorm.
* User: IKamenev
* Date: 21.12.11
* Time: 12:14
* To change this template use File | Settings | File Templates.
*/
var mapHotelsForCity = {
mapInitialized: false,
centerLat: null,
centerLng: null,
zoomLevel: null,
countryPath: null,
cityID: null,
init: function () {
$("#mapCanvas").googleMapV3({
centerLat: this.centerLat,
centerLng: this.centerLng,
zoomLevel: 12,
dragEndEvent: this.mapDragEndEvent,
zoomEndEvent: this.mapZoomEndEvent
});
// $("#mapCanvas").bind("mousewheel", function(event) {
// console.log("mousewheel");
// event.stopPropagation();
// return false;
// });
this.getOverlays();
},
mapZoomEndEvent: function() {
mapHotelsForCity.getOverlays();
},
mapDragEndEvent: function() {
//console.log('mapDragEndEvent');
mapHotelsForCity.getOverlays();
},
getOverlays: function() {
//console.log("getOverlays");
var bounds = $("#mapCanvas")[0].googleMapObject.getBounds();
if (!bounds) {
setTimeout(function() {mapHotelsForCity.getOverlays();}, 10);
return;
}
var sw = bounds.getSouthWest();
var ne = bounds.getNorthEast();
var t = this;
$.ajax({
url: '/ajax/getOverlaysForStaticHotelsOnMap/' + this.countryPath + '/' + this.cityID + '?lat1=' + sw.lat() + '&lng1=' + sw.lng() + '&lat2=' + ne.lat() + '&lng2=' + ne.lng(),
dataType: 'json',
success: function (data) {
if (data.overlays) {
if (data.overlays.length > 0) {
for (i in data.overlays) {
var hotel = data.overlays[i];
hotel.countryPath = t.countryPath;
hotel.cityID = t.cityID;
//console.log(hotel);
var item = new HotelMarker(hotel);
$("#mapCanvas")[0].addItem(item);
}
}
$("#mapCanvas")[0].showItems({type: 'hotel'});
}
}
});
},
showList: function() {
$("#showMapText").html('На карте');
$("#showListText").html('Списком');
$("#showList").addClass('active');
$("#showMap").removeClass('active');
$("#hotelsOnMap").hide();
$("#hotelsOnList").show();
mapHotelsForCity.needShowMap = false;
$('.tab > span.list').hide();
$('.tab > span.map').show();
},
showMap: function() {
$("#showMapText").html('На карте');
$("#showListText").html('Списком');
$("#showList").removeClass('active');
$("#showMap").addClass('active');
$("#hotelsOnMap").show();
$("#hotelsOnList").hide();
if (!this.mapInitialized)
mapHotelsForCity.init();
mapHotelsForCity.needShowMap = true;
$('.tab > span.list').show();
$('.tab > span.map').hide();
}
};