Version 4.5.0
This commit is contained in:
1 parent
1a0c7fd3c2
commit
f79dcf067a
3791 files changed
+248032
-76372
No files matched your search
@@ -11,7 +11,7 @@
|
||||
namespace IPS\GeoLocation\Maps;
|
||||
|
||||
/* To prevent PHP errors (extending class does not exist) revealing path */
|
||||
if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
{
|
||||
header( ( isset( $_SERVER['SERVER_PROTOCOL'] ) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0' ) . ' 403 Forbidden' );
|
||||
exit;
|
||||
@@ -49,6 +49,41 @@ class _Google
|
||||
* @return string
|
||||
*/
|
||||
public function render( $width, $height, $zoom=NULL, $scale=1, $maptype='roadmap' )
|
||||
{
|
||||
return \IPS\Theme::i()->getTemplate( 'global', 'core', 'global' )->staticMap( \IPS\Http\Url::external( 'https://maps.google.com/' )->setQueryString( 'q', $this->_getLocation() ), $this->mapUrl( $width, $height, $zoom, $scale, $maptype ), $this->geolocation->lat, $this->geolocation->long, $width, $height );
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the map image URL
|
||||
*
|
||||
* @param int $width Width
|
||||
* @param int $height Height
|
||||
* @param float|NULL $zoom The zoom amount (a value between 0 being totally zoomed out view of the world, and 1 being as fully zoomed in as possible) or NULL to zoom automatically based on how much data is available
|
||||
* @param int $scale Google maps scale to use (https://developers.google.com/maps/documentation/static-maps/intro#scale_values)
|
||||
* @param string $maptype Type of map to use. Valid values are roadmap (default), satellite, terrain, and hybrid (https://developers.google.com/maps/documentation/static-maps/intro#MapTypes)
|
||||
* @return \IPS\Http\Url|NULL
|
||||
*/
|
||||
public function mapUrl( $width, $height, $zoom=NULL, $scale=1, $maptype='roadmap' )
|
||||
{
|
||||
$location = $this->_getLocation();
|
||||
|
||||
return \IPS\Http\Url::external( 'https://maps.googleapis.com/maps/api/staticmap' )->setQueryString( array(
|
||||
'center' => $location,
|
||||
'zoom' => $zoom === NULL ? NULL : ceil( $zoom * 8 ),
|
||||
'size' => "{$width}x{$height}",
|
||||
'markers' => $location,
|
||||
'key' => \IPS\Settings::i()->google_maps_api_key,
|
||||
'scale' => $scale,
|
||||
'maptype' => $maptype
|
||||
) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetch the location
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function _getLocation()
|
||||
{
|
||||
if ( $this->geolocation->lat and $this->geolocation->long )
|
||||
{
|
||||
@@ -61,7 +96,7 @@ class _Google
|
||||
{
|
||||
if ( $this->geolocation->$k )
|
||||
{
|
||||
if ( is_array( $this->geolocation->$k ) )
|
||||
if ( \is_array( $this->geolocation->$k ) )
|
||||
{
|
||||
foreach ( array_reverse( $this->geolocation->$k ) as $v )
|
||||
{
|
||||
@@ -80,18 +115,6 @@ class _Google
|
||||
$location = implode( ', ', array_reverse( $location ) );
|
||||
}
|
||||
|
||||
$linkUrl = \IPS\Http\Url::external( 'https://maps.google.com/' )->setQueryString( 'q', $location );
|
||||
|
||||
$imageUrl = \IPS\Http\Url::external( 'https://maps.googleapis.com/maps/api/staticmap' )->setQueryString( array(
|
||||
'center' => $location,
|
||||
'zoom' => $zoom === NULL ? NULL : ceil( $zoom * 8 ),
|
||||
'size' => "{$width}x{$height}",
|
||||
'markers' => $location,
|
||||
'key' => \IPS\Settings::i()->google_maps_api_key,
|
||||
'scale' => $scale,
|
||||
'maptype' => $maptype
|
||||
) );
|
||||
|
||||
return \IPS\Theme::i()->getTemplate( 'global', 'core', 'global' )->staticMap( $linkUrl, $imageUrl, $this->geolocation->lat, $this->geolocation->long );
|
||||
return $location;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user