/** {@inheritdoc} */ public function draw($canvas) { $scale = $this->map->getZoomScale(); $vp = $this->map->getViewport(); $xOffset = -$vp->left; $yOffset = -$vp->top; $poly = array(); $xCenter = 0; $yCenter = 0; foreach ($this->xy as $pos) { $x = $xOffset + $pos->x * $scale; $y = $yOffset + $pos->y * $scale; $poly[] = $x; $poly[] = $y; $xCenter += $x; $yCenter += $y; } // we need at least 2 points to draw a line $nbPoints = count($poly) / 2; if ($nbPoints < 2) { return false; } $xCenter = $xCenter / $nbPoints; $yCenter = $yCenter / $nbPoints; $color = $this->color->allocate($canvas); if ($this->fillcolor) { if ($nbPoints == 2) { // filled polygon needs at least 3 points $poly[] = $poly[0]; $poly[] = $poly[1]; ++$nbPoints; } imagesetthickness($canvas, 1); imagefilledpolygon($canvas, $poly, $nbPoints, $this->fillcolor->allocate($canvas)); imagesetthickness($canvas, $this->weight); imagepolygon($canvas, $poly, $nbPoints, $color); } else { imagesetthickness($canvas, $this->weight); imagesetthickness($canvas, $this->weight); for ($i = 0; $i < count($poly) - 2; $i++) { imageline($canvas, $poly[$i], $poly[$i + 1], $poly[$i + 2], $poly[$i + 3], $color); $i++; } } if ($this->label) { // white/black $label = new Label($this->label); $label->setPos(new Point($xCenter, $yCenter)); $label->setColor($this->color); $label->setOutline(new Color(0, 0, 0), 1); $label->draw($canvas); } return true; }
/** {@inheritdoc} */ public function draw($canvas) { $icon = false; if ($this->icon && $this->icon !== 'none') { $icon = new Icon($this->icon); if ($this->color) { $icon->setColor($this->color); } } $label = false; if ($this->label) { $label = new Label($this->label); $label->setColor($this->fontColor); $label->setOutline($this->fontOutline, 1); $label->setOffset(0, 5); // background with same color as marker, but 50% transparency if ($this->color) { $bg = clone $this->color; } else { $bg = new Color(0, 0, 0); } $bg->a = 127; $label->setBackground($bg); } $scale = $this->map->getZoomScale(); $vp = $this->map->getViewport(); $xOffset = -$vp->left; $yOffset = -$vp->top; foreach ($this->xy as $point) { $p = new Point($point->x * $scale + $xOffset, $point->y * $scale + $yOffset); if ($this->circleRadiusHoriz) { // TODO: stroke width, circle color, fill color if ($this->color) { $c = $this->color->allocate($canvas); } else { $c = imagecolorallocate($canvas, 255, 0, 0); } // at least 1px circle is drawed $h = max(1, $this->circleRadiusHoriz * 2 * $this->map->getZoomScale()); $v = max(1, $this->circleRadiusVert * 2 * $this->map->getZoomScale()); if ($this->circleFillColor) { $fc = $this->circleFillColor->allocate($canvas); imagefilledellipse($canvas, $p->x, $p->y, $h, $v, $fc); } imagesetthickness($canvas, $this->circleStrokeWeight); imageellipse($canvas, $p->x, $p->y, $h, $v, $c); } if ($icon) { $icon->setPos($p); $icon->draw($canvas); } if ($label) { $label->setPos($p); // +5 is in pixel scale $label->draw($canvas); } } return true; }