isWestOf($max) && $min->isSouthOf($max)) || $min->equals($max)) { if ($min->epsg == $max->epsg && $min->epsg == $epsg) { $this->min = $min; $this->max = $max; $this->epsg = $epsg; } else { $e = new mb_exception("Mapbender_bbox: constructor: EPSG mismatch!"); } } else { $e = new mb_exception("Mapbender_bbox: constructor: min (".$this->min.") is not southwest of max (".$this->max.")!"); } } // params are x1, y1, x2, xy, epsg else if (is_numeric($param0) && is_numeric($param1) && is_numeric($param2) && is_numeric($param3) && is_string($param4)) { $e = new mb_notice("Mapbender_bbox: constructor: x1, y1, x2, y2, epsg"); $min = new Mapbender_point(floatval($param0), floatval($param1), $param4); $max = new Mapbender_point(floatval($param2), floatval($param3), $param4); $epsg = $param4; // is an EPSG code like "EPSG:4326" if ($min->isWestOf($max) && $min->isSouthOf($max)) { if ($min->epsg == $max->epsg && $min->epsg == $epsg) { $this->min = $min; $this->max = $max; $this->epsg = $epsg; } else { $e = new mb_exception("Mapbender_bbox: constructor: EPSG mismatch!"); } } else { $e = new mb_exception("Mapbender_bbox: constructor: min (".$this->min.") is not southwest of max (".$this->max.")!"); } } else { throw new Exception("invalid parameters to Mapbender_bbox"); } } public static function createFromLayerEpsg ($c) { return new Mapbender_bbox( $c["minx"], $c["miny"], $c["maxx"], $c["maxy"], $c["epsg"] ); } /** * Computes a new bounding box, bbox1 UNION bbox2 */ static function union ($bboxArray) { if (count($bboxArray) == 1) { return array_pop($bboxArray); } elseif (count($bboxArray) >= 2) { $bbox1 = array_pop($bboxArray); $bbox2 = Mapbender_bbox::union($bboxArray); if (!($bbox1 != null && $bbox1->isValid()) && !($bbox2 != null && $bbox2->isValid())) { $e = new mb_exception("Mapbender_bbox: union: both parameters invalid!"); return null; } elseif (!($bbox1 != null && $bbox1->isValid()) && ($bbox2 != null && $bbox2->isValid())) { $e = new mb_exception("Mapbender_bbox: union: first parameter invalid!"); return $bbox2; } elseif (($bbox1 != null && $bbox1->isValid()) && !($bbox2 != null && $bbox2->isValid())) { $e = new mb_exception("Mapbender_bbox: union: second parameter invalid!"); return $bbox1; } else { if ($bbox1->epsg == $bbox2->epsg) { $e = new mb_notice("Mapbender_bbox: union: bbox1 is: " . $bbox1); $e = new mb_notice("Mapbender_bbox: union: bbox2 is: " . $bbox2); $e = new mb_notice("Mapbender_bbox: union: merging bbox1 and bbox2..."); return new Mapbender_bbox(Mapbender_point::min($bbox1->min, $bbox2->min), Mapbender_point::max($bbox1->max, $bbox2->max), $bbox1->epsg); } else { $e = new mb_exception("Mapbender_bbox: cannot process union with different EPSG codes"); } } } else { $e = new mb_exception("Mapbender_bbox: Invalid parameter (Not an array)!"); } return null; } /** * transforms this bbox in another EPSG * @param toEpsg transform the bbox to this EPSG code, example: "EPSG:4326" */ function transform($toEpsg) { if ($this->isValid()) { $this->epsg = $toEpsg; $this->min->transform($toEpsg); $this->max->transform($toEpsg); return true; } return false; } /** * checks if lower left and upper right coordinate are set, as well as EPSG */ function isValid() { if ($this->min != null && $this->max != null && $this->epsg != null) { return true; } $e = new mb_exception("Mapbender_bbox: this is not a valid bbox!"); return false; } function toHtml () { return (string) $this->min->toHtml() . " | " . $this->max->toHtml(); } function __toString() { return (string) "[" . $this->min . $this->max . " " . $this->epsg . "]"; } function toJson() { return (string) "[" . $this->min->x . ",". $this->min->y . "," . $this->max->x . "," . $this->max->y . "]"; } function toJavaScript () { return (string) "{" . "srs: '" . $this->epsg . "'," . "extent: new Mapbender.Extent(" . $this->min->x . ", " . $this->min->y . ", " . $this->max->x . ", " . $this->max->y . ")}"; } } ?>