Exemplo n.º 1
0
 /**
  * @param \Bmsite\Maps\StaticMap\StaticMapGenerator $map
  * @param int $maxZoom
  */
 public function __construct(StaticMapGenerator $map, $maxZoom)
 {
     $this->map = $map;
     $this->proj = $map->getProjection();
     $this->debug = $map->getDebug();
     $this->mapname = $map->getMapName();
     $this->maxZoom = $maxZoom;
 }
Exemplo n.º 2
0
 /** {@inheritdoc} */
 public function draw($canvas)
 {
     $zoom = $this->map->getZoom();
     $proj = $this->map->getProjection();
     $vp = $this->map->getViewport();
     foreach ($this->features as $feature) {
         $feature->draw($proj, $canvas, -$vp->left, -$vp->top, $zoom);
     }
 }
Exemplo n.º 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;
 }
Exemplo n.º 4
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;
     }
     $icon = $this->loadIcon();
     if (!$icon) {
         return false;
     }
     $width = imagesx($icon);
     $height = imagesy($icon);
     $w = $this->size[0];
     $h = $this->size[1];
     $x = $p->x - $w / 2 + $xOffset;
     $y = $p->y - $h / 2 + $yOffset;
     if ($w != $width || $h != $height) {
         imagecopyresampled($canvas, $icon, $x, $y, 0, 0, $w, $h, $width, $height);
     } else {
         imagecopy($canvas, $icon, $x, $y, 0, 0, $width, $height);
     }
     imagedestroy($icon);
     return true;
 }
Exemplo n.º 5
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;
 }
Exemplo n.º 6
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;
 }
Exemplo n.º 7
0
 /**
  * Parse location x/y
  *
  * @param string $val
  *
  * @return mixed
  */
 protected function parseLocation($val)
 {
     $ret = false;
     $pairs = explode(',', $val);
     if (count($pairs) == 2 && is_numeric($pairs[0]) && is_numeric($pairs[1])) {
         $x = (double) $pairs[0];
         $y = (double) $pairs[1];
         $proj = $this->map->getProjection();
         try {
             $ret = $proj->project(new Point($x, $y));
         } catch (\InvalidArgumentException $e) {
             // ignore point
         }
     }
     return $ret;
 }