class GoogleMaps{
constructor(map, key, place){
// Initialisierung
this._googleMapsCookieName = 'GoogleMapsAllowed';
this._place = '';
this._key = '';
this._iframe = '';
this._acceptHTML = '
' +
'' +
'Bei der Verwendung von Google-Maps könnten Daten an Google übertragen werden.
' +
'Bitte klicken Sie hier damit die Karte aktiviert wird.
' +
'Näheres zu diesem Thema finden Sie in der Datenschutzerklärung' +
'' +
'
';
// Map festlegen
this._map = $(map).length > 0 ? map : $('#' + map);
// Werte setzen
this.setKey(key);
this.setPlace(place)
var self = this;
// Den Klick zum akzeptieren abfangen
if(typeof $(this).on != 'undefined'){
$(this._map).on({
'click': function(){self.accept();}
}, '.mapAccept');
}
else{
$(this._map).find('.mapAccept').live('click', function(e){
self.accept();
});
}
}
show(){
var html = this._acceptHTML;
if(this.googleAllowed()){
html = this.getIframe();
}
$(this._map).html(html);
}
setKey(key){
this._key = key;
}
getKey(){
return this._key;
}
setPlace(place){
this._place = place;
}
getPlace(){
return this._place;
}
googleAllowed(){
return GoogleMaps.getCookie(this._googleMapsCookieName) == 1;
}
getIframe(){
return this._iframe.replace(/{KEY}/ig, this.getKey()).replace(/{PLACE}/ig, this.getPlace());
}
// Akzeptiert die Datenschutzbedingung
accept(){
GoogleMaps.setCookie(this._googleMapsCookieName, 1, 365);
this.show();
}
static getCookie(cname) {
var name = cname + "=";
var decodedCookie = decodeURIComponent(document.cookie);
var ca = decodedCookie.split(';');
for(var i = 0; i < ca.length; i++) {
var c = ca[i];
while (c.charAt(0) == ' ') {
c = c.substring(1);
}
if (c.indexOf(name) == 0) {
return c.substring(name.length, c.length);
}
}
return "";
}
static setCookie(cname, cvalue, exdays) {
var d = new Date();
d.setTime(d.getTime() + (exdays*24*60*60*1000));
var expires = "expires="+ d.toUTCString();
document.cookie = cname + "=" + cvalue + ";" + expires + ";path=/";
}
}
$(window).load(function(){
var map1 = new GoogleMaps('anfahrtGMap', 'AIzaSyCvv8VwVkOa_VFwbCJWehdjGDMkSnzmx94', 'IDS%20GmbH%20%26%20Co.%20KG%2C%20Holzwiese%209%2C%2088267%20Vogt');
map1.show();
});