hedera-web/forms/cms/location/index.js

104 lines
2.4 KiB
JavaScript
Raw Normal View History

2022-11-16 01:44:39 +00:00
import './style.scss';
var gmapsIsLoaded = false;
2022-11-16 01:44:39 +00:00
export default new Class({
Extends: Hedera.Form,
Template: require('./ui.xml')
2015-01-31 01:05:12 +00:00
,locations: null
2022-11-28 08:51:31 +00:00
,async 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';
2022-11-28 08:51:31 +00:00
const resultSet = await this.conn.execQuery(sql);
this.locations = resultSet.fetchData();
2018-08-31 06:14:47 +00:00
if (!gmapsIsLoaded) {
2022-11-29 18:13:32 +00:00
window.gmapsLoadedCallback = () => this.gmapsLoaded();
2018-08-31 06:14:47 +00:00
Vn.includeJs('https://maps.google.com/maps/api/js'
+'?sensor=false&callback=gmapsLoadedCallback'
+'&key=AIzaSyBbunFsAFEkjtw-c7BUHNgkThSlKEKFxiE',
null, true
);
} else
this.gmapsLoaded();
}
2022-11-16 01:46:44 +00:00
,gmapsLoaded() {
2018-08-31 06:14:47 +00:00
this.gui.loaderPop();
gmapsIsLoaded = true;
2015-01-31 01:05:12 +00:00
if (!this.locations || !gmapsIsLoaded)
return;
var options = {
2015-03-06 23:33:54 +00:00
zoom: 4
,mapTypeId: google.maps.MapTypeId.ROADMAP
2018-08-31 06:14:47 +00:00
,center: new google.maps.LatLng(46.0, 4.0)
};
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);
2022-05-28 15:49:46 +00:00
for (const location of this.locations)
this.createMarker(location, gmap);
}
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';
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);
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);
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
);
2018-08-31 06:14:47 +00:00
var marker = new google.maps.Marker({
position: lat
,tilte: location.title
,map: gmap
});
2018-08-31 06:14:47 +00:00
var infoWindow = new google.maps.InfoWindow({
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-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);
}
2022-11-16 01:46:44 +00:00
,openInfoWindow(infoWindow, gmap, marker) {
if (this.openedWindow)
2018-08-31 06:14:47 +00:00
this.openedWindow.close();
2018-08-31 06:14:47 +00:00
infoWindow.open(gmap, marker);
this.openedWindow = infoWindow;
}
});