private static function selectByApplication($appId, $frameName)
 {
     // find the mapframe in the application elements...
     $sql = "SELECT * FROM gui_element WHERE fkey_gui_id = \$1 AND " . "e_id = \$2 AND e_public = 1 LIMIT 1";
     $v = array($appId, $frameName);
     $t = array('s', 's');
     $res = db_prep_query($sql, $v, $t);
     $row = db_fetch_array($res);
     // if found...
     if ($row) {
         $currentMap = new Map();
         // use settings from database
         $currentMap->setWidth($row["e_width"]);
         $currentMap->setHeight($row["e_height"]);
         $currentMap->setFrameName($row["e_id"]);
         // get the WMS
         $wmsArray = wms::selectMyWmsByApplication($appId);
         //			$e = new mb_notice("WMS in this map: " . implode(",", $wmsArray));
         // if this is the overview, find the WMS index and
         // reset the WMS array
         // BEWARE, SUPER UGLY CODE AHEAD!!
         // (BUT THERE IS NO OTHER WAY TO DO IT)
         if (strpos($row["e_js_file"], "mb_overview.js") !== false) {
             //				$e = new mb_exception("guess this is the OV");
             $ov_sql = "SELECT var_value FROM gui_element_vars WHERE " . "var_name = 'overview_wms' AND fkey_e_id = \$1 AND " . "fkey_gui_id = \$2";
             $ov_v = array($frameName, $appId);
             $ov_t = array('s', 's');
             $ov_res = db_prep_query($ov_sql, $ov_v, $ov_t);
             $ov_row = db_fetch_array($ov_res);
             if ($ov_row) {
                 $ovIndex = intval($ov_row["var_value"]);
             }
             //				$e = new mb_exception("OV index: " . $ovIndex);
             if (!isset($ovIndex)) {
                 $ovIndex = 0;
             }
             $wmsArray = array($wmsArray[$ovIndex]);
             //				$e = new mb_notice("WMS in this map (corrected): " . implode(",", $wmsArray));
         } else {
             //				$e = new mb_exception("guess this is NOT the OV");
         }
         $currentMap->wmsArray = $wmsArray;
         // EXTENT
         $sql = "SELECT gui_wms_epsg FROM gui_wms WHERE gui_wms_position = 0 AND fkey_gui_id = \$1";
         $v = array($appId);
         $t = array('s');
         $res = db_prep_query($sql, $v, $t);
         $row = db_fetch_array($res);
         $epsg = $row["gui_wms_epsg"];
         $layer_epsg = $wmsArray[0]->objLayer[0]->layer_epsg;
         $j = 0;
         for ($i = 0; $i < count($layer_epsg); $i++) {
             if ($layer_epsg[$i]["epsg"] === $epsg) {
                 $j = $i;
                 break;
             }
         }
         $minx = $wmsArray[0]->objLayer[0]->layer_epsg[$j]["minx"];
         $miny = $wmsArray[0]->objLayer[0]->layer_epsg[$j]["miny"];
         $maxx = $wmsArray[0]->objLayer[0]->layer_epsg[$j]["maxx"];
         $maxy = $wmsArray[0]->objLayer[0]->layer_epsg[$j]["maxy"];
         $epsg = $wmsArray[0]->objLayer[0]->layer_epsg[$j]["epsg"];
         $mapExtent = new Mapbender_bbox($minx, $miny, $maxx, $maxy, $epsg);
         $currentMap->setExtent($mapExtent);
         return $currentMap;
     } else {
         return null;
     }
 }
 /**
  * Called during WMC parsing; sets the maps within a WMC.
  *
  * @return
  */
 private function setMapData()
 {
     if ($this->generalExtensionArray["OV_WIDTH"] && $this->generalExtensionArray["OV_HEIGHT"] && $this->generalExtensionArray["OV_FRAMENAME"] && $this->generalExtensionArray["OV_MINX"] && $this->generalExtensionArray["OV_MINY"] && $this->generalExtensionArray["OV_MAXX"] && $this->generalExtensionArray["OV_MAXY"] && $this->generalExtensionArray["OV_SRS"]) {
         $this->overviewMap = new Map();
         $this->overviewMap->setWidth(is_array($this->generalExtensionArray["OV_WIDTH"]) ? $this->generalExtensionArray["OV_WIDTH"][0] : $this->generalExtensionArray["OV_WIDTH"]);
         $this->overviewMap->setHeight(is_array($this->generalExtensionArray["OV_HEIGHT"]) ? $this->generalExtensionArray["OV_HEIGHT"][0] : $this->generalExtensionArray["OV_HEIGHT"]);
         $this->overviewMap->setFrameName(is_array($this->generalExtensionArray["OV_FRAMENAME"]) ? $this->generalExtensionArray["OV_FRAMENAME"][0] : $this->generalExtensionArray["OV_FRAMENAME"]);
         $this->overviewMap->setIsOverview(true);
         if (is_array($this->generalExtensionArray["OV_SRS"])) {
             $this->generalExtensionArray["OV_SRS"] = $this->generalExtensionArray["OV_SRS"][0];
             $this->generalExtensionArray["OV_MINX"] = $this->generalExtensionArray["OV_MINX"][0];
             $this->generalExtensionArray["OV_MINY"] = $this->generalExtensionArray["OV_MINY"][0];
             $this->generalExtensionArray["OV_MAXX"] = $this->generalExtensionArray["OV_MAXX"][0];
             $this->generalExtensionArray["OV_MAXY"] = $this->generalExtensionArray["OV_MAXY"][0];
         }
         $bbox = new Mapbender_bbox($this->generalExtensionArray["OV_MINX"], $this->generalExtensionArray["OV_MINY"], $this->generalExtensionArray["OV_MAXX"], $this->generalExtensionArray["OV_MAXY"], $this->generalExtensionArray["OV_SRS"]);
         $this->overviewMap->setExtent($bbox);
     }
     if ($this->generalExtensionArray["EPSG"] && $this->generalExtensionArray["MINX"] && $this->generalExtensionArray["MINY"] && $this->generalExtensionArray["MAXX"] && $this->generalExtensionArray["MAXY"]) {
         $mainEpsgArray = array();
         $mainMinXArray = array();
         $mainMinYArray = array();
         $mainMaxXArray = array();
         $mainMaxYArray = array();
         if (!is_array($this->generalExtensionArray["EPSG"])) {
             $mainEpsgArray[0] = $this->generalExtensionArray["EPSG"];
             $mainMinXArray[0] = $this->generalExtensionArray["MINX"];
             $mainMinYArray[0] = $this->generalExtensionArray["MINY"];
             $mainMaxXArray[0] = $this->generalExtensionArray["MAXX"];
             $mainMaxYArray[0] = $this->generalExtensionArray["MAXY"];
         } else {
             $mainEpsgArray = $this->generalExtensionArray["EPSG"];
             $mainMinXArray = $this->generalExtensionArray["MINX"];
             $mainMinYArray = $this->generalExtensionArray["MINY"];
             $mainMaxXArray = $this->generalExtensionArray["MAXX"];
             $mainMaxYArray = $this->generalExtensionArray["MAXY"];
         }
         for ($i = 0; $i < count($mainEpsgArray); $i++) {
             $box = new Mapbender_bbox(floatval($mainMinXArray[$i]), floatval($mainMinYArray[$i]), floatval($mainMaxXArray[$i]), floatval($mainMaxYArray[$i]), $mainEpsgArray[$i]);
             $this->mainMap->addZoomFullExtent($box);
         }
     }
     if ($this->generalExtensionArray["MAIN_FRAMENAME"]) {
         $this->mainMap->setFrameName(is_array($this->generalExtensionArray["MAIN_FRAMENAME"]) ? $this->generalExtensionArray["MAIN_FRAMENAME"][0] : $this->generalExtensionArray["MAIN_FRAMENAME"]);
     } else {
         $this->mainMap->setFrameName("mapframe1");
     }
     unset($this->generalExtensionArray["OV_WIDTH"]);
     unset($this->generalExtensionArray["OV_HEIGHT"]);
     unset($this->generalExtensionArray["OV_MINX"]);
     unset($this->generalExtensionArray["OV_MINY"]);
     unset($this->generalExtensionArray["OV_MAXX"]);
     unset($this->generalExtensionArray["OV_MAXY"]);
     unset($this->generalExtensionArray["OV_SRS"]);
     unset($this->generalExtensionArray["OV_FRAMENAME"]);
     unset($this->generalExtensionArray["MINX"]);
     unset($this->generalExtensionArray["MINY"]);
     unset($this->generalExtensionArray["MAXX"]);
     unset($this->generalExtensionArray["MAXY"]);
     unset($this->generalExtensionArray["EPSG"]);
     unset($this->generalExtensionArray["MAIN_FRAMENAME"]);
     return true;
 }