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 328a9be + 478092a commit 226cb1c
Show file tree
Hide file tree
Showing 8 changed files with 198 additions and 7 deletions.
1 change: 1 addition & 0 deletions README.md
Expand Up @@ -56,6 +56,7 @@ You can now configure Googlmapper in a few simple steps. Open `app/config/packag
- `key` - A Google Maps API key. - `key` - A Google Maps API key.
- `region` - A region Google Maps should utilise, required in ISO 3166-1 code format, e.g. GB. - `region` - A region Google Maps should utilise, required in ISO 3166-1 code format, e.g. GB.
- `language` - A language Google Maps should utilise, required in ISO 639-1 code format, e.g. en-gb. - `language` - A language Google Maps should utilise, required in ISO 639-1 code format, e.g. en-gb.
- `async` - Perform the loading and rendering of Googlmapper map asynchronously, e.g. false.
- `user` - Use custom Google Maps for users logged into the Google service, e.g. false. - `user` - Use custom Google Maps for users logged into the Google service, e.g. false.
- `marker` - Automatically add Google Maps marker for your maps initial location, e.g. true. - `marker` - Automatically add Google Maps marker for your maps initial location, e.g. true.
- `center` - Automatically center Google Maps around the initial location, when false, Google Maps will automatically center the map, e.g. true. - `center` - Automatically center Google Maps around the initial location, when false, Google Maps will automatically center the map, e.g. true.
Expand Down
41 changes: 40 additions & 1 deletion src/Cornford/Googlmapper/Contracts/MappingBaseInterface.php
Expand Up @@ -79,6 +79,27 @@ public function setLanguage($value);
*/ */
public function getLanguage(); public function getLanguage();


/**
* Get the map async status.
*
* @return boolean
*/
public function getAsync();

/**
* Enable async for maps.
*
* @return void
*/
public function enableAsync();

/**
* Disable async for maps.
*
* @return void
*/
public function disableAsync();

/** /**
* Get the map user status. * Get the map user status.
* *
Expand Down Expand Up @@ -256,6 +277,24 @@ public function setType($type);
*/ */
public function getType(); public function getType();


/**
* Set map heading.
*
* @param integer|double $value
*
* @throws MapperArgumentException
*
* @return void
*/
public function setHeading($value);

/**
* Get map heading.
*
* @return integer
*/
public function getHeading();

/** /**
* Set map tilt. * Set map tilt.
* *
Expand All @@ -268,7 +307,7 @@ public function getType();
public function setTilt($value); public function setTilt($value);


/** /**
* Get map $tilt. * Get map tilt.
* *
* @return integer * @return integer
*/ */
Expand Down
102 changes: 100 additions & 2 deletions src/Cornford/Googlmapper/MapperBase.php
Expand Up @@ -18,6 +18,8 @@ abstract class MapperBase implements MappingBaseInterface
const TYPE_HYBRID = 'HYBRID'; const TYPE_HYBRID = 'HYBRID';
const TYPE_TERRAIN = 'TERRAIN'; const TYPE_TERRAIN = 'TERRAIN';


const ASYNC = false;

const USER = false; const USER = false;


const MARKER = true; const MARKER = true;
Expand All @@ -31,7 +33,9 @@ abstract class MapperBase implements MappingBaseInterface


const FULLSCREEN_CONTROL = true; const FULLSCREEN_CONTROL = true;


const TILT = 90; const HEADING = 0;

const TILT = 0;


const UI = true; const UI = true;


Expand Down Expand Up @@ -491,6 +495,13 @@ abstract class MapperBase implements MappingBaseInterface
'zu' 'zu'
]; ];


/**
* Async maps.
*
* @var boolean
*/
protected $async;

/** /**
* User custom maps. * User custom maps.
* *
Expand Down Expand Up @@ -566,6 +577,13 @@ abstract class MapperBase implements MappingBaseInterface
'TERRAIN' 'TERRAIN'
]; ];


/**
* Map heading.
*
* @var integer
*/
protected $heading;

/** /**
* Map tilt. * Map tilt.
* *
Expand Down Expand Up @@ -684,13 +702,15 @@ public function __construct(View $view, array $options = [])
$this->setRegion(isset($options['region']) ? $options['region'] : self::REGION); $this->setRegion(isset($options['region']) ? $options['region'] : self::REGION);
$this->setLanguage(isset($options['language']) ? $options['language'] : self::LANGUAGE); $this->setLanguage(isset($options['language']) ? $options['language'] : self::LANGUAGE);
$this->setUser(isset($options['user']) ? $options['user'] : self::USER); $this->setUser(isset($options['user']) ? $options['user'] : self::USER);
$this->setAsync(isset($options['async']) ? $options['async'] : self::ASYNC);
$this->setMarker(isset($options['marker']) ? $options['marker'] : self::MARKER); $this->setMarker(isset($options['marker']) ? $options['marker'] : self::MARKER);
$this->setCenter(isset($options['center']) ? $options['center'] : self::CENTER); $this->setCenter(isset($options['center']) ? $options['center'] : self::CENTER);
$this->setLocate(isset($options['locate']) ? $options['locate'] : self::LOCATE); $this->setLocate(isset($options['locate']) ? $options['locate'] : self::LOCATE);
$this->setZoom(isset($options['zoom']) ? $options['zoom'] : self::ZOOM); $this->setZoom(isset($options['zoom']) ? $options['zoom'] : self::ZOOM);
$this->setScrollWheelZoom(isset($options['scrollWheelZoom']) ? $options['scrollWheelZoom'] : self::SCROLL_WHEEL_ZOOM); $this->setScrollWheelZoom(isset($options['scrollWheelZoom']) ? $options['scrollWheelZoom'] : self::SCROLL_WHEEL_ZOOM);
$this->setFullscreenControl(isset($options['fullscreenControl']) ? $options['fullscreenControl'] : self::FULLSCREEN_CONTROL); $this->setFullscreenControl(isset($options['fullscreenControl']) ? $options['fullscreenControl'] : self::FULLSCREEN_CONTROL);
$this->setType(isset($options['type']) ? $options['type'] : self::TYPE_ROADMAP); $this->setType(isset($options['type']) ? $options['type'] : self::TYPE_ROADMAP);
$this->setHeading(isset($options['heading']) ? $options['heading'] : self::HEADING);
$this->setTilt(isset($options['tilt']) ? $options['tilt'] : self::TILT); $this->setTilt(isset($options['tilt']) ? $options['tilt'] : self::TILT);
$this->setUi(isset($options['ui']) ? $options['ui'] : self::UI); $this->setUi(isset($options['ui']) ? $options['ui'] : self::UI);
$this->setIcon(isset($options['markers']['icon']) ? $options['markers']['icon'] : self::ICON); $this->setIcon(isset($options['markers']['icon']) ? $options['markers']['icon'] : self::ICON);
Expand Down Expand Up @@ -853,6 +873,54 @@ public function getLanguage()
return $this->language; return $this->language;
} }


/**
* Set the map async status.
*
* @param boolean $value
*
* @throws MapperArgumentException
*
* @return void
*/
protected function setAsync($value)
{
if (!is_bool($value)) {
throw new MapperArgumentException('Invalid map async status.');
}

$this->async = $value;
}

/**
* Get the map async status.
*
* @return boolean
*/
public function getAsync()
{
return $this->async;
}

/**
* Enable async for maps.
*
* @return void
*/
public function enableAsync()
{
$this->setAsync(true);
}

/**
* Disable async for maps.
*
* @return void
*/
public function disableAsync()
{
$this->setAsync(false);
}

/** /**
* Set the map user status. * Set the map user status.
* *
Expand Down Expand Up @@ -1209,6 +1277,34 @@ public function getType()
return $this->type; return $this->type;
} }


/**
* Set map heading.
*
* @param integer|double $value
*
* @throws MapperArgumentException
*
* @return void
*/
public function setHeading($value)
{
if (!is_numeric($value)) {
throw new MapperArgumentException('Invalid map heading.');
}

$this->heading = $value;
}

/**
* Get map heading.
*
* @return integer
*/
public function getHeading()
{
return $this->heading;
}

/** /**
* Set map tilt. * Set map tilt.
* *
Expand All @@ -1228,7 +1324,7 @@ public function setTilt($value)
} }


/** /**
* Get map $tilt. * Get map tilt.
* *
* @return integer * @return integer
*/ */
Expand Down Expand Up @@ -1493,6 +1589,7 @@ protected function getOptions()
'version' => $this->version, 'version' => $this->version,
'region' => $this->getRegion(), 'region' => $this->getRegion(),
'language' => $this->getLanguage(), 'language' => $this->getLanguage(),
'async' => $this->getAsync(),
'user' => $this->getUser(), 'user' => $this->getUser(),
'marker' => $this->getMarker(), 'marker' => $this->getMarker(),
'center' => $this->getCenter(), 'center' => $this->getCenter(),
Expand All @@ -1501,6 +1598,7 @@ protected function getOptions()
'scrollWheelZoom' => $this->getScrollWheelZoom(), 'scrollWheelZoom' => $this->getScrollWheelZoom(),
'fullscreenControl' => $this->getFullscreenControl(), 'fullscreenControl' => $this->getFullscreenControl(),
'type' => $this->getType(), 'type' => $this->getType(),
'heading' => $this->getHeading(),
'tilt' => $this->getTilt(), 'tilt' => $this->getTilt(),
'ui' => $this->getUi(), 'ui' => $this->getUi(),
'overlay' => '', 'overlay' => '',
Expand Down
10 changes: 10 additions & 0 deletions src/config/config.php
Expand Up @@ -42,6 +42,16 @@
*/ */
'language' => 'en-gb', 'language' => 'en-gb',


/*
|--------------------------------------------------------------------------
| Asynchronous
|--------------------------------------------------------------------------
|
| Perform the loading and rendering of Googlmapper map asynchronously.
|
*/
'async' => false,

/* /*
|-------------------------------------------------------------------------- |--------------------------------------------------------------------------
| User Custom Maps | User Custom Maps
Expand Down
26 changes: 25 additions & 1 deletion src/views/javascript.blade.php
Expand Up @@ -2,12 +2,36 @@


@if ($view->share('javascript', true)) @endif @if ($view->share('javascript', true)) @endif


<script type="text/javascript" src="//maps.googleapis.com/maps/api/js?v={!! $options['version'] !!}&region={!! $options['region'] !!}&language={!! $options['language'] !!}&key={!! $options['key'] !!}&signed_in={!! $options['user'] ? 'true' : 'false' !!}&libraries=places"></script> @if ($options['async'])

<script async defer type="text/javascript" src="//maps.googleapis.com/maps/api/js?v={!! $options['version'] !!}&region={!! $options['region'] !!}&language={!! $options['language'] !!}&key={!! $options['key'] !!}&signed_in={!! $options['user'] ? 'true' : 'false' !!}&libraries=places&callback=initialize_method"></script>

@else

<script type="text/javascript" src="//maps.googleapis.com/maps/api/js?v={!! $options['version'] !!}&region={!! $options['region'] !!}&language={!! $options['language'] !!}&key={!! $options['key'] !!}&signed_in={!! $options['user'] ? 'true' : 'false' !!}&libraries=places"></script>

@endif


@if ($options['cluster']) @if ($options['cluster'])


<script type="text/javascript" src="//googlemaps.github.io/js-marker-clusterer/src/markerclusterer.js"></script> <script type="text/javascript" src="//googlemaps.github.io/js-marker-clusterer/src/markerclusterer.js"></script>


@endif @endif


@if ($options['async'])

<script type="text/javascript">
var initialize_items = [];
function initialize_method() {
initialize_items.forEach(function(item) {
item.method();
});
}
</script>

@endif

@endif @endif
6 changes: 5 additions & 1 deletion src/views/map.blade.php
Expand Up @@ -95,6 +95,10 @@ function initialize_{!! $id !!}() {
}); });
} }
google.maps.event.addDomListener(window, 'load', initialize_{!! $id !!}); @if (!$options['async'])
google.maps.event.addDomListener(window, 'load', initialize_{!! $id !!});
@endif
</script> </script>
13 changes: 12 additions & 1 deletion src/views/mapper.blade.php
Expand Up @@ -4,5 +4,16 @@


{!! $item->render($id, $view) !!} {!! $item->render($id, $view) !!}


@endforeach @if ($options['async'])

<script type="text/javascript">
initialize_items.push({
method: initialize_{!! $id !!}
});
</script>

@endif

@endforeach
6 changes: 5 additions & 1 deletion src/views/streetview.blade.php
Expand Up @@ -30,6 +30,10 @@ function initialize_{!! $id !!}() {
map.setStreetView(panorama); map.setStreetView(panorama);
} }
google.maps.event.addDomListener(window, 'load', initialize_{!! $id !!}); @if (!$options['async'])
google.maps.event.addDomListener(window, 'load', initialize_{!! $id !!});
@endif
</script> </script>

0 comments on commit 226cb1c

Please sign in to comment.