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

Commit e45d40e

Browse files
committed
Added ability to set custom icon URLs
1 parent 9bb9fc3 commit e45d40e

File tree

3 files changed

+48
-5
lines changed

3 files changed

+48
-5
lines changed

examples/example3.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
$marker->setSize('mid');
1313
$marker->setLongitude(-0.062004);
1414
$marker->setLatitude(51.462564);
15-
$marker->setLabel('b');
15+
$marker->setLabel('D');
1616

1717
$map = new \GoogleStaticMap\Map();
1818
$map->setCenter('London,UK');

examples/example4.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,9 @@
88
*/
99

1010
$marker = new \GoogleStaticMap\Marker();
11-
$marker->setColor('blue');
12-
$marker->setSize('mid');
1311
$marker->setLongitude(-0.062004);
1412
$marker->setLatitude(51.462564);
15-
$marker->setLabel('C');
13+
$marker->setIconUrl('https://goo.gl/5y3S82');
1614

1715
$marker2 = new \GoogleStaticMap\Marker();
1816
$marker2->setColor('red');

src/GoogleStaticMap/Marker.php

Lines changed: 46 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,40 @@ class Marker
1717
{
1818
public const SEPARATOR = '|';
1919

20+
/**
21+
* @var array
22+
*/
2023
protected $validMarkerSizes = ['tiny', 'mid', 'small'];
24+
25+
/**
26+
* @var string
27+
*/
2128
protected $longitude = '';
29+
30+
/**
31+
* @var string
32+
*/
2233
protected $latitude = '';
34+
35+
/**
36+
* @var string
37+
*/
2338
protected $label = '';
39+
40+
/**
41+
* @var string
42+
*/
2443
protected $colour = '';
44+
45+
/**
46+
* @var string
47+
*/
2548
protected $size = '';
26-
protected $customIcon = ''; //TODO implement
49+
50+
/**
51+
* @var ?string
52+
*/
53+
protected $customIcon = null;
2754

2855
/**
2956
* Output the marker url string
@@ -98,6 +125,16 @@ public function setSize(string $size)
98125
return $this;
99126
}
100127

128+
/**
129+
* @param string $url
130+
* @return Marker
131+
*/
132+
public function setIconUrl(string $url)
133+
{
134+
$this->customIcon = $url;
135+
return $this;
136+
}
137+
101138
/**
102139
* Return the marker longitude
103140
*
@@ -148,6 +185,13 @@ public function getSize(): string
148185
return $this->size;
149186
}
150187

188+
/**
189+
* @return null|string
190+
*/
191+
public function getIconUrl(): ?string
192+
{
193+
return $this->customIcon;
194+
}
151195
/**
152196
* Return the marker url string
153197
*
@@ -156,6 +200,7 @@ public function getSize(): string
156200
public function build(): string
157201
{
158202
return 'markers=' .
203+
((!empty($this->customIcon)) ? 'icon:' . urlencode($this->customIcon . $this::SEPARATOR) : '') .
159204
((!empty($this->colour)) ? 'color:' . urlencode($this->colour . $this::SEPARATOR) : '') .
160205
((!empty($this->label)) ? 'label:' . urlencode($this->label . $this::SEPARATOR) : '') .
161206
((!empty($this->size)) ? 'size:' . urlencode($this->size . $this::SEPARATOR) : '') .

0 commit comments

Comments
 (0)