@bmlt-enabled/croutonjs 3.22.4 → 3.24.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
@@ -25,11 +25,22 @@ function MapDelegate(config) {
25
25
  iconAnchor: [12, 32], // point of the icon which will correspond to marker's location
26
26
  shadowAnchor: [12, 32], // the same for the shadow
27
27
  popupAnchor: [12, -32] // point from which the popup should open relative to the iconAnchor
28
+ });
29
+ var g_icon_image_searchpoimt = L.icon({
30
+ iconUrl: config.BMLTPlugin_images+"/SearchPoint.png",
31
+ shadowUrl: config.BMLTPlugin_images+"/NAMarkerS.png",
32
+ iconSize: [23, 32], // size of the icon
33
+ shadowSize: [43, 32], // size of the shadow
34
+ iconAnchor: [12, 32], // point of the icon which will correspond to marker's location
35
+ shadowAnchor: [12, 32], // the same for the shadow
36
+ popupAnchor: [12, -32] // point from which the popup should open relative to the iconAnchor
28
37
  });
29
38
  var gAllMarkers = []; ///< Holds all the markers.
30
39
  var gMainMap;
31
40
  var gTileLayer;
32
41
  var gClusterLayer = null;
42
+ var gSearchPointMarker = false;
43
+ var gOpenMarker = false;
33
44
  function createMap(inDiv, inCenter, inHidden = false) {
34
45
  if (! inCenter ) return null;
35
46
  if ( inHidden ) {
@@ -123,10 +134,11 @@ function MapDelegate(config) {
123
134
  function getZoomAdjust(only_out,filterMeetings) {
124
135
  if (!gMainMap) return 12;
125
136
  var ret = gMainMap.getZoom();
137
+ if (config.map_search && config.filter_visible) return ret;
126
138
  var center = gMainMap.getCenter();
127
139
  var bounds = gMainMap.getBounds();
128
140
  var zoomedOut = false;
129
- while(filterMeetings(bounds).length==0 && ret>6) {
141
+ while(filterMeetings(bounds, center).length==0 && ret>6) {
130
142
  zoomedOut = true;
131
143
  // not exact, because earth is curved
132
144
  ret -= 1;
@@ -171,18 +183,26 @@ function MapDelegate(config) {
171
183
  if (!gMainMap) return null;
172
184
  return gMainMap.latLngToLayerPoint(L.latLng(lat,lng));
173
185
  }
186
+ function markSearchPoint(inCoords) {
187
+ if (!gMainMap) return;
188
+ if (gSearchPointMarker) gSearchPointMarker.remove();
189
+ gSearchPointMarker = L.marker(inCoords, {icon: g_icon_image_searchpoimt});
190
+ gSearchPointMarker.addTo(gMainMap);
191
+ }
174
192
  function createMarker ( inCoords, ///< The long/lat for the marker.
175
193
  multi, ///< Flag if marker has multiple meetings
176
194
  in_html, ///< The info window HTML
177
195
  in_title, ///< The tooltip
178
- in_ids
196
+ in_ids,
197
+ openedMarker
179
198
  )
180
199
  {
181
200
  if (!gMainMap) return;
182
201
  var in_main_icon = (multi ? g_icon_image_multi : g_icon_image_single);
183
202
 
184
203
  let highlightRow = function(target) {
185
- let id = target.id.split('-')[1];
204
+ const id = target.id.split('-')[1];
205
+ gOpenMarker = id;
186
206
  jQuery(".bmlt-data-row > td").removeClass("rowHighlight");
187
207
  jQuery("#meeting-data-row-" + id + " > td").addClass("rowHighlight");
188
208
  if (typeof crouton != 'undefined') crouton.dayTabFromId(id);
@@ -192,6 +212,16 @@ function MapDelegate(config) {
192
212
  if (gClusterLayer) gClusterLayer.addLayer(marker);
193
213
  else marker.addTo(gMainMap);
194
214
  marker.on('popupopen', function(e) {
215
+ if (openedMarker && marker.getPopup().getContent().includes("panel-"+openedMarker)) {
216
+ // I want to just do this:
217
+ //jQuery("#panel-"+openedMarker).prop("checked", true);
218
+ // But for some reason, leaflet makes a copy of the popup, so the ID is not unique....
219
+ jQuery("input[type=radio][name=panel]").filter(function() {
220
+ return jQuery(this).attr('id')=="panel-"+openedMarker})
221
+ .each(function(index,value) {
222
+ jQuery(this).prop("checked", true);
223
+ });
224
+ }
195
225
  marker.setIcon(g_icon_image_selected);
196
226
  gMainMap.on('zoomstart',function(){
197
227
  marker.closePopup();
@@ -204,11 +234,21 @@ function MapDelegate(config) {
204
234
  });
205
235
  });
206
236
  marker.on('popupclose', function(e) {
237
+ gOpenMarker = false;
207
238
  marker.setIcon(marker.isMulti ? g_icon_image_multi : g_icon_image_single);
208
239
  jQuery(".bmlt-data-row > td").removeClass("rowHighlight");
209
240
  });
241
+ if (openedMarker && in_ids.includes(parseInt(openedMarker))) {
242
+ marker.openPopup();
243
+ marker.once('add', function() {
244
+ if (!marker.isPopupOpen()) marker.openPopup();
245
+ });
246
+ }
210
247
  gAllMarkers.push( {ids: in_ids, marker: marker} );
211
248
  }
249
+ function getOpenMarker() {
250
+ return gOpenMarker;
251
+ }
212
252
  function openMarker(id) {
213
253
  if (!gMainMap) return;
214
254
  marker = gAllMarkers.find((m) => m.ids.includes(id));
@@ -358,15 +398,20 @@ function addControl(div,pos,cb) {
358
398
  geoCodeParams.countrycodes = config.region;
359
399
  }
360
400
  if (config.bounds
361
- && config.bounds.north && config.bounds.north.trim()!== ''
362
- && config.bounds.east && config.bounds.east.trim()!== ''
363
- && config.bounds.south && config.bounds.south.trim()!== ''
364
- && config.bounds.west && config.bounds.west.trim()!== '') {
401
+ && isNumber(config.bounds.north)
402
+ && isNumber(config.bounds.east)
403
+ && isNumber(config.bounds.south)
404
+ && isNumber(config.bounds.west)) {
365
405
  geoCodeParams.viewbox = config.bounds.south+","+config.bounds.west+","+
366
406
  config.bounds.north+","+config.bounds.east;
367
407
  }
368
408
  geocode(in_loc, geoCodeParams, callback, filterMeetings);
369
409
  }
410
+ function isNumber(x) {
411
+ if (typeof x === 'number') return true;
412
+ if (typeof x === 'string' && x.trim() !== '' && !isNaN(x)) return true;
413
+ return false;
414
+ }
370
415
  function contains(bounds, lat, lng) {
371
416
  if (!gMainMap) return true;
372
417
  return bounds.contains(L.latLng ( lat, lng ));
@@ -406,6 +451,19 @@ function addControl(div,pos,cb) {
406
451
  })
407
452
  });
408
453
  }
454
+ function getCorners(lat_lngs = false) {
455
+ var bounds = lat_lngs
456
+ ? lat_lngs.reduce(function(b,lat_lng) {b.extend(lat_lng); return b;}, L.latLngBounds())
457
+ : gMainMap.getBounds();
458
+
459
+ return {
460
+ "ne" : {"lat": bounds.getNorthEast().lat, "lng": bounds.getNorthEast().lng},
461
+ "sw" : {"lat": bounds.getSouthWest().lat, "lng": bounds.getSouthWest().lng}
462
+ }
463
+ }
464
+ function getCenter() {
465
+ return {"lat": gMainMap.getCenter().lat, "lng": gMainMap.getCenter().lng};
466
+ }
409
467
  function modalOn() {
410
468
  if (gMainMap) gMainMap.dragging.disable()
411
469
  }
@@ -416,8 +474,8 @@ function addControl(div,pos,cb) {
416
474
  f();
417
475
  }
418
476
  function returnTrue() {return true;}
419
- function hasClickSearch() {
420
- return gMainMap != null;
477
+ function isMapDefined() {
478
+ return (gMainMap != null);
421
479
  }
422
480
  this.createMap = createMap;
423
481
  this.addListener = addListener;
@@ -445,7 +503,11 @@ function addControl(div,pos,cb) {
445
503
  this.modalOn = modalOn;
446
504
  this.modalOff = modalOff;
447
505
  this.afterInit = afterInit;
448
- this.hasClickSearch = hasClickSearch;
506
+ this.isMapDefined = isMapDefined;
507
+ this.getCorners = getCorners;
508
+ this.getCenter = getCenter;
509
+ this.markSearchPoint = markSearchPoint;
510
+ this.getOpenMarker = getOpenMarker;
449
511
  }
450
512
  MapDelegate.prototype.createMap = null;
451
513
  MapDelegate.prototype.addListener = null;
@@ -473,8 +535,11 @@ MapDelegate.prototype.getGeocodeCenter = null;
473
535
  MapDelegate.prototype.modalOn = null;
474
536
  MapDelegate.prototype.modalOff = null;
475
537
  MapDelegate.prototype.afterInit = null;
476
- MapDelegate.prototype.hasClickSearch = null;
477
-
538
+ MapDelegate.prototype.isMapDefined = null;
539
+ MapDelegate.prototype.getCorners = null;
540
+ MapDelegate.prototype.getCenter = null;
541
+ MapDelegate.prototype.markSearchPoint = null;
542
+ MapDelegate.prototype.getOpenMarker = null;
478
543
  /* @preserve
479
544
  * Leaflet 1.5.1+Detached: 2e3e0ffbe87f246eb76d86d2633ddd59b262830b.2e3e0ff, a JS library for interactive maps. http://leafletjs.com
480
545
  * (c) 2010-2018 Vladimir Agafonkin, (c) 2010-2011 CloudMade