示例#1
0
 /** {@inheritdoc} */
 public function draw($canvas)
 {
     if ($this->map) {
         $scale = $this->map->getZoomScale();
         $vp = $this->map->getViewport();
         $xOffset = -$vp->left;
         $yOffset = -$vp->top;
         $p = new Point($this->pos->x * $scale, $this->pos->y * $scale);
     } else {
         $p = $this->pos;
         $xOffset = 0;
         $yOffset = 0;
     }
     $font = $this->getFont();
     $bbox = $this->getTextBbox();
     // bottom-left corner
     $x = $p->x - $bbox->getWidth() / 2 - $bbox->left + $xOffset + $this->relOffsetX;
     $y = $p->y + $bbox->getHeight() - $bbox->bottom + $yOffset + $this->relOffsetY;
     if ($this->background) {
         $s = $this->background->allocate($canvas);
         imagefilledrectangle($canvas, $x + $bbox->left, $y + $bbox->bottom + 1, $x + $bbox->right - 1, $y + $bbox->top, $s);
     }
     if ($this->outlineColor) {
         $s = $this->outlineColor->allocate($canvas);
         $dd = $this->outlineWidth;
         for ($dx = -$dd; $dx <= $dd; $dx++) {
             for ($dy = -$dd; $dy <= $dd; $dy++) {
                 imagettftext($canvas, $this->fontSize, 0, $x + $dx, $y + $dy, $s, $font, $this->text);
             }
         }
     }
     $c = $this->color->allocate($canvas);
     imagettftext($canvas, $this->fontSize, 0, $x, $y, $c, $font, $this->text);
     return true;
 }
示例#2
0
 /** {@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;
 }
示例#3
0
 /** {@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;
 }