2022-11-16 01:44:39 +00:00
|
|
|
import './style.scss';
|
2015-01-23 13:09:30 +00:00
|
|
|
|
|
|
|
var gmapsIsLoaded = false;
|
|
|
|
|
2022-11-16 01:44:39 +00:00
|
|
|
export default new Class({
|
|
|
|
Extends: Hedera.Form,
|
|
|
|
Template: require('./ui.xml')
|
2015-01-23 13:09:30 +00:00
|
|
|
|
2015-01-31 01:05:12 +00:00
|
|
|
,locations: null
|
|
|
|
|
2022-11-16 01:46:44 +00:00
|
|
|
,activate() {
|
2018-08-31 06:14:47 +00:00
|
|
|
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';
|
2018-08-31 06:14:47 +00:00
|
|
|
this.conn.execQuery(sql, this.onLocationsDone.bind(this));
|
2015-01-23 13:09:30 +00:00
|
|
|
|
2018-08-31 06:14:47 +00:00
|
|
|
if (!gmapsIsLoaded) {
|
|
|
|
gmapsLoadedCallback = this.gmapsLoaded.bind(this);
|
|
|
|
Vn.includeJs('https://maps.google.com/maps/api/js'
|
|
|
|
+'?sensor=false&callback=gmapsLoadedCallback'
|
|
|
|
+'&key=AIzaSyBbunFsAFEkjtw-c7BUHNgkThSlKEKFxiE',
|
|
|
|
null, true
|
|
|
|
);
|
|
|
|
} else
|
|
|
|
this.gmapsLoaded();
|
2015-01-23 13:09:30 +00:00
|
|
|
}
|
|
|
|
|
2022-11-16 01:46:44 +00:00
|
|
|
,onLocationsDone(resultSet) {
|
2022-05-28 15:49:46 +00:00
|
|
|
this.locations = resultSet.fetchData();
|
2018-08-31 06:14:47 +00:00
|
|
|
this.allLoaded();
|
2015-01-31 01:05:12 +00:00
|
|
|
}
|
|
|
|
|
2022-11-16 01:46:44 +00:00
|
|
|
,gmapsLoaded() {
|
2018-08-31 06:14:47 +00:00
|
|
|
this.gui.loaderPop();
|
2015-01-23 13:09:30 +00:00
|
|
|
gmapsIsLoaded = true;
|
2018-08-31 06:14:47 +00:00
|
|
|
this.allLoaded();
|
2015-01-31 01:05:12 +00:00
|
|
|
}
|
|
|
|
|
2022-11-16 01:46:44 +00:00
|
|
|
,allLoaded() {
|
2015-01-31 01:05:12 +00:00
|
|
|
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
|
2018-08-31 06:14:47 +00:00
|
|
|
,center: new google.maps.LatLng(46.0, 4.0)
|
2015-01-23 13:09:30 +00:00
|
|
|
};
|
|
|
|
|
2022-05-28 01:18:06 +00:00
|
|
|
var div = this.$.form;
|
2018-08-31 06:14:47 +00:00
|
|
|
var gmap = new google.maps.Map(div, options);
|
2015-01-23 13:09:30 +00:00
|
|
|
|
2022-05-28 15:49:46 +00:00
|
|
|
for (const location of this.locations)
|
|
|
|
this.createMarker(location, gmap);
|
2015-01-23 13:09:30 +00:00
|
|
|
}
|
|
|
|
|
2022-11-16 01:46:44 +00:00
|
|
|
,createMarker(location, gmap) {
|
2018-08-31 06:14:47 +00:00
|
|
|
var div = document.createElement('div');
|
2015-01-31 01:05:12 +00:00
|
|
|
div.className = 'marker';
|
2015-01-23 13:09:30 +00:00
|
|
|
|
2018-08-31 06:14:47 +00:00
|
|
|
var h = document.createElement('h3');
|
2022-05-28 15:49:46 +00:00
|
|
|
h.appendChild(document.createTextNode(location.title));
|
2018-08-31 06:14:47 +00:00
|
|
|
div.appendChild(h);
|
2015-01-23 13:09:30 +00:00
|
|
|
|
2018-08-31 06:14:47 +00:00
|
|
|
var p = document.createElement('p');
|
2022-05-28 15:49:46 +00:00
|
|
|
p.appendChild(document.createTextNode(location.address));
|
2018-08-31 06:14:47 +00:00
|
|
|
div.appendChild(p);
|
2015-01-31 01:05:12 +00:00
|
|
|
|
2018-08-31 06:14:47 +00:00
|
|
|
var p = document.createElement('p');
|
2022-05-28 15:49:46 +00:00
|
|
|
p.appendChild(document.createTextNode(location.postcode +' '+ location.city));
|
2018-08-31 06:14:47 +00:00
|
|
|
div.appendChild(p);
|
2015-01-31 01:05:12 +00:00
|
|
|
|
2018-08-31 06:14:47 +00:00
|
|
|
var p = document.createElement('p');
|
2022-05-28 15:49:46 +00:00
|
|
|
p.appendChild(document.createTextNode(location.province));
|
2018-08-31 06:14:47 +00:00
|
|
|
div.appendChild(p);
|
2015-01-31 01:05:12 +00:00
|
|
|
|
2018-08-31 06:14:47 +00:00
|
|
|
var p = document.createElement('p');
|
2022-05-28 15:49:46 +00:00
|
|
|
p.appendChild(document.createTextNode(location.phone));
|
2018-08-31 06:14:47 +00:00
|
|
|
div.appendChild(p);
|
2015-01-23 13:09:30 +00:00
|
|
|
|
2018-08-31 06:14:47 +00:00
|
|
|
var lat = new google.maps.LatLng(
|
2022-05-28 15:49:46 +00:00
|
|
|
location.lat,
|
|
|
|
location.lng
|
2015-01-31 01:05:12 +00:00
|
|
|
);
|
2015-01-23 13:09:30 +00:00
|
|
|
|
2018-08-31 06:14:47 +00:00
|
|
|
var marker = new google.maps.Marker({
|
2015-01-23 13:09:30 +00:00
|
|
|
position: lat
|
|
|
|
,tilte: location.title
|
|
|
|
,map: gmap
|
|
|
|
});
|
|
|
|
|
2018-08-31 06:14:47 +00:00
|
|
|
var infoWindow = new google.maps.InfoWindow({
|
2015-01-23 13:09:30 +00:00
|
|
|
content: div
|
|
|
|
});
|
|
|
|
|
2018-08-31 06:14:47 +00:00
|
|
|
google.maps.event.addListener(marker, 'click',
|
|
|
|
this.openInfoWindow.bind(this, infoWindow, gmap, marker));
|
2015-01-23 13:09:30 +00:00
|
|
|
|
2015-01-31 01:05:12 +00:00
|
|
|
if (Vn.Locale.language
|
2022-05-28 15:49:46 +00:00
|
|
|
&& Vn.Locale.language == location.language)
|
2018-08-31 06:14:47 +00:00
|
|
|
this.openInfoWindow(infoWindow, gmap, marker);
|
2015-01-23 13:09:30 +00:00
|
|
|
}
|
|
|
|
|
2022-11-16 01:46:44 +00:00
|
|
|
,openInfoWindow(infoWindow, gmap, marker) {
|
2015-01-23 13:09:30 +00:00
|
|
|
if (this.openedWindow)
|
2018-08-31 06:14:47 +00:00
|
|
|
this.openedWindow.close();
|
2015-01-23 13:09:30 +00:00
|
|
|
|
2018-08-31 06:14:47 +00:00
|
|
|
infoWindow.open(gmap, marker);
|
2015-01-23 13:09:30 +00:00
|
|
|
this.openedWindow = infoWindow;
|
|
|
|
}
|
|
|
|
});
|