MapsAlive Object¶
The MapsAlive object provides access to the API object and the Event object. You can also get the API object using the api
property of the Event object. However, your JavaScript will only have access to the Event object from within an API callback function (an Event object is passed to the callback function).
You need to use the MapsAlive object when:
-
MapsAlive calls one of your marker action functions or one of your Live Data request functions. MapsAlive does not pass an Event object to these functions, but you can get the Event object by calling the MapsAlive object's
getEvent
method from your function. Once you have the Event object, you can get the API object from the Event object'sapi
property. -
One of your other JavaScript functions is called as a result of an event handler that you coded for a non-MapsAlive event. An example would be an
onmouseover
,onmouseoff
, oronclick
event that you coded somewhere so that your JavaScript could respond to a user action. Your function can get the API object by calling thegetApi
method of the MapsAlive object. If necessary, you can pass the instance identifier of the event's tour to your event handler using the TOUR_INSTANCE macro.
Examples of the scenarios described above are shown below.
// Callback functions can get the API object from the passed-in Event object.
function onEventTourLoaded(event) {
let api = event.api;
...
}
// Marker action or Live Data request functions can get the Event object by calling getEvent.
function markerActionHandler() {
let event = MapsAlive.getEvent();
let api = event.api;
...
}
<button onclick="someOtherHandler('TOUR_INSTANCE')">Click Me</button>
// Other functions can get the API by calling MapsAlive.getApi().
function someOtherHandler(instance) {
let apiForThisTour = MapsAlive.getApi();
let apiForAnotherTour = MapsAlive.getApi(12345);
let apiForSpecificInstance = MapsAlive.getApi(instance);
...
}
The MapsAlive object's methods are listed below in alphabetical order.
getApi¶
The getApi
method returns the API object for a tour. Which tour depends on what parameter is passed to the method.
Signature¶
MapsAlive.getApi()
MapsAlive.getApi(tourNumber)
MapsAlive.getApi(instanceIdentifier)
Example¶
let apiForThisTour = MapsAlive.getApi();
let apiForAnotherTour = MapsAlive.getApi(12345);
let apiForSpecificInstance = MapsAlive.getApi(instance);
When no parameter is passed:
- If the method is called from the JavaScript field of a tour's Custom HTML, MapsAlive automatically inserts the tour number of the tour that is making the call. It does this by looking for the empty parentheses so don't code spaces between the opening and closing parenthesis.
- Otherwise, the first instance of the first tour on the page is returned and a warning is displayed in the developer console.
Parameters¶
- tourNumber
- An integer specifying the number of a tour in the containing web page. If there is no such tour, the method returns null. If the containing web page contains more than one instance of the tour identified by the
tourNumber
parameter, the method will return the API object for the first instance of the tour and report a warning in the developer console. - instanceIdentifier
- A string specifying the instance identifier for a tour. If the string is empty, the method will return the first tour on the containing web page that has no instance identifier. If the string is not empty and no tour has the specified identifier, the method returns null. The comparison of
instanceIdentifier
to tour instance identifiers is case-insensitive.
getEvent¶
The getEvent
property returns an Event object that contains information about the context of the caller of a JavaScript function that you wrote to handle one of the following:
- Marker action (click, mouseover, or mouseout)
- Live Data request function call
Your function can use the returned Event object to get access to the API object. This method return nulls if called from a function that is not a marker action handler or Live Data request function.
Signature¶
MapsAlive.getEvent
Example¶
let event = MapsAlive.getEvent();
event.api.setMarkerSelected(event.hotspot.id);