var LEO_GOOGLE_MAP = new function() { this.geo; this.map; this.gdir; this.geocoder; this.addressMarker; this.trafficInfo; this.first_try = true; this.red_marker; this._venue_allocation; this.minLat; this.minLng; this.maxLat; this.maxLng; this._event; this.document; this.setEvent = function (document, event) { this.document = document; this._event = event; } this.setMarker = function (data) { try { var event = data.event; var teaserTextAttribute = "PR-Text"; var pictureAttribute = "MP-Bild-W-2"; for (i = 0; i < data.statusinfo.count; i++) { var lat = event[i].date[0].venue.venue_lat; var lon = event[i].date[0].venue.venue_lon; lat = lat + (Math.random() * 0.001); lon = lon + (Math.random() * 0.001); this.minLat = Math.min(minLat, lat - 0.01); this.minLng = Math.min(minLng, lon - 0.01); this.maxLat = Math.max(maxLat, lat + 0.01); this.maxLng = Math.max(maxLng, lon + 0.01); var id = event[i].event_id; var title = event[i].event_identifier; if (title == _event) { continue; } var staette = event[i].date[0].venue_allocation; var city = event[i].date[0].venue.venue_town; var postcode = event[i].date[0].venue.venue_postcode; var street = event[i].date[0].venue.venue_street; var house_nr = event[i].date[0].venue.venue_house_number; if (street != null) { if (house_nr != null) { street += " " + house_nr; } } else { street = ""; } var text = event[i].event_description; if (text == null) { if (event[i].textsystem != null && event[i].textsystem[teaserTextAttribute] != null) { text = event[i].textsystem[teaserTextAttribute].txt_content; } } if (text == null) { text = ""; } text.replace("
", ""); text = text.substring(0, 150) + '...'; street = street.substring(0, 28); staette = staette.substring(0, 28); title = title.substring(0, 40); var start = event[i].date[0].date_start; if (start.indexOf(" 00:00") != -1) { start = start.replace(" 00:00", ""); } else { start += ' Uhr'; } var ende = event[i].date[0].date_end; if (ende == null) { ende = event[i].date[0].date_start; } if (ende.indexOf(" 23:59") != -1) { ende = ende.replace(" 23:59", ""); } else { ende += ' Uhr'; } if (start == ende) { start += '
'; ende = ""; } else { start += ' -
'; } var bild = 'https://termine.mainpost.de/img/icons/veranstaltung.gif'; if (event[i].attributes != null && event[i].attributes[pictureAttribute] != null) { bild = event[i].attributes[pictureAttribute]; bild = bild.replace("width", "_w"); bild = bild.replace("height", "_h"); bild += '&width=120&height=-1'; } var html = '
'; html += ''; html += ''; html += ''; html += ''; html += ''; html += ''; html += ''; html += ''; html += ''; html += '

' + title + '

'; html += '

' + text + 'mehr

'; html += '
WannWo
' + start + ende + '' + staette + '
' + street + '
'; html += '
'; this.addMarker(lat, lon, html); } } catch (e) { } } this.searchAndAddMarker = function (search_string, html) { if (this.geo == null) { this.geo = new google.maps.Geocoder(); } this.geo.geocode( { 'address': search_string}, function(results, status) { // If that was successful if (status == google.maps.GeocoderStatus.OK) { var p = new Array(); p[0] = results[0].geometry.location.lng(); p[1] = results[0].geometry.location.lat(); this.addMarker(p[1], p[0], html); } }); } this.showAddress = function (place, city, postcode, street, house_nr, venue_allocation) { this._venue_allocation = venue_allocation if (this.geo == null) { this.geo = new google.maps.Geocoder(); } this._place = place; // ====== Perform the Geocoding ====== this.geo.geocode({ 'address': city + ' ' + postcode + ' ' + street + ' ' + house_nr}, function(results, status) { // If that was successful if (status == google.maps.GeocoderStatus.OK) { var p = new Array(); p[0] = results[0].geometry.location.lng(); p[1] = results[0].geometry.location.lat(); var options = { zoom: 15, center: results[0].geometry.location, mapTypeId: google.maps.MapTypeId.ROADMAP } map = new google.maps.Map(this.document.getElementById("leo_google_map"), options); // Traffic-Infos var trafficLayer = new google.maps.TrafficLayer(); trafficLayer.setMap(map); var point = new google.maps.Point(p[0], p[1]); var image = 'https://termine.mainpost.de/img/gmap_marker.png' this.red_marker = new google.maps.Marker({ position: results[0].geometry.location, draggable:false, animation: google.maps.Animation.DROP, title: city + ' ' + postcode + ' ,' + street + ' ' + house_nr, icon: image }); this.red_marker.setMap(map); var content_infoWindow = '
' + '
' + venue_allocation + '
'; var infowindow = new google.maps.InfoWindow({ content: content_infoWindow, maxWidth: 350 }); infowindow.open(map,this.red_marker); google.maps.event.addListener(infowindow, 'domready', function() { // Reference to the DIV which receives the contents of the infowindow using jQuery var iwOuter = jQuery('.gm-style-iw'); /* The DIV we want to change is above the .gm-style-iw DIV. * So, we use jQuery and create a iwBackground variable, * and took advantage of the existing reference to .gm-style-iw for the previous DIV with .prev(). */ var iwBackground = iwOuter.prev(); var iwNext = iwOuter.next(); // add class to the white background DIV iwBackground.children(':nth-child(4)').addClass('custom_iw_4'); iwBackground.children(':nth-child(1)').addClass('custom_iw_1'); iwBackground.children(':nth-child(2)').addClass('custom_iw_2'); iwBackground.children(':nth-child(3)').addClass('custom_iw_3'); //hide close-icon iwNext.css({'opacity' : '1'}); }); google.maps.event.addListener(red_marker, "click", function (e) { infowindow.open(map, red_marker); }); this.minLat = p[1] - 0.01; this.minLng = p[0] - 0.01; this.maxLat = p[1] + 0.01; this.maxLng = p[0] + 0.01; // Collecting Geodata //console.log(results[0]); country = results[0].address_components[5].short_name; if (results[0].address_components != null) { if (results[0].address_components[8] != null) { postcode = results[0].address_components[8].short_name; } if (results[0].address_components[4] != null) { city = results[0].address_components[4].long_name; } } var service = "http://termine.mainpost.de:80/leoonline/JSONClientServlet?request=demo_geodata_collecting"; var args = "&z1=" + postcode + "&z2=" + city + "&z3=" + country + "&z4=" + place + "&z5=" + street + "&z6=" + house_nr + "&z7=" + p[0] + "&z8=" + p[1]; //jQuery.get(service + args); service = "http://termine.mainpost.de:80/leoonline/JSONClientServlet?request=evt_poi_search"; args = "&z1=" + escape(p[0] + " " + p[1]) + "&z2=5" + "&z3=max_rows:100&z4=filter:date_in_format:dd.MM.yyyy HH:mm"; //jQuery.getJSON(service + args, setMarker); } else { if (first_try) { first_try = false; this.showAddress('', city, postcode, '', ''); return; } var container = document.getElementById("evt_details"); var google_div = document.getElementById("leo_google_map"); container.removeChild(google_div); } } ); } this.addMarker = function (lat, lon, html) { var point = new google.maps.LatLng(lat, lon); var icon = "https://maps.google.com/mapfiles/marker_green.png"; var shadow = new google.maps.MarkerImage('https://maps.gstatic.com/mapfiles/shadow50.png', new google.maps.Size(53, 32), new google.maps.Point(0,0), new google.maps.Point(12, 32)); var marker = new google.maps.Marker({ position: point, animation: google.maps.Animation.DROP, icon: icon, shadow: shadow, map: this.map }); var infoWindow = new google.maps.InfoWindow(); infoWindow.setPosition(point); infoWindow.setContent(html); google.maps.event.addListener(marker, 'click', function () { infoWindow.open(this.map); }); } }