Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 6e681f5

Browse files
Merge pull request #241 from denisaug/master
GoogleMaps: view and viewstreet mode support
2 parents b211d2d + ea25440 commit 6e681f5

File tree

2 files changed

+74
-2
lines changed

2 files changed

+74
-2
lines changed

‎src/Http/Url.php‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,7 @@ public function getSlicePath($offset, $length = null)
313313
*/
314314
public function getPath()
315315
{
316-
$path = !empty($this->info['path']) ? '/'.implode('/', array_map('urlencode', $this->info['path'])).'/' : '/';
316+
$path = !empty($this->info['path']) ? '/'.implode('/', array_map('self::urlEncode', $this->info['path'])).'/' : '/';
317317

318318
if (isset($this->info['file'])) {
319319
$path .= self::urlEncode($this->info['file']);
@@ -663,7 +663,9 @@ function ($matches) {
663663

664664
private static function urlEncode($path)
665665
{
666-
return str_replace(['%3A'], [':'], urlencode($path));
666+
// : - used for files
667+
// @ and , - used for GoogleMaps adapter url (in view and streetview modes)
668+
return str_replace(['%3A','%40','%2C'], [':','@',','], urlencode($path));
667669
}
668670

669671
private static function validUrlOrEmpty($url)

‎src/Providers/Api/GoogleMaps.php‎

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,22 @@ public function __construct(Adapter $adapter)
2525

2626
$mode = $adapter->getResponse()->getUrl()->getDirectoryPosition(1);
2727

28+
// Default is view (if mode is not mentioned in the url)
29+
$this->mode = 'view';
30+
2831
switch ($mode) {
2932
case 'place':
3033
case 'dir':
3134
case 'search':
3235
$this->mode = $mode;
3336
break;
3437
}
38+
39+
// check streetview mode
40+
// simple check,- starts with @, ends with t
41+
if ((substr($mode, 0, 1) === '@') && (substr($mode, -1) === 't')) {
42+
$this->mode = 'streetview';
43+
}
3544
}
3645

3746
/**
@@ -50,6 +59,45 @@ public function getTitle()
5059
}
5160
}
5261

62+
/**
63+
* Returns parsed position data from url.
64+
*
65+
* @return array
66+
*/
67+
private function getPosition()
68+
{
69+
$url = $this->adapter->getResponse()->getUrl();
70+
71+
// Set defaults
72+
$position = [
73+
'coordinates' => '',
74+
'zoom' => '4',
75+
'heading' => '0',
76+
'pitch' => '0',
77+
'fov' => '90'
78+
];
79+
80+
if ($this->mode === 'view') {
81+
$pos = explode(",", $url->getDirectoryPosition(1));
82+
$position['coordinates'] = str_replace('@','',$pos[0]).','.$pos[1];
83+
$position['zoom'] = str_replace('z',"",$pos[2]);
84+
}
85+
86+
if ($this->mode === 'streetview') {
87+
$pos = explode(",", $url->getDirectoryPosition(1));
88+
$position['coordinates'] = str_replace('@','',$pos[0]).','.$pos[1];
89+
$position['zoom'] = str_replace('a','',$pos[2]); // seems not used by google (emulated by other params)
90+
$position['heading'] = str_replace('h','',$pos[4]);
91+
$position['fov'] = str_replace('y','',$pos[3]);
92+
$pitch = str_replace('t','',$pos[5]); // t is pitch but in 180% format
93+
if (is_numeric($pitch)) {
94+
$position['pitch'] = floatval($pitch) - 90;
95+
}
96+
}
97+
98+
return $position;
99+
}
100+
53101
/**
54102
* {@inheritdoc}
55103
*/
@@ -71,6 +119,28 @@ public function getCode()
71119
}
72120

73121
switch ($this->mode) {
122+
case 'view':
123+
$pos = $this->getPosition();
124+
return Utils::iframe($url
125+
->withPath('maps/embed/v1/'.$this->mode)
126+
->withQueryParameters([
127+
'center' => $pos['coordinates'],
128+
'zoom' => $pos['zoom'],
129+
'key' => $key,
130+
]));
131+
132+
case 'streetview':
133+
$pos = $this->getPosition();
134+
return Utils::iframe($url
135+
->withPath('maps/embed/v1/'.$this->mode)
136+
->withQueryParameters([
137+
'location' => $pos['coordinates'],
138+
'heading' => $pos['heading'],
139+
'pitch' => $pos['pitch'],
140+
'fov' => $pos['fov'],
141+
'key' => $key,
142+
]));
143+
74144
case 'place':
75145
case 'search':
76146
return Utils::iframe($url

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /