/** * draws an outlined two color polygon * * @param int $im image identifier as returned by ImageCreateFromGIF() etc. * @param string $coords coordinate string, format : "x1,y1,x2,y2,..." with every (x,y) pair is * an ending point of a line of the polygon * @param int $c1 color identifier 1 * @param int $c3 color identifier 2 * @param boolean $closed true: the first and the last point will be connected with a line */ function drawPoly(&$im, $coords, $c1, $c2, $closed, $a_x_ratio = 1, $a_y_ratio = 1) { if ($closed) { $p = 0; } else { $p = 1; } $anz = ilMapArea::countCoords($coords); if ($anz < 3 - $p) { return; } $c = explode(",", $coords); for ($i = 0; $i < $anz - $p; $i++) { $this->drawLine($im, $c[$i * 2] / $a_x_ratio, $c[$i * 2 + 1] / $a_y_ratio, $c[($i * 2 + 2) % (2 * $anz)] / $a_x_ratio, $c[($i * 2 + 3) % (2 * $anz)] / $a_y_ratio, $c1, $c2); } }
/** * edit shape of existing map area */ function setShape($a_handle = true) { global $lng, $ilCtrl; if ($a_handle) { $this->handleMapParameters(); } if ($_POST["areatype2"] != "") { $_SESSION["il_map_edit_area_type"] = $_POST["areatype2"]; } if ($_SESSION["il_map_area_nr"] != "") { $_POST["area"][0] = $_SESSION["il_map_area_nr"]; } if (!isset($_POST["area"])) { ilUtil::sendFailure($lng->txt("no_checkbox"), true); $ilCtrl->redirect($this, "editMapAreas"); } if (count($_POST["area"]) > 1) { ilUtil::sendFailure($lng->txt("cont_select_max_one_item"), true); $ilCtrl->redirect($this, "editMapAreas"); } if ($_SESSION["il_map_edit_mode"] != "edit_shape") { $_SESSION["il_map_area_nr"] = $_POST["area"][0]; $_SESSION["il_map_edit_mode"] = "edit_shape"; $_SESSION["il_map_edit_target_script"] = $ilCtrl->getLinkTarget($this, "setShape", "", false, false); } $area_type = $_SESSION["il_map_edit_area_type"]; $coords = $_SESSION["il_map_edit_coords"]; $cnt_coords = ilMapArea::countCoords($coords); // decide what to do next switch ($area_type) { // Rectangle case "Rect": if ($cnt_coords < 2) { return $this->editMapArea(true, false, false, "shape", $_POST["area"][0]); } else { if ($cnt_coords == 2) { return $this->saveArea(); } } break; // Circle // Circle case "Circle": if ($cnt_coords <= 1) { return $this->editMapArea(true, false, false, "shape", $_POST["area"][0]); } else { if ($cnt_coords == 2) { $c = explode(",", $coords); $coords = $c[0] . "," . $c[1] . ","; // determine radius $coords .= round(sqrt(pow(abs($c[3] - $c[1]), 2) + pow(abs($c[2] - $c[0]), 2))); } $_SESSION["il_map_edit_coords"] = $coords; return $this->saveArea(); } break; // Polygon // Polygon case "Poly": if ($cnt_coords < 1) { return $this->editMapArea(true, false, false, "shape", $_POST["area"][0]); } else { if ($cnt_coords < 3) { return $this->editMapArea(true, true, false, "shape", $_POST["area"][0]); } else { return $this->editMapArea(true, true, true, "shape", $_POST["area"][0]); } } break; // Whole Picture // Whole Picture case "WholePicture": return $this->saveArea(); } }