var Bizgaze; (function (Bizgaze) { let Apps; (function (Apps) { let Support; (function (Support) { let Controls; (function (Controls) { class SupportMap extends Unibase.Platform.Core.BaseComponent { init(formpropertyid, prop, callback) { var _id = $(".formValidate:visible").attr("id"); var slt = _id.split('_'); var map11 = $('#locationcontrol_' + formpropertyid); map11.geocomplete({ details: "form.form_" + slt[1] }); var instance = this; instance.loadControlSettings(prop.ControlJsonText, prop.FormPropertyId); instance.loadPropertySettings(prop.PropertySettings, prop.FormPropertyId); } loadControl(containerid, prop) { var instance = this; var regExpr = ""; var ErrMsg = ""; var Isrequired = prop.IsRequired != true ? 'hidden' : ''; var required = prop.IsRequired != true ? '' : 'required'; var html = '
' + '' + ' ' + 'Capture Location' + '
' + '
' + '
' + '' + '' + '' + ''; $("#" + containerid).html(html); var latd = 0; var lgtd = 0; $('#hfLattitude').val(latd); $('#hfLongitude').val(lgtd); $("#lbl_coordinates").html("latd : " + latd + ", lgtd : " + lgtd); Bizgaze.Apps.Support.Controls.SupportMap.Instance().loadMap(latd, lgtd, prop.FormPropertyId); } loadMap(latd, lgtd, formpropertyid) { var instance = this; var myLatlng = new google.maps.LatLng(latd, lgtd); var mapOptions = { zoom: 15, center: myLatlng, }; var map = new google.maps.Map(document.getElementById("meetingAddressMap"), mapOptions); var marker = new google.maps.Marker({ position: myLatlng, title: "Hello World!", }); marker.setMap(map); var url = "https://maps.googleapis.com/maps/api/geocode/json?latlng=" + latd + "," + lgtd + "&key=" + _mapsettings.key() + "&sensor=false"; var xhr = Bizgaze.Apps.Support.Controls.SupportMap.Instance().createCORSRequest2('Get', url); if (!xhr) { bootbox.alert('CORS not supported'); return; } xhr.onload = function () { var text = xhr.responseText; var json = JSON.parse(text); instance.addressData = []; instance.addressData = json.results; $("#locationcontrol_" + formpropertyid).val(json.results[0].formatted_address); }; xhr.onerror = function () { bootbox.alert('Woops, there was an error making the request.'); }; } getAddressLocation(Id) { var instance = this; var ac = eval('new google.maps.places.Autocomplete((document.getElementById("locationcontrol_" + Id)), {types: ["geocode"]});'); ac.addListener('place_changed', function () { var geocoder = new google.maps.Geocoder(); setTimeout(function () { var address = document.getElementById('locationcontrol_' + Id); address.value; geocoder.geocode({ 'address': address.value }, function (results, status) { if (status == google.maps.GeocoderStatus.OK) { var latitude = results[0].geometry.location.lat(); var longitude = results[0].geometry.location.lng(); $('#hfLattitude').val(latitude); $('#hfLongitude').val(longitude); var latd = latitude; var lgtd = longitude; $("#lbl_coordinates").html("latd : " + latd + ", lgtd : " + lgtd); Bizgaze.Apps.Support.Controls.SupportMap.Instance().loadMap(latd, lgtd, Id); } }); }, 500); }); } getReverseGeocodingData(lat, lng, formpropertyid) { var instance = this; var latlng = new google.maps.LatLng(lat, lng); var geocoder = new google.maps.Geocoder(); geocoder.geocode({ 'location': latlng }, function (results, status) { if (status !== google.maps.GeocoderStatus.OK) { alert(status); } if (status == google.maps.GeocoderStatus.OK) { console.log(results); var address = (results[1].formatted_address); $("#locationcontrol_" + formpropertyid).val(address); } }); } getLocation(formpropertyid) { if (navigator.geolocation) { navigator.geolocation.getCurrentPosition(function (position) { $("#hfLattitude").val(position.coords.latitude); $("#hfLongitude").val(position.coords.longitude); Bizgaze.Apps.Support.Controls.SupportMap.Instance().showPosition(formpropertyid, position); }); } else { bootbox.alert("Geolocation is not supported by this browser."); } } showPosition(formpropertyid, position) { $("#hfLattitude").val(position.coords.latitude); $("#hfLongitude").val(position.coords.longitude); $("#lbl_coordinates").html("latd : " + position.coords.latitude + ", lgtd : " + position.coords.longitude); Bizgaze.Apps.Support.Controls.SupportMap.Instance().loadMap(position.coords.latitude, position.coords.longitude, formpropertyid); Bizgaze.Apps.Support.Controls.SupportMap.Instance().getReverseGeocodingData(position.coords.latitude, position.coords.longitude, formpropertyid); } mapControlObj(formpropertyid) { var instance = this; var mapEntries = new Array(); mapEntries.push({ Latitude: $('#hfLattitude').val(), Longitude: $("#hfLongitude").val(), }); return mapEntries; } createCORSRequest2(method, url) { let XDomainRequest; var xhr = new XMLHttpRequest(); if ("withCredentials" in xhr) { xhr.open(method, url, true); } else if (typeof XDomainRequest != "undefined") { xhr = new XDomainRequest(); xhr.open(method, url); } else { xhr = null; } return xhr; } loadControlSettings(controlsettingjson, formpropertyid) { return null; } loadPropertySettings(propertysettings, formpropertyid) { return null; } bindEditFormDetails(formpropertyid, propval, DocPropertyName) { return null; } static Instance() { if (this.instance === undefined) { this.instance = new SupportMap(); } return this.instance; } } Controls.SupportMap = SupportMap; })(Controls = Support.Controls || (Support.Controls = {})); })(Support = Apps.Support || (Apps.Support = {})); })(Apps = Bizgaze.Apps || (Bizgaze.Apps = {})); })(Bizgaze || (Bizgaze = {}));