@bmlt-enabled/croutonjs 3.19.1 → 3.19.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/crouton-map.js CHANGED
@@ -21,6 +21,27 @@ function MeetingMap(inConfig) {
21
21
  function apiLoadedCallback() {
22
22
  loadedCallbackFunction(...loadedCallbackArgs);
23
23
  }
24
+
25
+ function retrieveGeolocation() {
26
+ return new Promise((resolve, reject) => {
27
+ if (window.storedGeolocation) {
28
+ resolve(window.storedGeolocation);
29
+ } else if (navigator.geolocation) {
30
+ navigator.geolocation.getCurrentPosition((position) => {
31
+ window.storedGeolocation = {
32
+ latitude: position.coords.latitude,
33
+ longitude: position.coords.longitude
34
+ };
35
+ resolve(window.storedGeolocation);
36
+ }, (error) => {
37
+ reject(new Error('Error getting geolocation: ' + error.message));
38
+ });
39
+ } else {
40
+ reject(new Error('Geolocation is not supported by this browser.'));
41
+ }
42
+ });
43
+ }
44
+
24
45
  /************************************************************************************//**
25
46
  * \brief Load the map and set it up. *
26
47
  ****************************************************************************************/
@@ -126,14 +147,15 @@ function MeetingMap(inConfig) {
126
147
  var controlDiv = document.createElement('div');
127
148
  controlDiv.innerHTML = template(menuContext);
128
149
  controlDiv.querySelector("#nearbyMeetings").addEventListener('click', function (e) {
129
- if (navigator.geolocation) {
130
- navigator.geolocation.getCurrentPosition(function (position) {
131
- coords = position.coords;
132
- gDelegate.setViewToPosition(coords, filterMeetingsAndBounds);
133
- });
134
- }
150
+ retrieveGeolocation().then(position => {
151
+ gDelegate.setViewToPosition(position, filterMeetingsAndBounds);
152
+ }).catch(error => {
153
+ console.error(error.message);
154
+ $('.geo').removeClass("hide").addClass("show").html(`<p>${error.message}</p>`);
155
+ });
135
156
  dropdownContent = document.getElementById("map-menu-dropdown").style.display = "none";
136
157
  });
158
+
137
159
  controlDiv.querySelector("#lookupLocation").addEventListener('click', showGeocodingDialog);
138
160
  controlDiv.querySelector("#filterMeetings").addEventListener('click', showFilterDialog);
139
161
  controlDiv.querySelector("#showAsTable").addEventListener('click', showListView);
@@ -193,17 +215,15 @@ function MeetingMap(inConfig) {
193
215
  searchResponseCallback(fitDuringFilter);
194
216
  };
195
217
  function nearMeSearch() {
196
- if (navigator.geolocation) {
197
- navigator.geolocation.getCurrentPosition(
198
- function (position) {
199
- showThrobber();
200
- crouton.searchByCoordinates(position.coords.latitude, position.coords.longitude, config.map_search.width);
201
- },
202
- showBmltSearchDialog
203
- )
204
- }
218
+ retrieveGeolocation().then(position => {
219
+ showThrobber();
220
+ crouton.searchByCoordinates(position.latitude, position.longitude, config.map_search.width);
221
+ }).catch(error => {
222
+ console.error(error.message);
223
+ });
224
+ showBmltSearchDialog();
205
225
  closeModalWindow(gSearchModal);
206
- }
226
+ };
207
227
  function clickSearch(e) {
208
228
  gDelegate.clickSearch(e, function(lat,lng) {
209
229
  showThrobber();
@@ -651,6 +671,7 @@ MeetingMap.prototype.refreshMeetings = null;
651
671
  MeetingMap.prototype.openModalWindow = null;
652
672
  MeetingMap.prototype.closeModalWindow = null;
653
673
  MeetingMap.prototype.loadPopupMap = null;
674
+
654
675
  function MapDelegate(config) {
655
676
  var g_icon_image_single = L.icon({
656
677
  iconUrl: config.BMLTPlugin_images+"/NAMarker.png",