Permalink
Browse files

Merge branch 'develop'

  • Loading branch information...
2 parents 328a9be + 478092a commit 226cb1cf39d18e2d236b30d10926ba2b54fcb8f8 Bradley Cornford committed Jan 3, 2017
View
@@ -56,6 +56,7 @@ You can now configure Googlmapper in a few simple steps. Open `app/config/packag
- `key` - A Google Maps API key.
- `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.
+- `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.
- `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.
@@ -79,6 +79,27 @@ public function setLanguage($value);
*/
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.
*
@@ -256,6 +277,24 @@ public function setType($type);
*/
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.
*
@@ -268,7 +307,7 @@ public function getType();
public function setTilt($value);
/**
- * Get map $tilt.
+ * Get map tilt.
*
* @return integer
*/
@@ -18,6 +18,8 @@
const TYPE_HYBRID = 'HYBRID';
const TYPE_TERRAIN = 'TERRAIN';
+ const ASYNC = false;
+
const USER = false;
const MARKER = true;
@@ -31,7 +33,9 @@
const FULLSCREEN_CONTROL = true;
- const TILT = 90;
+ const HEADING = 0;
+
+ const TILT = 0;
const UI = true;
@@ -492,6 +496,13 @@
];
/**
+ * Async maps.
+ *
+ * @var boolean
+ */
+ protected $async;
+
+ /**
* User custom maps.
*
* @var boolean
@@ -566,6 +577,13 @@
'TERRAIN'
];
+ /**
+ * Map heading.
+ *
+ * @var integer
+ */
+ protected $heading;
+
/**
* Map tilt.
*
@@ -684,13 +702,15 @@ public function __construct(View $view, array $options = [])
$this->setRegion(isset($options['region']) ? $options['region'] : self::REGION);
$this->setLanguage(isset($options['language']) ? $options['language'] : self::LANGUAGE);
$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->setCenter(isset($options['center']) ? $options['center'] : self::CENTER);
$this->setLocate(isset($options['locate']) ? $options['locate'] : self::LOCATE);
$this->setZoom(isset($options['zoom']) ? $options['zoom'] : self::ZOOM);
$this->setScrollWheelZoom(isset($options['scrollWheelZoom']) ? $options['scrollWheelZoom'] : self::SCROLL_WHEEL_ZOOM);
$this->setFullscreenControl(isset($options['fullscreenControl']) ? $options['fullscreenControl'] : self::FULLSCREEN_CONTROL);
$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->setUi(isset($options['ui']) ? $options['ui'] : self::UI);
$this->setIcon(isset($options['markers']['icon']) ? $options['markers']['icon'] : self::ICON);
@@ -853,6 +873,54 @@ public function getLanguage()
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.
*
@@ -1210,6 +1278,34 @@ public function getType()
}
/**
+ * 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.
*
* @param integer|double $value
@@ -1228,7 +1324,7 @@ public function setTilt($value)
}
/**
- * Get map $tilt.
+ * Get map tilt.
*
* @return integer
*/
@@ -1493,6 +1589,7 @@ protected function getOptions()
'version' => $this->version,
'region' => $this->getRegion(),
'language' => $this->getLanguage(),
+ 'async' => $this->getAsync(),
'user' => $this->getUser(),
'marker' => $this->getMarker(),
'center' => $this->getCenter(),
@@ -1501,6 +1598,7 @@ protected function getOptions()
'scrollWheelZoom' => $this->getScrollWheelZoom(),
'fullscreenControl' => $this->getFullscreenControl(),
'type' => $this->getType(),
+ 'heading' => $this->getHeading(),
'tilt' => $this->getTilt(),
'ui' => $this->getUi(),
'overlay' => '',
View
@@ -44,6 +44,16 @@
/*
|--------------------------------------------------------------------------
+ | Asynchronous
+ |--------------------------------------------------------------------------
+ |
+ | Perform the loading and rendering of Googlmapper map asynchronously.
+ |
+ */
+ 'async' => false,
+
+ /*
+ |--------------------------------------------------------------------------
| User Custom Maps
|--------------------------------------------------------------------------
|
@@ -2,12 +2,36 @@
@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'])
<script type="text/javascript" src="//googlemaps.github.io/js-marker-clusterer/src/markerclusterer.js"></script>
@endif
+ @if ($options['async'])
+
+ <script type="text/javascript">
+
+ var initialize_items = [];
+
+ function initialize_method() {
+ initialize_items.forEach(function(item) {
+ item.method();
+ });
+ }
+
+ </script>
+
+ @endif
+
@endif
@@ -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>
@@ -4,5 +4,16 @@
{!! $item->render($id, $view) !!}
-@endforeach
+ @if ($options['async'])
+
+ <script type="text/javascript">
+
+ initialize_items.push({
+ method: initialize_{!! $id !!}
+ });
+ </script>
+
+ @endif
+
+@endforeach
@@ -30,6 +30,10 @@ function initialize_{!! $id !!}() {
map.setStreetView(panorama);
}
- google.maps.event.addDomListener(window, 'load', initialize_{!! $id !!});
+ @if (!$options['async'])
+
+ google.maps.event.addDomListener(window, 'load', initialize_{!! $id !!});
+
+ @endif
</script>

0 comments on commit 226cb1c

Please sign in to comment.