123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178 |
- 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 = '<style type="text/css">.pac-container{z-index:1100 !important;}</style><div class="row"><div class="div_map_meeting hidden" ></div><div class="col-sm-12"><label for="lbl" id="lbl_' + prop.DocPropertyName + '" class="text-secondary" style="margin-bottom:0px;" >' + prop.LabelName + '<span class="text-danger ' + Isrequired + '" id="spnIsRequired_' + prop.DocPropertyId + '"> *</span></label><div class="input-group floating-label-form-group floating-label-form-group-with-value border-left-0" style="padding-left:0px">' +
- '<span class="input-group-addon bg-white no-border mt-10"><i class="text-success fa fa-map-marker pull-left"></i></span>' +
- '<input type="text" id="locationcontrol_' + prop.FormPropertyId + '" class="form-control ' + required + '" data-isdefault="' + prop.IsDefault + '" data-propdoctypename="' + prop.DocTypeName + '" data-required="' + prop.IsRequired + '" data-regularexp="' + regExpr + '" data-validatemsg="' + ErrMsg + '" placeholder="' + prop.Placeholder + '" data-placeholder="' + prop.Placeholder + '" data-label="' + prop.LabelName + '" onkeypress="Bizgaze.Apps.Support.Controls.SupportMap.Instance().getAddressLocation(' + prop.FormPropertyId + ')"> ' +
- '<a href="javascript:;" style="font-size: 14px;" class="btn btn-success mb-1" onclick="Bizgaze.Apps.Support.Controls.SupportMap.Instance().getLocation(' + prop.FormPropertyId + ')">Capture Location</a>' +
- '<input type="hidden" id="hfId" value=""><label for="Validation" id="lblValidation_' + prop.DocPropertyName + '"></label><input type="hidden" id="hfFormPropertyId" value=""></div></div>' +
- '<div class="col-sm-2 mt-25 hidden" style="padding:0px">' +
- '<a href="javascript:;" class="btn btn-success mb-1" onclick="_bizgaze_control_Location.getLocation()">Capture Location</a>' +
- '<button type="button" class="btn btn-success hidden" onclick="_bizgaze_control_Location.getMobileLocation()">Capture Location</button>' +
- '</div></div><div id="meetingAddressMap" class="text-center b-a" style="height: 250px"></div>' +
- '<div class="coordinates"><span id="lbl_coordinates"></span></div><input type="hidden" id="hfLattitude" name="lat" value="">' +
- '<input type ="hidden" id = "hfLongitude" name = "lng" value = "" >' +
- '<input type="hidden" id="hdn_locationcontrol" class="value-control" value="Bizgaze.Apps.Support.Controls.SupportMap.Instance().mapControlObj(' + prop.FormPropertyId + ')">' +
- '<a href="javascript:;" class="btn btn-default input-group-addon hidden" onclick="_bizgaze_control_Location.getLocation()">Capture Location</a>' +
- '<a href="javascript:;" class="btn btn-primary hidden input-group-addon" onclick="_bizgaze_control_Location.getMobileLocation()">Current Location</a>';
- $("#" + 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 = {}));
|