Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
Bradley Cornford committed Jan 3, 2017
2 parents 226cb1c + ca6d5bb commit ca34ef0
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 32 deletions.
9 changes: 5 additions & 4 deletions spec/Cornford/Googlmapper/MapperSpec.php
Expand Up @@ -6,7 +6,6 @@

class MapperSpec extends ObjectBehavior
{

const STRING = 'test';
const LOCATION = 'Sheffield, United Kingdom';
const INTEGER = 10;
Expand All @@ -18,6 +17,8 @@ class MapperSpec extends ObjectBehavior

const ANIMATION = 'NONE';

const API_KEY = 'AIzaSyAtqWsq5Ai3GYv6dSa6311tZiYKlbYT4mw';

public function let()
{
$location = Mockery::mock('Cornford\Googlmapper\Models\Location');
Expand Down Expand Up @@ -47,19 +48,19 @@ public function it_throws_an_exception_with_incorrect_options()

public function it_can_return_a_location_when_a_location_is_searched()
{
$this->setKey('AIzaSyAtqWsq5Ai3GYv6dSa6311tZiYKlbYT4mw');
$this->setKey(self::API_KEY);
$this->location(self::LOCATION)->shouldReturnAnInstanceOf('Cornford\Googlmapper\Models\Location');
}

public function it_throws_an_exception_when_a_blank_location_is_searched()
{
$this->setKey('AIzaSyAtqWsq5Ai3GYv6dSa6311tZiYKlbYT4mw');
$this->setKey(self::API_KEY);
$this->shouldThrow('Cornford\Googlmapper\Exceptions\MapperArgumentException')->during('location', ['']);
}

public function it_throws_an_exception_when_an_invalid_location_is_searched()
{
$this->setKey('AIzaSyAtqWsq5Ai3GYv6dSa6311tZiYKlbYT4mw');
$this->setKey(self::API_KEY);
$this->shouldThrow('Cornford\Googlmapper\Exceptions\MapperSearchResultException')->during('location', ['abcdefghijklmnopqrstuvwxyz']);
}

Expand Down
92 changes: 64 additions & 28 deletions src/Cornford/Googlmapper/Mapper.php
Expand Up @@ -253,14 +253,20 @@ public function streetview($latitude, $longitude, $heading, $pitch, array $optio
public function marker($latitude, $longitude, array $options = [])
{
$items = $this->getItems();
$parameters = $this->getOptions();
$options = array_replace_recursive(['user' => $parameters['user']], $parameters['markers'], $options);

if (empty($items)) {
throw new MapperException('No map found to add a marker to.');
}

$item = end($items);
$parameters = $this->getOptions();
$options = array_replace_recursive(
['user' => $parameters['user']],
['markers' => $parameters['markers']],
$item->getOptions()['markers'],
$options
);

$item->marker($latitude, $longitude, $options);

return $this;
Expand All @@ -286,9 +292,15 @@ public function informationWindow($latitude, $longitude, $content, array $option
throw new MapperException('No map found to add a information window to.');
}

$parameters = $this->getOptions();
$options = array_replace_recursive(['user' => $parameters['user']], ['markers' => $parameters['markers']], $options);
$item = end($items);
$parameters = $this->getOptions();
$options = array_replace_recursive(
['user' => $parameters['user']],
['markers' => $parameters['markers']],
$item->getOptions()['markers'],
$options
);

$item->marker($latitude, $longitude, array_replace_recursive($options, ['markers' => ['content' => $content]]));

return $this;
Expand All @@ -307,7 +319,10 @@ public function informationWindow($latitude, $longitude, $content, array $option
public function polyline(array $coordinates = [], array $options = [])
{
$items = $this->getItems();
$parameters = $this->getOptions();

if (empty($items)) {
throw new MapperException('No map found to add a polyline to.');
}

$defaults = [
'coordinates' => $coordinates,
Expand All @@ -317,13 +332,16 @@ public function polyline(array $coordinates = [], array $options = [])
'strokeWeight' => 2,
'editable' => false
];
$options = array_replace_recursive(['user' => $parameters['user']], $defaults, $options);

if (empty($items)) {
throw new MapperException('No map found to add a polyline to.');
}
$item = end($items);
$parameters = $this->getOptions();
$options = array_replace_recursive(
['user' => $parameters['user']],
$defaults,
['user' => $item->getOptions()['user']],
$options
);

$item = end($items);
$item->shape('polyline', $coordinates, $options);

return $this;
Expand All @@ -342,7 +360,10 @@ public function polyline(array $coordinates = [], array $options = [])
public function polygon(array $coordinates = [], array $options = [])
{
$items = $this->getItems();
$parameters = $this->getOptions();

if (empty($items)) {
throw new MapperException('No map found to add a polygon to.');
}

$defaults = [
'coordinates' => $coordinates,
Expand All @@ -353,13 +374,16 @@ public function polygon(array $coordinates = [], array $options = [])
'fillOpacity' => 0.35,
'editable' => false
];
$options = array_replace_recursive(['user' => $parameters['user']], $defaults, $options);

if (empty($items)) {
throw new MapperException('No map found to add a polygon to.');
}

$item = end($items);
$parameters = $this->getOptions();
$options = array_replace_recursive(
['user' => $parameters['user']],
$defaults,
['user' => $item->getOptions()['user']],
$options
);

$item->shape('polygon', $coordinates, $options);

return $this;
Expand All @@ -378,7 +402,10 @@ public function polygon(array $coordinates = [], array $options = [])
public function rectangle(array $coordinates = [], array $options = [])
{
$items = $this->getItems();
$parameters = $this->getOptions();

if (empty($items)) {
throw new MapperException('No map found to add a rectangle to.');
}

$defaults = [
'coordinates' => $coordinates,
Expand All @@ -389,13 +416,16 @@ public function rectangle(array $coordinates = [], array $options = [])
'fillOpacity' => 0.35,
'editable' => false
];
$options = array_replace_recursive(['user' => $parameters['user']], $defaults, $options);

if (empty($items)) {
throw new MapperException('No map found to add a rectangle to.');
}

$item = end($items);
$parameters = $this->getOptions();
$options = array_replace_recursive(
['user' => $parameters['user']],
$defaults,
['user' => $item->getOptions()['user']],
$options
);

$item->shape('rectangle', $coordinates, $options);

return $this;
Expand All @@ -414,7 +444,10 @@ public function rectangle(array $coordinates = [], array $options = [])
public function circle(array $coordinates = [], array $options = [])
{
$items = $this->getItems();
$parameters = $this->getOptions();

if (empty($items)) {
throw new MapperException('No map found to add a circle to.');
}

$defaults = [
'coordinates' => $coordinates,
Expand All @@ -426,13 +459,16 @@ public function circle(array $coordinates = [], array $options = [])
'radius' => 100000,
'editable' => false
];
$options = array_replace_recursive(['user' => $parameters['user']], $defaults, $options);

if (empty($items)) {
throw new MapperException('No map found to add a circle to.');
}

$item = end($items);
$parameters = $this->getOptions();
$options = array_replace_recursive(
['user' => $parameters['user']],
$defaults,
['user' => $item->getOptions()['user']],
$options
);

$item->shape('circle', $coordinates, $options);

return $this;
Expand Down

0 comments on commit ca34ef0

Please sign in to comment.