You are not logged in.

Dear visitor, welcome to krpano.com Forum. If this is your first visit here, please read the Help. It explains in detail how this page works. To use all features of this page, you should consider registering. Please use the registration form, to register here or read more information about the registration process. If you are already registered, please login here.

1

Thursday, October 26th 2017, 12:51pm

Maps plugin: how to use gmAPI?

Hi to everyone!

I'd like to use the gmAPI object which is mentioned in this page of the documentation. This part of the documentation being rather obscure (unlike the rest of the documentation I should say), could anyone tell me how to use this gmAPI object? How to access it? Where is it?

Greetings,

Seb

This post has been edited 1 times, last edit by "seb-visitit" (Oct 26th 2017, 1:09pm)


2

Thursday, October 26th 2017, 1:43pm

Hi,

here an example:

Call in the 'onmapready' event a custom action:

Source code

1
2
3
4
<plugin name="map"
    ...
    onmapready="gmapi_test();"
    />


and in in that custom (Javascript) Action access the gmAPI object via the 'caller' object (that is the plugin[map] object):

Source code

1
2
3
4
5
6
7
<action name="gmapi_test" type="Javascript"><![CDATA[
    var gmAPI = caller.gmAPI;
    if (gmAPI) // check if having the gmAPI
    {
        gmAPI.map.setOptions(...);
    }
]]></action>


Best regards,
Klaus

3

Thursday, October 26th 2017, 2:13pm

Thanks Klaus for the quick answer!

How would I do (if doable) with external JS? I mean:

In my vtourskin.xml:

Source code

1
2
3
4
5
<layer name="skin_map_container" type="container" align="leftop" width="100%" height="100%" bgroundedge="get:skin_settings.design_bgroundedge" maskchildren="true">
  <layer name="skin_map" state="closed" url="" visible="false" align="lefttop" width="100%" height="50%" x="0" y="0" zorder="1" lat="0" lng="0" zoom="10" bgalpha="0" maptype="hybrid" onmapready="skin_addmapspots(); js(map());">
  							[...]
      						</layer>
					</layer>


Im my custom JS file:

Source code

1
2
3
function googleMap() {
  // How to get gmAPI from here?
}

4

Thursday, October 26th 2017, 2:18pm

e.g.

Source code

1
2
3
4
5
function googleMap() {
  var krpano = document.getElementById("krpanoSWFObject");
  var mapsplugin = krpano.get("plugin[map]");
  mapsplugin.gmAPI.setOptions(...);
}

5

Thursday, October 26th 2017, 2:22pm

Thanks again. Excuse my newbiness, but "plugin[map]" is null in my case. I edited the vtourskin.xml excerpt in my previous post to be more explicit.
I can get layer[skin_map], but it has no gmAPI attribute :-/

6

Thursday, October 26th 2017, 2:28pm

Hi,

the name 'plugin[map]' depends of course on the name that was used in the xml to load the maps plugin.

And right for the vtourskin.xml this would be the 'layer[skin_map]'.

When layer[skin_map].gmAPI is undefined there could be normally only these reasons:
- you're trying to get gmAPI before the onmapsready event has been called/processed,
- or the googlemaps.js is too old (it would need to be 1.19-pr9 or higher),
- or you're using bing instead of google maps,
- or you're using flash instead of html5.

Try to check if one of these is true.

Best regards,
Klaus

7

Thursday, October 26th 2017, 2:34pm

Thanks again Klaus, you nailed it! I was using an up-to-date krpanotools binary, but an out-of-date googlemaps.js. It's working now :-).