/** * @author Marco Alionso Ramirez, marco@onemarco.com * @url http://onemarco.com * @version 1.0 * This code is public domain */ /** * The Tooltip class is an addon designed for the Google Maps GMarker class. * @constructor * @param {GMarker} marker * @param {String} text * @param {Number} padding */ function Tooltip(marker, text, padding){ this.marker_ = marker; this.text_ = text; this.padding_ = padding; } Tooltip.prototype = new GOverlay(); Tooltip.prototype.initialize = function(map){ var div = document.createElement("div"); div.appendChild(document.createTextNode(this.text_)); div.className = 'tooltip'; div.style.position = 'absolute'; div.style.visibility = 'hidden'; map.getPane(G_MAP_FLOAT_PANE).appendChild(div); this.map_ = map; this.div_ = div; } Tooltip.prototype.remove = function(){ this.div.parentNode.removeChild(this.div); } Tooltip.prototype.copy = function(){ var content = typeof this.content == 'string' ? this.content : this.content.cloneNode(true); return new Tooltip(this.marker,content,this.padding); } Tooltip.prototype.redraw = function(force){ if (!force) return; var markerPos = this.map_.fromLatLngToDivPixel(this.marker_.getPoint()); var iconAnchor = this.marker_.getIcon().iconAnchor; var xPos = Math.round(markerPos.x - this.div_.clientWidth / 2); var yPos = markerPos.y - iconAnchor.y - this.div_.clientHeight - this.padding_; this.div_.style.top = yPos + 'px'; this.div_.style.left = xPos + 'px'; } Tooltip.prototype.show = function(){ this.div_.style.visibility = 'visible'; } Tooltip.prototype.hide = function(){ this.div_.style.visibility = 'hidden'; } if (GBrowserIsCompatible()) { // === Create an associative array of GIcons() === var gicons = []; var icontype =""; var farbicon = new GIcon(); farbicon.iconSize = new GSize(12, 22); farbicon.shadowSize = new GSize(22, 20); farbicon.iconAnchor = new GPoint(6, 20); farbicon.infoWindowAnchor = new GPoint(5, 1); farbicon.imageMap = [4,0,0,4,0,7,3,11,4,19,7,19,8,11,11,7,11,4,7,0]; farbicon.transparent = "./files/mm_20_transparent.png"; // The first pair is the top/left corner, // the second pair is top/right, // the third is bottom/right, // and the fourth is bottom/left. gicons["red"] = new GIcon(farbicon, "./files/mm_20_red.png", null, "./files//mm_20_shadow.png" ); gicons["blue"] = new GIcon(farbicon, "./files/mm_20_blue.png", null, "./files/mm_20_shadow.png"); gicons["green"] = new GIcon(farbicon, "./files/mm_20_green.png", null, "./files/mm_20_shadow.png"); gicons["orange"] = new GIcon(farbicon, "./files/mm_20_orange.png", null, "./files/mm_20_shadow.png"); // Marker ohne Link erstellen erstellen function createMarkerOL(point,titel,icontype) { var markerOL = new GMarker(point, gicons[icontype]); GEvent.addListener(markerOL, "mouseover",function() { this.tooltip.show(); }); GEvent.addListener(markerOL, "mouseout",function() { this.tooltip.hide(); }); return markerOL; } // Marker mit Link erstellen function createMarker(point,titel,link,icontype) { var marker = new GMarker(point, gicons[icontype]); // Link aufrufen bei Klick GEvent.addListener(marker, 'click', function() { window.location.href = (link); }); GEvent.addListener(marker, "mouseover",function() { this.tooltip.show(); }); GEvent.addListener(marker, "mouseout",function() { this.tooltip.hide(); }); return marker; } // Marker ohne Link erstellen erstellen function createMarkerOLOT(point,icontype) { var markerOLOT = new GMarker(point, gicons[icontype]); return markerOLOT; } // Karte zeichen var map = new GMap2(document.getElementById("map")); map.addControl(new GHierarchicalMapTypeControl()); map.setCenter(new GLatLng(52.295167,7.439568),5,G_PHYSICAL_MAP); map.enableScrollWheelZoom(); map.enableContinuousZoom(); var point = new GLatLng(52.295167,7.439568); var tooltip = 'Abi-Fete 2010\n war am 12.06.2010\n in Rheine-Schotthock'; var link = "/index.html"; var marker = createMarker(point,tooltip,'/index.html') var tooltip = new Tooltip(marker,tooltip,15); marker.tooltip = tooltip; map.addOverlay(marker); map.addOverlay(tooltip); } // display a warning if the browser was not compatible else { alert("Sorry, the Google Maps API is not compatible with this browser"); }