/** * Created by JetBrains PhpStorm. * User: IKamenev * Date: 21.12.11 * Time: 16:05 * To change this template use File | Settings | File Templates. */ function WishCustomOverlay(options) { this._markerItem = options.marker; this._marker = options.marker.marker; this._width = options.width; this._height = 200; this._div = null; this._html = options.html; this._verticalOffset = 31; // расстояние от маркера до нижнего края всплывающего окошка this._doNotClose = false; this.setMap(options.map); } WishCustomOverlay.prototype = new CustomOverlay(); function WishMarker(item) { this.id = item.id; this.tags = []; for (i in item.tags) { this.tags.push(item.tags[i].toString()); } if(item.rawId) this.rawId = item.rawId; this.title = (item.title) ? item.title : ''; this.link = (item.link) ? item.link : ''; this.showBubble = true; this.bubbleAjaxBaseUrl = null; this.vwButtons = false; this.bubbleLoaded = false; this.bubbleLoading = false; this.bubbleWidth = 500; //item.width ? item.width : 500; if(item.bubbleAjaxBaseUrl) this.bubbleAjaxBaseUrl = item.bubbleAjaxBaseUrl; if (typeof(item.showBubble) != "undefined") this.showBubble = item.showBubble; this.type = "poi"; this.marker = null; this.html = ""; if(item.activeImageURL && item.activeImageURL != 'undefined' && item.activeImageURL != '') this.activeImageURL = item.activeImageURL; else if(item.markerHover && item.markerHover != 'undefined' && item.markerHover != '') this.activeImageURL = item.markerHover; else this.activeImageURL = '/i/icons/poi_bubble_hover.png'; if(item.inactiveImageURL && item.inactiveImageURL != 'undefined' && item.inactiveImageURL != '') this.inactiveImageURL = item.inactiveImageURL; else if(item.markerNormal && item.markerNormal != 'undefined' && item.markerNormal != '') this.inactiveImageURL = item.markerNormal; else this.inactiveImageURL = '/i/icons/poi_bubble.png'; this.activeImage = null; this.inactiveImage = null; this.selected = false; this.overlay = null; this.zIndex = 1; // прелоад неактивной картинки, чтобы исключить мигание this.preloadImage = function (img) { $("").attr("src", img); }; this.preloadImage(this.inactiveImageURL); this.preloadImage(this.activeImageURL); // mouseOut с маркера this.mouseOver = function (map) { this.map = map; this.makeActive(); }; // mouseOver над маркером this.mouseOut = function (map) { this.map = map; this.makeInactive(); }; // клик по маркеру this.click = function (map) { if (this.markerOpened) { this.closeMarker(); } else { this.openMarker(); } }; this.markerOpened = false; this.openMarker = function() { if (this.markerOpened) return; if (this.overlay) { delete(this.overlay); this.overlay = null; } if(this.bubbleAjaxBaseUrl && !this.bubbleLoaded) { this.loadAjaxBubbleHtml(); } this.overlay = new WishCustomOverlay({ map: this.map, html: this.html, width: this.bubbleWidth, marker: this }); if (this.map.lastOpenedMarker && this.map.lastOpenedMarker != this) { this.map.lastOpenedMarker.overlay.hide(); this.map.lastOpenedMarker.markerOpened = false; this.map.lastOpenedMarker.makeInactive(); } this.map.lastOpenedMarker = this; this.markerOpened = true; }; this.closeMarker = function() { this.markerOpened = false; if (this.overlay) { this.overlay.hide(); if (this.map.lastOpenedMarker) { this.map.lastOpenedMarker = null; } } this.makeInactive(); }; this.loadAjaxBubbleHtml = function() { if(this.bubbleLoading) return; this.html = this.makeLoadingHTML(); //this.bubbleWidth = 160; var url = this.bubbleAjaxBaseUrl + '/' + this.rawId; var _this = this; $.ajax({ url: url, success: function (data) { _this.html = data; if(_this.overlay && _this.markerOpened) { _this.closeMarker(); _this.openMarker(); _this.makeActive(); } _this.bubbleLoading = false; } }); this.bubbleLoading = true; }; this.makeActive = function () { this.marker.setIcon(this.activeImage); this.marker.setZIndex(this.zIndex + 1); }; this.makeInactive = function () { if (!this.selected) this.marker.setIcon(this.inactiveImage); this.marker.setZIndex(this.zIndex); }; this.select = function() { this.selected = true; this.makeActive(); this.openMarker(); }; this.deselect = function() { this.selected = false; this.makeInactive(); this.closeMarker(); }; this.scrollTo = function() { this.map.setCenter(this.marker.getPosition()); }; var baseIcon = ""; this.inactiveImage = new google.maps.MarkerImage(this.inactiveImageURL); this.activeImage = new google.maps.MarkerImage(this.activeImageURL); if (item.zIndex) { this.zIndex = item.zIndex; } this.marker = new google.maps.Marker( { position:new google.maps.LatLng(item.lat, item.lng), map:null, icon:this.inactiveImage, title:this.title, zIndex: this.zIndex } ); this.makeLoadingHTML = function () { return '\