var GMap = new Class({ initialize: function(map, opts){ var map, marker, windowOpen, markers, select, areas; if (GBrowserIsCompatible() == false) return; function createMarker(point, id) { var marker; marker = new GMarkerHover(point, { propertyID: id, image: '../images/gicon.png', hoverImage: '../images/gicon-hover.png', iconAnchor_x: 15, iconAnchor_y: 37, iconWidth: 30, iconHeight: 37, gThumb: new GThumb(opts), opts: opts }); GEvent.addListener(marker, 'mouseover', function () { if (windowOpen == false) marker.gThumb.show(); }); GEvent.addListener(marker, "click", function() { var i; for (i = 0; i < markers.length; i++) markers[i].closeInfoWindow(); marker.gThumb.hide(); marker.openInfoWindow(); }); GEvent.addListener(marker, 'mouseout', function () { marker.gThumb.hide(); }); GEvent.addListener(marker, 'infowindowopen', function () { windowOpen = true; }); GEvent.addListener(marker, 'infowindowclose', function () { windowOpen = false; }); return marker; } windowOpen = false; markers = new Array(); areas = new Array(); areas.push({latLng: new GLatLng(40.03, -86.15), zoom: 9}); // indianapolis areas.push({latLng: new GLatLng(40.411928, -86.891556), zoom: 11}); // northern indianapolis areas.push({latLng: new GLatLng(39.490264, -86.389618), zoom: 10}); // southern indianapoils select = $('area'); var target = new Element('div').setProperty('id', 'map'); $(map).adopt(target); map = new GMap2(target); map.addControl(new GLargeMapControl ()); map.setCenter(new GLatLng(40.03, -86.15), 9); marker = createMarker(new GLatLng(39.405635, -86.420772), 'countryview'); markers.push(marker); map.addOverlay(marker); marker = createMarker(new GLatLng(40.422187, -86.900868), 'wabash'); markers.push(marker); map.addOverlay(marker); marker = createMarker(new GLatLng(39.665013, -86.185212), 'murphys'); markers.push(marker); map.addOverlay(marker); marker = createMarker(new GLatLng(39.588435, -86.38534), 'towneview'); markers.push(marker); map.addOverlay(marker); marker = createMarker(new GLatLng(39.861395, -86.001062), 'benjamin'); markers.push(marker); map.addOverlay(marker); marker = createMarker(new GLatLng(39.918229, -86.045823), 'masters'); markers.push(marker); map.addOverlay(marker); select.options[0] = new Option('Indianapolis','0'); // select.options[1] = new Option('Northern Indiana','1'); // select.options[2] = new Option('Southern Indiana','2'); // select.addEvent('change', function () { var area; area = areas[this.value]; map.setZoom(area.zoom); map.panTo(area.latLng); }); $ES('li', 'mapTypes').each(function (el) { el.addEvent('click', function (e) { map.setMapType(eval(this.getAttribute('id'))); }); }); } }); // ---------------------------------------------------------------------------------// // GMarkerHover // ---------------------------------------------------------------------------------// function GMarkerHover (point, options) { this.point = point; this.propertyID = options.propertyID || ''; this.image = options.image || ''; this.hoverImage = options.hoverImage || ''; this.iconHeight = options.iconHeight || 0; this.iconWidth = options.iconWidth || 0; this.iconAnchor_x = options.iconAnchor_x || 0; this.iconAnchor_y = options.iconAnchor_y || 0; this.gThumb = options.gThumb || null; this.opts = options.opts; this.gThumb.marker = this; } GMarkerHover.prototype = new GOverlay(); GMarkerHover.prototype.initialize = function(map) { var icon, img; this.map_ = map; icon = this.opts.createGIcon(this.image); icon.addEvent('mouseover', function (e) { GEvent.trigger(this, 'mouseover'); this.opts.gIconSwap(e.target, this.hoverImage); }.bindWithEvent(this)); icon.addEvent('mouseout', function (e) { GEvent.trigger(this, 'mouseout'); if (this.infoWindow) return; this.opts.gIconSwap(e.target, this.image); }.bindWithEvent(this)); icon.addEvent('click', function (e) { GEvent.trigger(this, 'click'); }.bindWithEvent(this)); map.getPane(G_MAP_MARKER_PANE).appendChild(icon); this.map_.addOverlay(this.gThumb); this.icon = icon; } GMarkerHover.prototype.trigger = function() { GEvent.trigger(this, 'click'); } GMarkerHover.prototype.remove = function() { } GMarkerHover.prototype.redraw = function(force) { if (!force) return; var p = this.map_.fromLatLngToDivPixel(this.point); var left = p.x - this.iconAnchor_x; var bottom = -p.y + (this.iconHeight - this.iconAnchor_y); this.icon.setStyles({ left: left + 'px', bottom: bottom + 'px' }); } GMarkerHover.prototype.copy = function() { } GMarkerHover.prototype.closeInfoWindow = function () { if (this.infoWindow) this.map_.removeOverlay(this.infoWindow); this.infoWindow = null; this.opts.gIconSwap(this.icon, this.image); GEvent.trigger(this, 'infowindowclose'); } GMarkerHover.prototype.openInfoWindow = function() { var infoWindow; if (this.infoWindow) return; infoWindow = new InfoWindow(this, {xmlURL: '../scripts/php/propertydata.php', propertyID: this.propertyID}); GEvent.bind(infoWindow, "close", this, this.closeInfoWindow); this.map_.addOverlay(infoWindow); this.infoWindow = infoWindow; this.opts.gIconSwap(this.icon, this.hoverImage); GEvent.trigger(this, 'infowindowopen'); } // ---------------------------------------------------------------------------------// // GThumb // ---------------------------------------------------------------------------------// function GThumb (opts) { this.marker = null; this.opts = opts; this.moreInfoLink = null; } GThumb.prototype = new GOverlay(); GThumb.prototype.initialize = function(map) { var div, content, img, a; this.map_ = map; /*
*/ content = new Element('div').addClass('gThumbContent'); content.adopt(new Element('img').setProperty('src', '../images/gthumb-' + this.marker.propertyID + '.gif')); this.moreInfoLink = new Element('a').setProperty('href', '#').appendText('click for more info').addEvent('click', function (e) { Window.stopEvent(e); this.marker.trigger(); }.bindWithEvent(this)); content.adopt(this.moreInfoLink); div = new Element('div').addClass('gThumb'); div.adopt(new Element('div').addClass('gThumbBackground')); div.adopt(content); div.setStyle('display', 'none'); div.addEvent('mouseover', function (e) { this.show(); }.bindWithEvent(this)); div.addEvent('mouseout', function (e) { this.hide(); }.bindWithEvent(this)); map.getPane(G_MAP_FLOAT_SHADOW_PANE).appendChild(div); this.div_ = div; } GThumb.prototype.remove = function() { this.div_.remove(); } GThumb.prototype.show = function() { clearInterval(this.hideInterval); this.div_.setStyle('display', 'block'); } GThumb.prototype.hide = function() { this.hideInterval = (function () { this.div_.setStyle('display', 'none'); }.bind(this)).delay(100); } GThumb.prototype.redraw = function(force) { if (!force) return; var point = this.marker.point; var p = this.map_.fromLatLngToDivPixel(point); var left = p.x - (120 / 2); var bottom = -p.y + 27; this.div_.style.left = left + "px"; this.div_.style.bottom = bottom + "px"; this.opts.gThumbRedraw(this.div_.getElement('.gThumbBackground')); } GThumb.prototype.copy = function() { } // ---------------------------------------------------------------------------------// // InfoWindow // ---------------------------------------------------------------------------------// function InfoWindow (marker, options) { this.marker = marker; this.propertyID = options.propertyID || ''; this.xmlURL = options.xmlURL || ''; } InfoWindow.prototype = new GOverlay(); InfoWindow.prototype.initialize = function(map) { var target, bg, content, closeBtn, shadow, complete, url, request; this.map_ = map; /* */ closeBtn = new Element('a').addClass('close'); content = new Element('div').addClass('infoWindowContent'); bg = new Element('div').addClass('infoWindowBackground'); target = new Element('div').addClass('infoWindow'); target.adopt(bg); target.adopt(content); shadow = new Element('div').addClass('infoWindowShadow'); closeBtn.addEvent('click', function (e) { e.stopPropagation(); GEvent.trigger(this, 'close'); }.bindWithEvent(this)); complete = function () { content.adopt(closeBtn); } url = this.xmlURL + '?id=' + this.propertyID; request = new Ajax(url, {onComplete: complete, update: content, method: 'get'}); request.request(); content.adopt(closeBtn); map.getPane(G_MAP_FLOAT_PANE).appendChild(target); map.getPane(G_MAP_FLOAT_SHADOW_PANE).appendChild(shadow); this.shadow = shadow; this.target = target; this.background = bg; } InfoWindow.prototype.remove = function() { this.target.remove(); this.shadow.remove(); //this = null; } InfoWindow.prototype.redraw = function(force) { if (!force) return; var p = this.map_.fromLatLngToDivPixel(this.marker.point); var left = p.x - 150; var bottom = -p.y + this.target.getStyle('height').toInt() + 27; this.target.setStyles({ left: left + 'px', bottom: bottom + 'px' }); this.shadow.setStyles({ left: (left - 9) + 'px', bottom: (bottom - 238 - 7) + 'px' }); var mapNE = this.map_.fromLatLngToDivPixel( this.map_.getBounds().getNorthEast() ); var mapSW = this.map_.fromLatLngToDivPixel( this.map_.getBounds().getSouthWest() ); var panX = 0; var panY = 0; if(this.target.offsetTop < mapNE.y) { panY = mapNE.y - this.target.offsetTop; } if(this.target.offsetLeft + this.target.getStyle('width').toInt() + 10 > mapNE.x) { panX = (this.target.offsetLeft + this.target.getStyle('width').toInt() + 10) - mapNE.x; } if (this.target.offsetLeft - 10 < mapSW.x) { panX = (this.target.offsetLeft - 30) - mapSW.x; } if(panX != 0 || panY != 0) { this.map_.panBy(new GSize(-panX - 10, panY + 30)); } this.marker.opts.infoWindowRedraw(this.shadow, this.background); } InfoWindow.prototype.copy = function() { }