Skip to content
This repository has been archived by the owner on Aug 28, 2020. It is now read-only.

Commit

Permalink
Added ability to set custom icon URLs
Browse files Browse the repository at this point in the history
  • Loading branch information
bensquire committed Nov 20, 2017
1 parent 9bb9fc3 commit e45d40e
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 5 deletions.
2 changes: 1 addition & 1 deletion examples/example3.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
$marker->setSize('mid');
$marker->setLongitude(-0.062004);
$marker->setLatitude(51.462564);
$marker->setLabel('b');
$marker->setLabel('D');

$map = new \GoogleStaticMap\Map();
$map->setCenter('London,UK');
Expand Down
4 changes: 1 addition & 3 deletions examples/example4.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,9 @@
*/

$marker = new \GoogleStaticMap\Marker();
$marker->setColor('blue');
$marker->setSize('mid');
$marker->setLongitude(-0.062004);
$marker->setLatitude(51.462564);
$marker->setLabel('C');
$marker->setIconUrl('https://goo.gl/5y3S82');

$marker2 = new \GoogleStaticMap\Marker();
$marker2->setColor('red');
Expand Down
47 changes: 46 additions & 1 deletion src/GoogleStaticMap/Marker.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,40 @@ class Marker
{
public const SEPARATOR = '|';

/**
* @var array
*/
protected $validMarkerSizes = ['tiny', 'mid', 'small'];

/**
* @var string
*/
protected $longitude = '';

/**
* @var string
*/
protected $latitude = '';

/**
* @var string
*/
protected $label = '';

/**
* @var string
*/
protected $colour = '';

/**
* @var string
*/
protected $size = '';
protected $customIcon = ''; //TODO implement

/**
* @var ?string
*/
protected $customIcon = null;

/**
* Output the marker url string
Expand Down Expand Up @@ -98,6 +125,16 @@ public function setSize(string $size)
return $this;
}

/**
* @param string $url
* @return Marker
*/
public function setIconUrl(string $url)
{
$this->customIcon = $url;
return $this;
}

/**
* Return the marker longitude
*
Expand Down Expand Up @@ -148,6 +185,13 @@ public function getSize(): string
return $this->size;
}

/**
* @return null|string
*/
public function getIconUrl(): ?string
{
return $this->customIcon;
}
/**
* Return the marker url string
*
Expand All @@ -156,6 +200,7 @@ public function getSize(): string
public function build(): string
{
return 'markers=' .
((!empty($this->customIcon)) ? 'icon:' . urlencode($this->customIcon . $this::SEPARATOR) : '') .
((!empty($this->colour)) ? 'color:' . urlencode($this->colour . $this::SEPARATOR) : '') .
((!empty($this->label)) ? 'label:' . urlencode($this->label . $this::SEPARATOR) : '') .
((!empty($this->size)) ? 'size:' . urlencode($this->size . $this::SEPARATOR) : '') .
Expand Down

0 comments on commit e45d40e

Please sign in to comment.