@bmlt-enabled/croutonjs 3.20.12 → 3.21.0

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
@@ -46,7 +46,7 @@ function MeetingMap(inConfig) {
46
46
  * \brief Load the map and set it up. *
47
47
  ****************************************************************************************/
48
48
 
49
- function loadMap(inDiv, menuContext, handlebarMapOptions=null,cb=null) {
49
+ function loadMap(inDiv, menuContext, handlebarMapOptions=null,cb=null,hide=false) {
50
50
  if (inDiv) {
51
51
  crouton_Handlebars.registerPartial("markerContentsTemplate", config['marker_contents_template']);
52
52
  gInDiv = inDiv;
@@ -66,7 +66,7 @@ function MeetingMap(inConfig) {
66
66
  }
67
67
  let loc = {latitude: config.lat, longitude: config.lng, zoom: config.zoom};
68
68
  if (handlebarMapOptions) loc = {latitude: handlebarMapOptions.lat, longitude: handlebarMapOptions.lng};
69
- if (gDelegate.createMap(inDiv, loc)) {
69
+ if (gDelegate.createMap(inDiv, loc, hide)) {
70
70
  gDelegate.addListener('zoomend', function (ev) {
71
71
  if (shouldRedrawMarkers() && gAllMeetings) {
72
72
  if (listOnlyVisible) {
@@ -92,12 +92,19 @@ function MeetingMap(inConfig) {
92
92
  };
93
93
  };
94
94
  var gSearchModal;
95
- function createSearchButton(menuContext) {
96
- var template = hbs_Crouton.templates['mapSearch'];
97
- var controlDiv = document.createElement('div');
98
- controlDiv.innerHTML = template();
95
+ function createSearchButton() {
96
+ const template = hbs_Crouton.templates['mapSearch'];
97
+ const controlDiv = document.createElement('div');
98
+ const params = {'hasClickSearch': gDelegate.hasClickSearch()}
99
+ controlDiv.innerHTML = template(params);
99
100
  controlDiv.querySelector("#map-search-button").addEventListener('click', showBmltSearchDialog);
100
101
  controlDiv.querySelector("#bmltsearch-nearbyMeetings").addEventListener('click', nearMeSearch);
102
+ controlDiv.querySelector("#bmltsearch-goto-text").addEventListener('keypress', function (event) {
103
+ if (event.key === "Enter") {
104
+ event.preventDefault();
105
+ document.getElementById("bmltsearch-text-button").click();
106
+ }
107
+ });
101
108
  controlDiv.querySelector("#bmltsearch-text-button").addEventListener('click', function () {
102
109
  let text = document.getElementById("bmltsearch-goto-text").value.trim();
103
110
  if (text === "") return;
@@ -105,7 +112,35 @@ function MeetingMap(inConfig) {
105
112
  gDelegate.callGeocoder(text, null, mapSearchGeocode);
106
113
  closeModalWindow(gSearchModal);
107
114
  });
108
- controlDiv.querySelector("#bmltsearch-clicksearch").addEventListener('click', clickSearch);
115
+ controlDiv.querySelector("#modal-seach-parameters").style.display = 'none';
116
+ controlDiv.querySelector("#show-search-parameters").addEventListener('click', function (e) {
117
+ const controlDiv = e.target.parentElement.parentElement;
118
+ let w = config.map_search.width;
119
+ let checked = '#search_radius';
120
+ if (w < 0) {
121
+ w = -w;
122
+ checked = '#search_count';
123
+ }
124
+ controlDiv.querySelector(checked).checked = true;
125
+ controlDiv.querySelector('#search_parameter').value = w;
126
+ controlDiv.querySelector("#modal-seach-parameters").style.display = 'block';
127
+ controlDiv.querySelector("#modal-search-page").style.display = 'none';
128
+ controlDiv.querySelector("#search_radius_label").innerHTML = crouton.localization.getWord('Radius of search in $$').replace('$$', crouton.config.distance_units);
129
+ });
130
+ controlDiv.querySelector("#show-search-page").addEventListener('click', function (e) {
131
+ const controlDiv = e.target.parentElement.parentElement;
132
+ let w = controlDiv.querySelector('#search_parameter').value;
133
+ if (controlDiv.querySelector('#search_count')) {
134
+ w = -Math.round(w);
135
+ if (w == 0) w = -1;
136
+ }
137
+ config.map_search.width = w;
138
+ controlDiv.querySelector("#modal-seach-parameters").style.display = 'none';
139
+ controlDiv.querySelector("#modal-search-page").style.display = 'block';
140
+ });
141
+
142
+
143
+ if (gDelegate.hasClickSearch()) controlDiv.querySelector("#bmltsearch-clicksearch").addEventListener('click', clickSearch);
109
144
  [...controlDiv.getElementsByClassName('modal-close')].forEach((elem)=>elem.addEventListener('click', (e)=>closeModalWindow(e.target)));
110
145
  gSearchModal = controlDiv.querySelector("#bmltsearch_modal");
111
146
  gSearchModal.parentElement.removeChild(gSearchModal);
@@ -200,14 +235,14 @@ function MeetingMap(inConfig) {
200
235
  function hasMapSearch() {
201
236
  return 'map_search' in config;
202
237
  }
203
- function loadFromCrouton(inDiv_id, meetings_responseObject, menuContext = null, handlebarMapOptions = null, fitBounds = true, callback) {
238
+ function loadFromCrouton(inDiv_id, meetings_responseObject, menuContext = null, handlebarMapOptions = null, fitBounds = true, callback, hide) {
204
239
  if (!gDelegate.isApiLoaded()) {
205
- preloadApiLoadedCallback(loadFromCrouton, [inDiv_id, meetings_responseObject, menuContext, handlebarMapOptions, fitBounds, callback]);
240
+ preloadApiLoadedCallback(loadFromCrouton, [inDiv_id, meetings_responseObject, menuContext, handlebarMapOptions, fitBounds, callback, hide]);
206
241
  gDelegate.loadApi();
207
242
  return;
208
243
  }
209
244
  let inDiv = document.getElementById(inDiv_id);
210
- loadMap(inDiv, menuContext, handlebarMapOptions,callback);
245
+ loadMap(inDiv, menuContext, handlebarMapOptions, callback, hide);
211
246
  loadAllMeetings(meetings_responseObject, fitBounds, true);
212
247
  };
213
248
  function loadPopupMap(inDiv_id, meeting, handlebarMapOptions = null) {
@@ -282,10 +317,14 @@ function MeetingMap(inConfig) {
282
317
  };
283
318
  };
284
319
  function mapSearchGeocode(resp) {
285
- let latlng = gDelegate.getGeocodeCenter(resp);
320
+ showThrobber();
286
321
  if (document.getElementById("bmltsearch-goto-text"))
287
322
  document.getElementById("bmltsearch-goto-text").value = "";
288
- showThrobber();
323
+ let latlng = gDelegate.getGeocodeCenter(resp);
324
+ if (!latlng) {
325
+ hideThrobber();
326
+ return;
327
+ }
289
328
  crouton.searchByCoordinates(latlng.lat, latlng.lng, config.map_search.width);
290
329
  }
291
330
  function loadAllMeetings(meetings_responseObject, fitBounds=true, fitAll=false) {
@@ -773,8 +812,15 @@ function MapDelegate(config) {
773
812
  var gMainMap;
774
813
  var gTileLayer;
775
814
  var gClusterLayer = null;
776
- function createMap(inDiv, inCenter) {
815
+ function createMap(inDiv, inCenter, inHidden = false) {
777
816
  if (! inCenter ) return null;
817
+ if ( inHidden ) {
818
+ gDiv = inDiv;
819
+ gDiv.style.height = 'auto';
820
+ gDiv.style.marginBottom = '10px';
821
+ gMainMap = null;
822
+ return gDiv;
823
+ }
778
824
  myOptions = {
779
825
  'minZoom': config.minZoom,
780
826
  'maxZoom': config.maxZoom,
@@ -804,6 +850,7 @@ function MapDelegate(config) {
804
850
  return gMainMap;
805
851
  }
806
852
  function addListener(ev,f,once) {
853
+ if (!gMainMap) return;
807
854
  if (ev=='idle') {
808
855
  ev = 'moveend';
809
856
  }
@@ -821,9 +868,11 @@ function MapDelegate(config) {
821
868
  return {'event': ev, 'f': f};
822
869
  }
823
870
  function removeListener(o) {
871
+ if (!gMainMap) return;
824
872
  gMainMap.off(o.event, o.f);
825
873
  }
826
874
  function setViewToPosition(position, filterMeetings, extra=null) {
875
+ if (!gMainMap) return;
827
876
  var latlng = L.latLng(position.latitude, position.longitude);
828
877
  gMainMap.flyTo(latlng);
829
878
  gMainMap.once('moveend', function(ev) {
@@ -845,10 +894,12 @@ function MapDelegate(config) {
845
894
  }
846
895
  function clearAllMarkers ( )
847
896
  {
897
+ if (!gMainMap) return;
848
898
  gAllMarkers && gAllMarkers.forEach((m) => {m.marker.closePopup(); gMainMap.removeLayer(m.marker)});
849
899
  gAllMarkers = [];
850
900
  };
851
901
  function getZoom() {
902
+ if (!gMainMap) return null;
852
903
  return gMainMap.getZoom();
853
904
  }
854
905
  function getZoomAdjust(only_out,filterMeetings) {
@@ -891,12 +942,15 @@ function MapDelegate(config) {
891
942
  return ret;
892
943
  }
893
944
  function setZoom(filterMeetings, force=0) {
945
+ if (!gMainMap) return;
894
946
  (force > 0) ? gMainMap.setZoom(force) : gMainMap.setZoom(getZoomAdjust(false,filterMeetings));
895
947
  }
896
948
  function zoomOut(filterMeetings) {
949
+ if (!gMainMap) return;
897
950
  gMainMap.setZoom(getZoomAdjust(true,filterMeetings));
898
951
  }
899
952
  function fromLatLngToPoint(lat, lng) {
953
+ if (!gMainMap) return null;
900
954
  return gMainMap.latLngToLayerPoint(L.latLng(lat,lng));
901
955
  }
902
956
  function createMarker ( inCoords, ///< The long/lat for the marker.
@@ -906,6 +960,7 @@ function MapDelegate(config) {
906
960
  in_ids
907
961
  )
908
962
  {
963
+ if (!gMainMap) return;
909
964
  var in_main_icon = (multi ? g_icon_image_multi : g_icon_image_single);
910
965
 
911
966
  let highlightRow = function(target) {
@@ -937,6 +992,7 @@ function MapDelegate(config) {
937
992
  gAllMarkers.push( {ids: in_ids, marker: marker} );
938
993
  }
939
994
  function openMarker(id) {
995
+ if (!gMainMap) return;
940
996
  marker = gAllMarkers.find((m) => m.ids.includes(id));
941
997
  if (marker) {
942
998
  marker.marker.openPopup();
@@ -947,6 +1003,10 @@ function openMarker(id) {
947
1003
  jQuery("#meeting-data-row-" + id + " > td").addClass("rowHighlight");
948
1004
  }
949
1005
  function addControl(div,pos,cb) {
1006
+ if (!gMainMap) {
1007
+ gDiv.appendChild(div);
1008
+ return;
1009
+ }
950
1010
  var ControlClass = L.Control.extend({
951
1011
  onAdd: function (map) {
952
1012
  return div;
@@ -1090,25 +1150,32 @@ function addControl(div,pos,cb) {
1090
1150
  geocode(in_loc, geoCodeParams, callback, filterMeetings);
1091
1151
  }
1092
1152
  function contains(bounds, lat, lng) {
1153
+ if (!gMainMap) return true;
1093
1154
  return bounds.contains(L.latLng ( lat, lng ));
1094
1155
  }
1095
1156
  function getBounds() {
1157
+ if (!gMainMap) return null;
1096
1158
  return gMainMap.getBounds();
1097
1159
  }
1098
1160
  function invalidateSize() {
1161
+ if (!gMainMap) return;
1099
1162
  gMainMap.invalidateSize();
1100
1163
  }
1101
1164
  function fitBounds(locations) {
1165
+ if (!gMainMap) return;
1102
1166
  const bounds = locations.reduce(function(b,lat_lng) {b.extend(lat_lng); return b;}, L.latLngBounds());
1103
1167
  gMainMap.fitBounds(bounds);
1104
1168
  }
1105
1169
  function createClusterLayer() {
1170
+ if (!gMainMap) return;
1106
1171
  gClusterLayer = L.markerClusterGroup();
1107
1172
  }
1108
1173
  function addClusterLayer() {
1174
+ if (!gMainMap) return;
1109
1175
  gClusterLayer && gMainMap.addLayer(gClusterLayer);
1110
1176
  }
1111
1177
  function removeClusterLayer() {
1178
+ if (!gMainMap) return;
1112
1179
  gClusterLayer && gMainMap.removeLayer(gClusterLayer);
1113
1180
  gClusterLayer = null;
1114
1181
  }
@@ -1131,6 +1198,9 @@ function addControl(div,pos,cb) {
1131
1198
  f();
1132
1199
  }
1133
1200
  function returnTrue() {return true;}
1201
+ function hasClickSearch() {
1202
+ return gMainMap != null;
1203
+ }
1134
1204
  this.createMap = createMap;
1135
1205
  this.addListener = addListener;
1136
1206
  this.removeListener = removeListener;
@@ -1157,6 +1227,7 @@ function addControl(div,pos,cb) {
1157
1227
  this.modalOn = modalOn;
1158
1228
  this.modalOff = modalOff;
1159
1229
  this.afterInit = afterInit;
1230
+ this.hasClickSearch = hasClickSearch;
1160
1231
  }
1161
1232
  MapDelegate.prototype.createMap = null;
1162
1233
  MapDelegate.prototype.addListener = null;
@@ -1184,6 +1255,7 @@ MapDelegate.prototype.getGeocodeCenter = null;
1184
1255
  MapDelegate.prototype.modalOn = null;
1185
1256
  MapDelegate.prototype.modalOff = null;
1186
1257
  MapDelegate.prototype.afterInit = null;
1258
+ MapDelegate.prototype.hasClickSearch = null;
1187
1259
 
1188
1260
  /* @preserve
1189
1261
  * Leaflet 1.5.1+Detached: 2e3e0ffbe87f246eb76d86d2633ddd59b262830b.2e3e0ff, a JS library for interactive maps. http://leafletjs.com