Built files from Bizgaze WebServer
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

supportmap.component.js 12KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. var Bizgaze;
  2. (function (Bizgaze) {
  3. let Apps;
  4. (function (Apps) {
  5. let Support;
  6. (function (Support) {
  7. let Controls;
  8. (function (Controls) {
  9. class SupportMap extends Unibase.Platform.Core.BaseComponent {
  10. init(formpropertyid, prop, callback) {
  11. var _id = $(".formValidate:visible").attr("id");
  12. var slt = _id.split('_');
  13. var map11 = $('#locationcontrol_' + formpropertyid);
  14. map11.geocomplete({ details: "form.form_" + slt[1] });
  15. var instance = this;
  16. instance.loadControlSettings(prop.ControlJsonText, prop.FormPropertyId);
  17. instance.loadPropertySettings(prop.PropertySettings, prop.FormPropertyId);
  18. }
  19. loadControl(containerid, prop) {
  20. var instance = this;
  21. var regExpr = "";
  22. var ErrMsg = "";
  23. var Isrequired = prop.IsRequired != true ? 'hidden' : '';
  24. var required = prop.IsRequired != true ? '' : 'required';
  25. 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">' +
  26. '<span class="input-group-addon bg-white no-border mt-10"><i class="text-success fa fa-map-marker pull-left"></i></span>' +
  27. '<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 + ')"> ' +
  28. '<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>' +
  29. '<input type="hidden" id="hfId" value=""><label for="Validation" id="lblValidation_' + prop.DocPropertyName + '"></label><input type="hidden" id="hfFormPropertyId" value=""></div></div>' +
  30. '<div class="col-sm-2 mt-25 hidden" style="padding:0px">' +
  31. '<a href="javascript:;" class="btn btn-success mb-1" onclick="_bizgaze_control_Location.getLocation()">Capture Location</a>' +
  32. '<button type="button" class="btn btn-success hidden" onclick="_bizgaze_control_Location.getMobileLocation()">Capture Location</button>' +
  33. '</div></div><div id="meetingAddressMap" class="text-center b-a" style="height: 250px"></div>' +
  34. '<div class="coordinates"><span id="lbl_coordinates"></span></div><input type="hidden" id="hfLattitude" name="lat" value="">' +
  35. '<input type ="hidden" id = "hfLongitude" name = "lng" value = "" >' +
  36. '<input type="hidden" id="hdn_locationcontrol" class="value-control" value="Bizgaze.Apps.Support.Controls.SupportMap.Instance().mapControlObj(' + prop.FormPropertyId + ')">' +
  37. '<a href="javascript:;" class="btn btn-default input-group-addon hidden" onclick="_bizgaze_control_Location.getLocation()">Capture Location</a>' +
  38. '<a href="javascript:;" class="btn btn-primary hidden input-group-addon" onclick="_bizgaze_control_Location.getMobileLocation()">Current Location</a>';
  39. $("#" + containerid).html(html);
  40. var latd = 0;
  41. var lgtd = 0;
  42. $('#hfLattitude').val(latd);
  43. $('#hfLongitude').val(lgtd);
  44. $("#lbl_coordinates").html("latd : " + latd + ", lgtd : " + lgtd);
  45. Bizgaze.Apps.Support.Controls.SupportMap.Instance().loadMap(latd, lgtd, prop.FormPropertyId);
  46. }
  47. loadMap(latd, lgtd, formpropertyid) {
  48. var instance = this;
  49. var myLatlng = new google.maps.LatLng(latd, lgtd);
  50. var mapOptions = {
  51. zoom: 15,
  52. center: myLatlng,
  53. };
  54. var map = new google.maps.Map(document.getElementById("meetingAddressMap"), mapOptions);
  55. var marker = new google.maps.Marker({
  56. position: myLatlng,
  57. title: "Hello World!",
  58. });
  59. marker.setMap(map);
  60. var url = "https://maps.googleapis.com/maps/api/geocode/json?latlng=" + latd + "," + lgtd + "&key=" + _mapsettings.key() + "&sensor=false";
  61. var xhr = Bizgaze.Apps.Support.Controls.SupportMap.Instance().createCORSRequest2('Get', url);
  62. if (!xhr) {
  63. bootbox.alert('CORS not supported');
  64. return;
  65. }
  66. xhr.onload = function () {
  67. var text = xhr.responseText;
  68. var json = JSON.parse(text);
  69. instance.addressData = [];
  70. instance.addressData = json.results;
  71. $("#locationcontrol_" + formpropertyid).val(json.results[0].formatted_address);
  72. };
  73. xhr.onerror = function () {
  74. bootbox.alert('Woops, there was an error making the request.');
  75. };
  76. }
  77. getAddressLocation(Id) {
  78. var instance = this;
  79. var ac = eval('new google.maps.places.Autocomplete((document.getElementById("locationcontrol_" + Id)), {types: ["geocode"]});');
  80. ac.addListener('place_changed', function () {
  81. var geocoder = new google.maps.Geocoder();
  82. setTimeout(function () {
  83. var address = document.getElementById('locationcontrol_' + Id);
  84. address.value;
  85. geocoder.geocode({ 'address': address.value }, function (results, status) {
  86. if (status == google.maps.GeocoderStatus.OK) {
  87. var latitude = results[0].geometry.location.lat();
  88. var longitude = results[0].geometry.location.lng();
  89. $('#hfLattitude').val(latitude);
  90. $('#hfLongitude').val(longitude);
  91. var latd = latitude;
  92. var lgtd = longitude;
  93. $("#lbl_coordinates").html("latd : " + latd + ", lgtd : " + lgtd);
  94. Bizgaze.Apps.Support.Controls.SupportMap.Instance().loadMap(latd, lgtd, Id);
  95. }
  96. });
  97. }, 500);
  98. });
  99. }
  100. getReverseGeocodingData(lat, lng, formpropertyid) {
  101. var instance = this;
  102. var latlng = new google.maps.LatLng(lat, lng);
  103. var geocoder = new google.maps.Geocoder();
  104. geocoder.geocode({ 'location': latlng }, function (results, status) {
  105. if (status !== google.maps.GeocoderStatus.OK) {
  106. alert(status);
  107. }
  108. if (status == google.maps.GeocoderStatus.OK) {
  109. console.log(results);
  110. var address = (results[1].formatted_address);
  111. $("#locationcontrol_" + formpropertyid).val(address);
  112. }
  113. });
  114. }
  115. getLocation(formpropertyid) {
  116. if (navigator.geolocation) {
  117. navigator.geolocation.getCurrentPosition(function (position) {
  118. $("#hfLattitude").val(position.coords.latitude);
  119. $("#hfLongitude").val(position.coords.longitude);
  120. Bizgaze.Apps.Support.Controls.SupportMap.Instance().showPosition(formpropertyid, position);
  121. });
  122. }
  123. else {
  124. bootbox.alert("Geolocation is not supported by this browser.");
  125. }
  126. }
  127. showPosition(formpropertyid, position) {
  128. $("#hfLattitude").val(position.coords.latitude);
  129. $("#hfLongitude").val(position.coords.longitude);
  130. $("#lbl_coordinates").html("latd : " + position.coords.latitude + ", lgtd : " + position.coords.longitude);
  131. Bizgaze.Apps.Support.Controls.SupportMap.Instance().loadMap(position.coords.latitude, position.coords.longitude, formpropertyid);
  132. Bizgaze.Apps.Support.Controls.SupportMap.Instance().getReverseGeocodingData(position.coords.latitude, position.coords.longitude, formpropertyid);
  133. }
  134. mapControlObj(formpropertyid) {
  135. var instance = this;
  136. var mapEntries = new Array();
  137. mapEntries.push({
  138. Latitude: $('#hfLattitude').val(),
  139. Longitude: $("#hfLongitude").val(),
  140. });
  141. return mapEntries;
  142. }
  143. createCORSRequest2(method, url) {
  144. let XDomainRequest;
  145. var xhr = new XMLHttpRequest();
  146. if ("withCredentials" in xhr) {
  147. xhr.open(method, url, true);
  148. }
  149. else if (typeof XDomainRequest != "undefined") {
  150. xhr = new XDomainRequest();
  151. xhr.open(method, url);
  152. }
  153. else {
  154. xhr = null;
  155. }
  156. return xhr;
  157. }
  158. loadControlSettings(controlsettingjson, formpropertyid) {
  159. return null;
  160. }
  161. loadPropertySettings(propertysettings, formpropertyid) {
  162. return null;
  163. }
  164. bindEditFormDetails(formpropertyid, propval, DocPropertyName) {
  165. return null;
  166. }
  167. static Instance() {
  168. if (this.instance === undefined) {
  169. this.instance = new SupportMap();
  170. }
  171. return this.instance;
  172. }
  173. }
  174. Controls.SupportMap = SupportMap;
  175. })(Controls = Support.Controls || (Support.Controls = {}));
  176. })(Support = Apps.Support || (Apps.Support = {}));
  177. })(Apps = Bizgaze.Apps || (Bizgaze.Apps = {}));
  178. })(Bizgaze || (Bizgaze = {}));