cnt_item = -1; $this->setMemberType($type); } function setAttribute($attribTag, $attrib) { $this->attributes[$attribTag] = $attrib; } function setMemberType($type) { $this->memberType = $type; } function addPolygon () { $this->cnt_item++; $this->geometry[$this->cnt_item] = new _polygon(); } function addLine () { $this->cnt_item++; $this->geometry[$this->cnt_item] = new _line(); } function addPoint () { $this->cnt_item++; $this->geometry[$this->cnt_item] = new _point(); } # function addCoordinates ($coord, $pos) { # $this->geometry[$this->cnt_item]->addCoordinates($coord, $pos); # } function addCoordinates ($coord) { $this->geometry[$this->cnt_item]->addCoordinates($coord); } function addLabel($label) { $this->geometry[$this->cnt_item]->setLabel($label); } function addToPng($image, $bbox, $width, $height, $line, $text, $label) { $pos = array(); $pos_next = array(); for ($j=0; $j < count($this->geometry); $j++) { $coord = $this->geometry[$j]->getCoordinates(); if ($this->geometry[$j]->getType() == "point") { $topOffset = imagefontheight(2); $pos = $this->makeRealWorld2mapPos($bbox, $width, $height, $coord["x"][0],$coord["y"][0]); imagestring ($image, 2,$pos["x"], ($pos["y"] - $topOffset), $this->getAttribute($label), $text); imageellipse($image, $pos["x"], $pos["y"], 5, 5, $line); } else { for($k=0; $k < count($coord["x"])-1; $k++){ $pos = $this->makeRealWorld2mapPos($bbox, $width, $height, $coord["x"][$k],$coord["y"][$k]); $pos_next = $this->makeRealWorld2mapPos($bbox, $width, $height, $coord["x"][$k+1],$coord["y"][$k+1]); imageline($image,$pos["x"],$pos["y"],$pos_next["x"],$pos_next["y"],$line); } } return $image; } } function getAllGeom() { return $this->geometry; } function getAllAttributes() { return $this->attributes; } function getAllAttributeKeys() { return array_keys($this->attributes); } function getAttribute($name) { if (array_key_exists($name, $this->attributes)) { return $this->attributes["$name"]; } else { return ""; } } function getGeomObj($index) { return $this->geometry[$index]; } function getMemberType() { return $this->memberType; } function getMemberSize() { return count($this->geometry); } function getGeomSize($i) { return count($this->geometry[$i]); } function getJavaObjStr($bbox, $width, $height) { $str = ""; for ($j=0; $j < count($this->geometry); $j++) { $coord = $this->geometry[$j]->getCoordinates(); $str .= "register_D('" . $this->geometry[$j]->getType() . "');"; if ($this->geometry[$j]->getType() == "point" && $this->geometry[$j]->getLabel()) { $str .= "D[D.length-1].label = '" . $this->geometry[$j]->getLabel() . "';"; } for($k=0; $k < count($coord["x"]); $k++){ $pos = $this->makeRealWorld2mapPos($bbox, $width, $height,$coord["x"][$k],$coord["y"][$k]); $str .= "D[D.length-1].x[D[D.length-1].x.length] = Math.round(" . $coord["x"][$k] . " * 100)/100;"; $str .= "D[D.length-1].y[D[D.length-1].y.length] = Math.round(" . $coord["y"][$k] . " * 100)/100;"; } $str .= "D[D.length-1].complete = true;"; } return $str; } function makeRealWorld2mapPos($bbox, $width, $height, $x,$y){ $minx = $bbox[0]; $miny = $bbox[1]; $maxx = $bbox[2]; $maxy = $bbox[3]; $xtentx = $maxx - $minx; $xtenty = $maxy - $miny; if ($xtenty != 0 && $xtentx != 0) { $posx = (($x - $minx) / $xtentx) * $width; $posy = (($maxy - $y) / $xtenty) * $height; $pos = array("x" => $posx, "y" => $posy); return $pos; } if ($xtenty == 0 || $xtentx == 0) { $mb_exception = new mb_exception("Division by zero in makeRealWorld2mapPos"); return 0; } } } ?>