From ec5efe6f020d8477391ff8a432e4d325f487d6d7 Mon Sep 17 00:00:00 2001
From: Demian Katz <demian.katz@villanova.edu>
Date: Thu, 14 Jun 2018 08:47:40 -0400
Subject: [PATCH] Rearrange code so function is defined before being called.

---
 themes/bootstrap3/js/map_selection_leaflet.js | 164 +++++++++---------
 1 file changed, 82 insertions(+), 82 deletions(-)

diff --git a/themes/bootstrap3/js/map_selection_leaflet.js b/themes/bootstrap3/js/map_selection_leaflet.js
index 4f5c264fb82..7db126cf787 100644
--- a/themes/bootstrap3/js/map_selection_leaflet.js
+++ b/themes/bootstrap3/js/map_selection_leaflet.js
@@ -43,7 +43,6 @@ function loadMapSelection(geoField, boundingBox, baseURL, homeURL, searchParams,
     shadowUrl: VuFind.path + '/themes/bootstrap3/css/vendor/leaflet/images/marker-shadow.png'
   });
 
-  
   // Initialize marker clusters with icon colors
   var markerClusters = new L.MarkerClusterGroup({
     iconCreateFunction: function icf(cluster) {
@@ -63,6 +62,88 @@ function loadMapSelection(geoField, boundingBox, baseURL, homeURL, searchParams,
       return new L.DivIcon({ html: '<div><span><b>' + childCount + '</b></span></div>', className: 'marker-cluster' + c, iconSize: new L.Point(40, 40) });
     }
   });
+
+  // Handle user interaction with markers and rectangles
+  //----------------------------------------------------//
+  function onClick() {
+    mapSearch.eachLayer(function msl(layer) {
+      if (layer.options.id === "mRect") {
+        mapSearch.removeLayer(layer);
+      }
+    });
+
+    // Reset previously selected features to inactive color - RED
+    if (clickedIDs.length > 0) {
+      markerClusters.eachLayer(function mcl(layer){
+        if (layer.options.recID === clickedIDs[0]) {
+          layer.options.recStatus = 'inactive';
+          layer._popup.setContent(layer.options.recPopup);
+          if (layer.options.recType === "rectangle") {
+            layer.setIcon(redRectIcon);
+          } else {
+            layer.setIcon(redIcon);
+          } 
+        } 
+      });
+      clickedIDs = []; 
+      clickedBounds = [];
+    }
+    
+    //Handle current feature selection
+    //Change color of all features with thisID to BLUE
+    var thisID = this.options.recID;
+    clickedIDs.push(thisID);
+    var j = 0;
+    markerClusters.eachLayer(function mc(layer){
+      if (layer.options.recID === thisID) {
+        j = j++;
+        layer.options.recStatus = 'active';
+        if (layer.options.recType === "rectangle") {
+          layer.setIcon(blueRectIcon);
+        } else {
+          layer.setIcon(blueIcon);
+        }
+        clickedBounds.push([layer.getLatLng().lat, layer.getLatLng().lng]);
+        if (layer.options.recType === "rectangle") {
+          // create rectangle from options and show
+          var mRect_sw = L.latLng([layer.options.recS, layer.options.recW]);
+          var mRect_ne = L.latLng([layer.options.recN, layer.options.recE]);
+          var mRect = L.rectangle([[mRect_sw, mRect_ne]], {
+            color: '#3388ff',
+            fillOcpacity: 0.1,
+            weight: 2,
+            id: 'mRect'
+          });
+          mRect.bindPopup(L.popup().setContent(layer.options.rmPopup));
+          var mrBounds = mRect.getBounds();
+          clickedBounds.push([
+            [mrBounds.getSouthWest().lat, mrBounds.getSouthWest().lng],
+            [mrBounds.getNorthEast().lat, mrBounds.getNorthEast().lng]
+          ]);
+          mapSearch.addLayer(mRect);
+        }
+      }
+    });
+    markerClusters.refreshClusters();
+
+    // Check if there are multiple markers at this location
+    // If so, update popup to show title for all rectangles by
+    // combining popup content.
+    thisID = this.options.recID;
+    var thisLat = this.getLatLng().lat;
+    var thisLng = this.getLatLng().lng;
+    var updatePopup = [this._popup.getContent()];
+    markerClusters.eachLayer(function mc(layer){
+      var mLat = layer.getLatLng().lat;
+      var mLng = layer.getLatLng().lng;
+      var mPopup = layer._popup.getContent();
+      if ((mLat === thisLat && mLng === thisLng) && updatePopup.indexOf(mPopup) < 0) {
+        updatePopup.push(mPopup);
+      }
+    });
+    this._popup.setContent(updatePopup.join(" "));
+  }
+
   // Searchbox
   //-------------------------------------//
   // Retrieve searchbox coordinates 
@@ -230,87 +311,6 @@ function loadMapSelection(geoField, boundingBox, baseURL, homeURL, searchParams,
     new L.Draw.Rectangle(mapSearch, drawnItems.options.rectangle).enable();
   };
   
-  // Handle user interaction with markers and rectangles
-  //----------------------------------------------------//
-  function onClick() {
-    mapSearch.eachLayer(function msl(layer) {
-      if (layer.options.id === "mRect") {
-        mapSearch.removeLayer(layer);
-      }
-    });
-
-    // Reset previously selected features to inactive color - RED
-    if (clickedIDs.length > 0) {
-      markerClusters.eachLayer(function mcl(layer){
-        if (layer.options.recID === clickedIDs[0]) {
-          layer.options.recStatus = 'inactive';
-          layer._popup.setContent(layer.options.recPopup);
-          if (layer.options.recType === "rectangle") {
-            layer.setIcon(redRectIcon);
-          } else {
-            layer.setIcon(redIcon);
-          } 
-        } 
-      });
-      clickedIDs = []; 
-      clickedBounds = [];
-    }
-    
-    //Handle current feature selection
-    //Change color of all features with thisID to BLUE
-    var thisID = this.options.recID;
-    clickedIDs.push(thisID);
-    var j = 0;
-    markerClusters.eachLayer(function mc(layer){
-      if (layer.options.recID === thisID) {
-        j = j++;
-        layer.options.recStatus = 'active';
-        if (layer.options.recType === "rectangle") {
-          layer.setIcon(blueRectIcon);
-        } else {
-          layer.setIcon(blueIcon);
-        }
-        clickedBounds.push([layer.getLatLng().lat, layer.getLatLng().lng]);
-        if (layer.options.recType === "rectangle") {
-          // create rectangle from options and show
-          var mRect_sw = L.latLng([layer.options.recS, layer.options.recW]);
-          var mRect_ne = L.latLng([layer.options.recN, layer.options.recE]);
-          var mRect = L.rectangle([[mRect_sw, mRect_ne]], {
-            color: '#3388ff',
-            fillOcpacity: 0.1,
-            weight: 2,
-            id: 'mRect'
-          });
-          mRect.bindPopup(L.popup().setContent(layer.options.rmPopup));
-          var mrBounds = mRect.getBounds();
-          clickedBounds.push([
-            [mrBounds.getSouthWest().lat, mrBounds.getSouthWest().lng],
-            [mrBounds.getNorthEast().lat, mrBounds.getNorthEast().lng]
-          ]);
-          mapSearch.addLayer(mRect);
-        }
-      }
-    });
-    markerClusters.refreshClusters();
-
-    // Check if there are multiple markers at this location
-    // If so, update popup to show title for all rectangles by
-    // combining popup content.
-    thisID = this.options.recID;
-    var thisLat = this.getLatLng().lat;
-    var thisLng = this.getLatLng().lng;
-    var updatePopup = [this._popup.getContent()];
-    markerClusters.eachLayer(function mc(layer){
-      var mLat = layer.getLatLng().lat;
-      var mLng = layer.getLatLng().lng;
-      var mPopup = layer._popup.getContent();
-      if ((mLat === thisLat && mLng === thisLng) && updatePopup.indexOf(mPopup) < 0) {
-        updatePopup.push(mPopup);
-      }
-    });
-    this._popup.setContent(updatePopup.join(" "));
-  }
-  
   // If user clicks on map anywhere turn all features to inactive color - RED
   // and reset clicked arrays
   mapSearch.on('click', function ms() {
-- 
GitLab