@@ -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