/**
  * Display 1st level reference maps -- i.e. create HTML tags, push data into JavaScript to create Google Maps dynamically
  */
 protected function _displayReferenceMaps($args, $overlays)
 {
     $js = "";
     $itemReferencesConfiguration = SELF::_retrieveReferenceElementConfiguration();
     if (!SELF::_needsMaps($itemReferencesConfiguration)) {
         return;
     }
     if (SELF::$_withGeoLoc and SELF::$_geoLocations) {
         $output = "<h2>" . __("Geolocations of References Items") . "</h2>\n";
         $itemReferencesMapHeight = intval(get_option('item_references_map_height'));
         if (!$itemReferencesMapHeight) {
             $itemReferencesMapHeight = ITEM_REFERENCES_MAP_HEIGHT_DEFAULT;
         }
         $mapsData = array();
         $db = get_db();
         foreach (SELF::$_geoLocations as $elementId => $referenceMap) {
             if ($referenceMap and $itemReferencesConfiguration[$elementId][0] > 0) {
                 $sql = "SELECT name FROM {$db->Elements} WHERE id = {$elementId}";
                 $elementName = $db->fetchOne($sql);
                 $output .= "<h4>{$elementName}</h4>\n";
                 $isLineReference = intval($itemReferencesConfiguration[$elementId][0] == 2);
                 $data = array("mapId" => "map" . $elementId, "coords" => array(), "line" => $isLineReference, "color" => intval($itemReferencesConfiguration[$elementId][1]));
                 $reqOverlays = array();
                 $distances = array();
                 $lastPin = null;
                 foreach ($referenceMap as $pin) {
                     if ($pin) {
                         $data["coords"][] = array("title" => $pin["geo_title"], "lat" => $pin["latitude"], "lng" => $pin["longitude"], "url" => $pin["url"], "ovl" => $pin["overlay"], "zl" => $pin["zoom_level"]);
                         if ($lastPin and $isLineReference) {
                             $distances[] = array("fromTitle" => "<a href='" . $lastPin["url"] . "'>" . $lastPin["geo_title"] . "</a>", "toTitle" => "<a href='" . $pin["url"] . "'>" . $pin["geo_title"] . "</a>", "linDistance" => number_format(SELF::_getDistanceFromLatLonInKm($pin["latitude"], $pin["longitude"], $lastPin["latitude"], $lastPin["longitude"]), 3, ",", ".") . " km");
                         }
                         $lastPin = $pin;
                         if (isset($reqOverlays[$pin["overlay"]])) {
                             $reqOverlays[$pin["overlay"]]++;
                         } else {
                             $reqOverlays[$pin["overlay"]] = 1;
                         }
                     }
                 }
                 $ovlDefault = -1;
                 if (count($reqOverlays) == 1) {
                     $ovlDefault = array_keys($reqOverlays)[0];
                 }
                 $distHtml = "";
                 if ($distances) {
                     $distHtml .= "<h5>" . __("Linear Distances") . "</h5>\n";
                     $distHtml .= "<table>";
                     $distHtml .= "<thead><tr>";
                     $distHtml .= "<th>" . __("Start Point") . "</th>";
                     $distHtml .= "<th>" . __("End Point") . "</th>";
                     $distHtml .= "<th style='text-align:right;'>" . __("Linear Distance") . "</th>";
                     $distHtml .= "</tr></thead>\n";
                     $distHtml .= "<tbody>\n";
                     foreach ($distances as $distance) {
                         $distHtml .= "<tr>";
                         $distHtml .= "<td>" . $distance["fromTitle"] . "</td>";
                         $distHtml .= "<td>" . $distance["toTitle"] . "</td>";
                         $distHtml .= "<td style='text-align:right;'>" . $distance["linDistance"] . "</td>";
                         $distHtml .= "</tr>\n";
                     }
                     $distHtml .= "</tbody>\n";
                     $distHtml .= "</table>\n";
                 }
                 $output .= "<div id='" . $data["mapId"] . "' style='height:" . $itemReferencesMapHeight . "px; width:100%;'></div>\n";
                 $curCount = count($mapsData);
                 if ($overlays) {
                     $output .= '<div class="reference_ovl_options"><strong>' . __("Select Map Overlay:") . '</strong> ' . get_view()->formSelect($data["mapId"] . "_ovl", $ovlDefault, array("class" => "refMapOvlSel", "data-map-arr" => $curCount), $overlays["jsSelect"]) . "<span class='refMapOvlSlider' id='" . $data["mapId"] . "_slider' data-map-arr='" . $curCount . "'></span>" . $distHtml . "</div>";
                 }
                 $mapsData[] = $data;
             }
         }
         if ($mapsData) {
             echo $output;
             $js .= "var mapsData=" . json_encode($mapsData) . ";\n";
         }
     }
     return $js;
 }