/**
* Handle: wpGoogleMaps
* Version: 0.0.1
* Deps: prototype,googleMaps
* Enqueue: true
*/
var wpGoogleMaps = Class.create();
wpGoogleMaps.prototype = {
directions : '',
map : {},
initialize : function() {
this.geocoder = new GClientGeocoder();
this.directions = new Template(
'
'
);
},
getDirections : function (f)
{
var cur_addr = f.cur_addr.value;
var new_addr = f.new_addr.value;
if (f.toFrom.value == 'To') {
var mapString = "from: " + new_addr + " to: " + cur_addr;
} else {
var mapString = "from: " + cur_addr + " to: " + new_addr;
}
this.map[f.mapNum.value]['gdir'].load(mapString);
this.map[f.mapNum.value]['map'].closeInfoWindow();
return false;
},
showDirections : function(toFrom, mapNum) {
var info = {'toFrom':toFrom, 'mapNum':mapNum};
info.name = this.map[mapNum]['mapInfo'].get('name');
info.lat = this.map[mapNum]['mapInfo'].get('point').lat();
info.lng = this.map[mapNum]['mapInfo'].get('point').lng();
if (toFrom == 'To' && this.map[mapNum]['mapInfo'].get('directions_from')) {
info.dirLink = ' - From here'
}
if (toFrom == 'From' && this.map[mapNum]['mapInfo'].get('directions_to')) {
info.dirLink = ' - To here'
}
this.updateInfoWindow(mapNum, this.directions.evaluate(info));
},
updateInfoWindow : function(mapNum, html) {
wpGMaps.map[mapNum]['html'] = html;
if (!this.map[mapNum]['mapInfo'].get('name')) {
this.map[mapNum]['mapInfo'].set('name', '');
this.map[mapNum]['nameTag'] = '';
} else {
this.map[mapNum]['nameTag'] = '' + this.map[mapNum]['mapInfo'].get('name') + '
';
}
html = this.map[mapNum]['nameTag'] + this.map[mapNum]['mapInfo'].get('description') + '
' + html;
this.map[mapNum]['marker'].openInfoWindowHtml(html);
},
wpNewMap : function(mapNum, mapInfo)
{
if (this.geocoder) {
if (!this.map[mapNum]) {
this.map[mapNum] = {};
}
this.map[mapNum]['mapInfo'] = $H(mapInfo);
var address = this.map[mapNum]['mapInfo'].get('address');
var name = this.map[mapNum]['mapInfo'].get('name');
if (!this.map[mapNum]['mapInfo'].get('description')) {
this.map[mapNum]['mapInfo'].set('description', address);
}
var wpGMaps = this;
this.map[mapNum]['map'] = new GMap2($('map_' + mapNum));
if (this.map[mapNum]['mapInfo'].get('zoompancontrol')) {
this.map[mapNum]['map'].addControl(new GLargeMapControl());
}
if (this.map[mapNum]['mapInfo'].get('typecontrol')) {
this.map[mapNum]['map'].addControl(new GMapTypeControl());
}
if (this.map[mapNum]['mapInfo'].get('mousewheel')) {
this.map[mapNum]['map'].enableScrollWheelZoom();
}
this.map[mapNum]['gdir'] = new GDirections(this.map[mapNum]['map'], $('dir_' + mapNum));
this.geocoder.getLatLng(
address,
function(point) {
if (!point) {
alert("There was an error polling the Google Servers for " + address + ".\nPlease try again.")
} else {
wpGMaps.map[mapNum]['mapInfo'].set('point', point);
wpGMaps.map[mapNum]['map'].setCenter(point, 13);
wpGMaps.map[mapNum]['marker'] = new GMarker(point);
GEvent.addListener(wpGMaps.map[mapNum]['marker'], "click", function() {
if (wpGMaps.map[mapNum]['map'].getInfoWindow().isHidden()) {
wpGMaps.updateInfoWindow(mapNum, wpGMaps.map[mapNum]['html']);
}
});
wpGMaps.map[mapNum]['map'].addOverlay(wpGMaps.map[mapNum]['marker']);
if (wpGMaps.map[mapNum]['mapInfo'].get('directions_to') && wpGMaps.map[mapNum]['mapInfo'].get('directions_from')) {
var html = 'Directions: ' +
'To here - ' +
'From here' +
'
';
wpGMaps.updateInfoWindow(mapNum, html);
} else if (wpGMaps.map[mapNum]['mapInfo'].get('directions_to')){
wpGMaps.showDirections('To', mapNum);
} else if (wpGMaps.map[mapNum]['mapInfo'].get('directions_from')){
wpGMaps.showDirections('From', mapNum);
} else {
wpGMaps.updateInfoWindow(mapNum, '');
}
}
}
);
}
}
}
var wpGMaps = new wpGoogleMaps();
new Event.observe(window, 'unload', GUnload);