Permalink
Browse files

Merge branch 'develop'

  • Loading branch information...
2 parents 226cb1c + ca6d5bb commit ca34ef0b8d51e869ea54eaa2fdf8a84efe69077b Bradley Cornford committed Jan 3, 2017
Showing with 69 additions and 32 deletions.
  1. +5 −4 spec/Cornford/Googlmapper/MapperSpec.php
  2. +64 −28 src/Cornford/Googlmapper/Mapper.php
@@ -6,7 +6,6 @@
class MapperSpec extends ObjectBehavior
{
-
const STRING = 'test';
const LOCATION = 'Sheffield, United Kingdom';
const INTEGER = 10;
@@ -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');
@@ -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']);
}
@@ -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;
@@ -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;
@@ -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,
@@ -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;
@@ -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,
@@ -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;
@@ -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,
@@ -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;
@@ -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,
@@ -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;

0 comments on commit ca34ef0

Please sign in to comment.