2015-01-23 13:09:30 +00:00
|
|
|
|
|
|
|
var gmapsIsLoaded = false;
|
|
|
|
|
|
|
|
Vn.Location = new Class
|
|
|
|
({
|
|
|
|
Extends: Vn.Module
|
|
|
|
|
2015-01-31 01:05:12 +00:00
|
|
|
,locations: null
|
|
|
|
|
2015-01-23 13:09:30 +00:00
|
|
|
,activate: function ()
|
|
|
|
{
|
|
|
|
this.gui.loaderPush ();
|
2015-01-31 01:05:12 +00:00
|
|
|
|
|
|
|
var sql = 'SELECT lat, lng, title, address, postcode, city, province, phone, language FROM location';
|
|
|
|
this.conn.execQuery (sql, this.onLocationsDone.bind (this));
|
2015-01-23 13:09:30 +00:00
|
|
|
|
|
|
|
if (!gmapsIsLoaded)
|
|
|
|
{
|
|
|
|
gmapsLoadedCallback = this.gmapsLoaded.bind (this);
|
|
|
|
Vn.includeJs ('https://maps.google.com/maps/api/js'+
|
|
|
|
'?sensor=false&callback=gmapsLoadedCallback', null, true);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
this.gmapsLoaded ();
|
|
|
|
}
|
|
|
|
|
2015-01-31 01:05:12 +00:00
|
|
|
,onLocationsDone: function (resultSet)
|
|
|
|
{
|
|
|
|
this.locations = resultSet.fetchResult ();
|
|
|
|
this.allLoaded ();
|
|
|
|
}
|
|
|
|
|
2015-01-23 13:09:30 +00:00
|
|
|
,gmapsLoaded: function ()
|
|
|
|
{
|
|
|
|
this.gui.loaderPop ();
|
|
|
|
gmapsIsLoaded = true;
|
2015-01-31 01:05:12 +00:00
|
|
|
this.allLoaded ();
|
|
|
|
}
|
|
|
|
|
|
|
|
,allLoaded: function ()
|
|
|
|
{
|
|
|
|
if (!this.locations || !gmapsIsLoaded)
|
|
|
|
return;
|
2015-01-23 13:09:30 +00:00
|
|
|
|
|
|
|
var options = {
|
2015-03-06 23:33:54 +00:00
|
|
|
zoom: 4
|
2015-01-23 13:09:30 +00:00
|
|
|
,mapTypeId: google.maps.MapTypeId.ROADMAP
|
|
|
|
,center: new google.maps.LatLng (46.0, 4.0)
|
|
|
|
};
|
|
|
|
|
2015-03-06 23:33:54 +00:00
|
|
|
var div = this.$('form');
|
2015-01-23 13:09:30 +00:00
|
|
|
var gmap = new google.maps.Map (div, options);
|
|
|
|
|
2015-01-31 01:05:12 +00:00
|
|
|
if (this.locations)
|
|
|
|
while (this.locations.next ())
|
|
|
|
this.createMarker (this.locations, gmap);
|
2015-01-23 13:09:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
,createMarker: function (location, gmap)
|
|
|
|
{
|
|
|
|
var div = document.createElement ('div');
|
2015-01-31 01:05:12 +00:00
|
|
|
div.className = 'marker';
|
2015-01-23 13:09:30 +00:00
|
|
|
|
|
|
|
var h = document.createElement ('h3');
|
2015-01-31 01:05:12 +00:00
|
|
|
h.appendChild (document.createTextNode (location.get ('title')));
|
2015-01-23 13:09:30 +00:00
|
|
|
div.appendChild (h);
|
|
|
|
|
2015-01-31 01:05:12 +00:00
|
|
|
var p = document.createElement ('p');
|
|
|
|
p.appendChild (document.createTextNode (location.get ('address')));
|
|
|
|
div.appendChild (p);
|
|
|
|
|
|
|
|
var p = document.createElement ('p');
|
|
|
|
p.appendChild (document.createTextNode (location.get ('postcode') +' '+ location.get ('city')));
|
|
|
|
div.appendChild (p);
|
|
|
|
|
|
|
|
var p = document.createElement ('p');
|
|
|
|
p.appendChild (document.createTextNode (location.get ('province')));
|
|
|
|
div.appendChild (p);
|
|
|
|
|
|
|
|
var p = document.createElement ('p');
|
|
|
|
p.appendChild (document.createTextNode (location.get ('phone')));
|
|
|
|
div.appendChild (p);
|
2015-01-23 13:09:30 +00:00
|
|
|
|
|
|
|
var lat = new google.maps.LatLng (
|
2015-01-31 01:05:12 +00:00
|
|
|
location.get ('lat'),
|
|
|
|
location.get ('lng')
|
|
|
|
);
|
2015-01-23 13:09:30 +00:00
|
|
|
|
|
|
|
var marker = new google.maps.Marker ({
|
|
|
|
position: lat
|
|
|
|
,tilte: location.title
|
|
|
|
,map: gmap
|
|
|
|
});
|
|
|
|
|
|
|
|
var infoWindow = new google.maps.InfoWindow ({
|
|
|
|
content: div
|
|
|
|
});
|
|
|
|
|
|
|
|
google.maps.event.addListener (marker, 'click',
|
|
|
|
this.openInfoWindow.bind (this, infoWindow, gmap, marker));
|
|
|
|
|
2015-01-31 01:05:12 +00:00
|
|
|
if (Vn.Locale.language
|
|
|
|
&& Vn.Locale.language == location.get ('language'))
|
2015-01-23 13:09:30 +00:00
|
|
|
this.openInfoWindow (infoWindow, gmap, marker);
|
|
|
|
}
|
|
|
|
|
|
|
|
,openInfoWindow: function (infoWindow, gmap, marker)
|
|
|
|
{
|
|
|
|
if (this.openedWindow)
|
|
|
|
this.openedWindow.close ();
|
|
|
|
|
|
|
|
infoWindow.open (gmap, marker);
|
|
|
|
this.openedWindow = infoWindow;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|