/* A Bar is a simple overlay that outlines a lat/lng bounds on the * map. It has a border of the given weight and color and can optionally * have a semi-transparent background color. * @param latlng {GLatLng} Point to place bar at. * @param opts {Object Literal} Passes configuration options - * weight, color, height, width, text, and offset. */ function MarkerLight(latlng, opts) { this.latlng = latlng; if (!opts) opts = {}; this.type_ = opts.type || ''; this.title_ = opts.title || ''; this.height_ = opts.height || 42; this.width_ = opts.width || 42; this.image_ = opts.image; this.imageOver_ = opts.imageOver; this.clicked_ = 0; } /* MarkerLight extends GOverlay class from the Google Maps API */ MarkerLight.prototype = new GOverlay(); /* Creates the DIV representing this MarkerLight. * @param map {GMap2} Map that bar overlay is added to. */ MarkerLight.prototype.initialize = function(map) { var me = this; // Create the DIV representing our MarkerLight var div = document.createElement("div"); if(me.type_ == 'photo') div.style.border = "1px solid white"; //div.className = 'markerlight'; div.style.position = "absolute"; div.style.marginTop = "-24px"; div.style.cursor = 'pointer'; div.setAttribute('title',me.title_); var img = document.createElement("img"); img.src = me.image_; img.style.width = me.width_ + "px"; img.style.height = me.height_ + "px"; div.appendChild(img); GEvent.addDomListener(div, "click", function(event) { me.clicked_ = 1; GEvent.trigger(me, "click"); }); GEvent.addDomListener(div, "mouseover", function(event) { me.clicked_ = 1; GEvent.trigger(me, "mouseover"); }); /* GEvent.addDomListener(div, "mouseover", function() { me.bringToFront_(); //if(me.label) GEvent.trigger(me.label.div_,'mouseover'); }); GEvent.addDomListener(div, "mouseout", function() { me.sendBack_(); //if(me.label) GEvent.trigger(me.label.div_,'mouseout'); }); */ map.getPane(G_MAP_MARKER_PANE).appendChild(div); this.map_ = map; this.div_ = div; }; /* Remove the main DIV from the map pane */ MarkerLight.prototype.remove = function() { this.div_.parentNode.removeChild(this.div_); if(this.label) this.label.hide(); }; /* Copy our data to a new MarkerLight * @return {MarkerLight} Copy of bar */ MarkerLight.prototype.copy = function() { var opts = {}; opts.color = this.color_; opts.height = this.height_; opts.width = this.width_; opts.image = this.image_; opts.imageOver = this.image_; return new MarkerLight(this.latlng, opts); }; /* Redraw the MarkerLight based on the current projection and zoom level * @param force {boolean} Helps decide whether to redraw overlay */ MarkerLight.prototype.redraw = function(force) { // We only need to redraw if the coordinate system has changed if (!force) return; // Calculate the DIV coordinates of two opposite corners // of our bounds to get the size and position of our MarkerLight var divPixel = this.map_.fromLatLngToDivPixel(this.latlng); var infoWinOffsetX = 20; var infoWinOffsetY = 22; // Now position our DIV based on the DIV coordinates of our bounds this.div_.style.width = this.width_ + "px"; this.div_.style.left = (divPixel.x) - infoWinOffsetX + "px" this.div_.style.height = (this.height_) + "px"; this.div_.style.top = (divPixel.y) - this.height_ + infoWinOffsetY + "px"; if(this.label) this.label.show(); }; MarkerLight.prototype.bringToFront_ = function() { var z = GOverlay.getZIndex(this.latlng.lat()); this.div_.style.zIndex = 1e9;; if(this.label) this.label.div_.style.zIndex = 1e9; } MarkerLight.prototype.sendBack_ = function() { var z = GOverlay.getZIndex(this.latlng.lat()); this.div_.style.zIndex = z; if(this.label) this.label.div_.style.zIndex = z; } /* MarkerLight.prototype.getZIndex = function(m) { return GOverlay.getZIndex(marker.getPoint().lat())-m.clicked*10000; } */ MarkerLight.prototype.getPoint = function() { return this.latlng; }; MarkerLight.prototype.getLatLng = function() { return this.latlng; }; MarkerLight.prototype.isHidden = function() { return false; }; MarkerLight.prototype.setStyle = function(style) { for (s in style) { this.div_.style[s] = style[s]; } }; MarkerLight.prototype.setImage = function(image) { this.div_.style.background = 'url("' + image + '")'; } MarkerLight.prototype.highlightBorder = function() { this.div_.style.border = "2px solid yellow"; } MarkerLight.prototype.resetBorder = function() { this.div_.style.border = "1px solid white"; }