Click or drag to resize

Telogis.GeoBase.MapLayers.Balloon

Verizon Connect Logo
Print this page
Learn more about Verizon Connect GeoBase.
Get information about the latest release

MapLayers.Balloon inherits from MapLayers.AbstractObject.

A simple balloon that can be associated with a marker on a map and used to display a small amount of text or HTML content.

JavaScript
// ** This example displays a balloon on a map. The balloon text, when clicked, will trigger a function (an alert)
// Create a Telogis.GeoBase.MapLayers.BalloonSkin to apply to balloon.config.skin.
var myBalloonSkin = new Telogis.GeoBase.MapLayers.BalloonSkin({
    bodyStyle: { // specify the style of the balloon and its text
        backgroundColor: "#ffffff",
        border:          "1px solid black",
        color:           "#000000",
        fontFamily:      "sans-serif",
        fontSize:        "20px",
        fontWeight:      "normal",
        padding:         "10px",
        textAlign:       "center",
        verticalAlign:   "middle",
        width:           "150px"
    },
    folder: "http://localhost/GeoStream/scripts/images/skins/balloon/directedwhite/", // specify the default images folder
    tagAnchorPoint: new Telogis.GeoBase.Point(0.0, 1.0), // specify the bottom-left image position
    tagOverlap: -7, // adjust the vertical position of the balloon tag (move bottom-left image and tag closer/further apart)
    bottomLeftTagSrc: 'tag-bottom-left.png', // image used for bottom-left balloon tag corner (relative to 'folder')
    bottomRightTagSrc: 'tag-bottom-right.png', // image used for bottom-right balloon tag corner
    topLeftTagSrc: 'tag-top-left.png', // image used for top-left balloon tag corner
    topRightTagSrc: 'tag-top-right.png' // image used for top-right balloon tag corner
});

// Create an arbitrary function to call using balloon.config.contentFunc
var newDiv = document.createElement('Div');
newDiv.appendChild(document.createTextNode('Click Me'));
newDiv.onclick = function() {alert('You clicked me!')}; // Click the balloon to activate an alert

// Create a Balloon instance on the map ('map') with a balloon containing text
var myBalloon = new Telogis.GeoBase.MapLayers.Balloon({
    dragEnabled: true,
    //content: "<a href='http://www.telogis.com'>Telogis</a>", // Text or HTML content for the balloon.
    // --- either content or contentFunc should be used, not both
    contentFunc: function() {return newDiv}, // A function to provide balloon content as HTML
    hAlign: Telogis.GeoBase.MapLayers.Balloon.ALIGN_RIGHT, // Horizontal alignment of the balloon
    location: new Telogis.GeoBase.LatLon(33.587137,-117.742878),
    show: true, // Show on initial load
    skin: myBalloonSkin, // The skin to apply to the balloon
    vAlign: Telogis.GeoBase.MapLayers.Balloon.ALIGN_BOTTOM, // Vertical alignment of the balloon
    map: map // May also be referenced as 'parent'
});
Exceptions
TypeDescription
Errors.ConfigurationErrorIf no valid MapLayers.BalloonSkin could be found.
Constructor
NameDescription
MapLayers.Balloon(config)

Arguments

  • config (Object) - Configuration options for the MapLayers.Balloon.

    Properties
    NameTypeDescription
    behaviorNumber

    The behavior pattern that determines how the balloon responds to UI events. This may be any meaningful combination of the static behavior flags on the MapLayers.Balloon object.

    Defaults to Balloon.HOVER_ACTIVE. This property may also be referenced by the name: behaviour.
    contentString

    The HTML or text to display in the balloon.

    Defaults to ''.
    contentFunc () Function

    A function to provide the content of the balloon, which will be re-evaluated each time the balloon is shown. This should take no arguments, and return an HTML string. Either content or contentFunc should be provided, not both.

    Returns

    String - The HTML string to populate the balloon with.

    hAlignNumber

    The horizontal alignment of the balloon relative to its target element. Valid values for this are MapLayers.Balloon.ALIGN_LEFT and MapLayers.Balloon.ALIGN_RIGHT.

    Defaults to Balloon.ALIGN_RIGHT.
    locationLatLon

    The location on the map that the balloon should originate from.

    Defaults to new LatLon (0.0, 0.0).
    showBoolean

    Whether the balloon should be initially shown.

    Defaults to false.
    skinMapLayers.BalloonSkin

    A reference to the skin to use for the balloon. Several of these are pre-defined as static properties of the MapLayers.BalloonSkin object.

    Defaults to BalloonSkin.standard.
    vAlignString

    The vertical alignment of the balloon relative to its target element. Valid values for this are MapLayers.Balloon.ALIGN_TOP and MapLayers.Balloon.ALIGN_BOTTOM.

    Defaults to Balloon.ALIGN_TOP.
Functions
NameDescription
clearBehavior ()

Removes all the events registered to describe the balloon's behavior, either as a deallocation step or so that a new behavior can be set up.

JavaScript
// Create a Balloon instance on the map ('map') with a balloon containing text
var myBalloon = new Telogis.GeoBase.MapLayers.Balloon({
    content: "<a href='http://www.telogis.com'>Telogis</a>",
    location: new Telogis.GeoBase.LatLon(33.587137,-117.742878),
    show: true,
    map: map
});

// Call a test function when the canvas is clicked
document.onclick = myTestFunction;
function myTestFunction() {
    // Clear the Balloon's behavior, returning it to default state
    myBalloon.clearBehavior();
};
destroy ()

Releases all resources used by the balloon when it is no longer needed, and frees the corresponding memory to avoid leaks.

JavaScript
// Create a Balloon instance on the map ('map') with a balloon containing text
var myBalloon = new Telogis.GeoBase.MapLayers.Balloon({
    content: "<a href='http://www.telogis.com'>Telogis</a>",
    location: new Telogis.GeoBase.LatLon(33.587137,-117.742878),
    show: true,
    map: map
});

// Call a test function when the canvas is clicked
document.onclick = myTestFunction;
function myTestFunction() {
    // Destroy the Balloon object
    myBalloon.destroy();
};
hide ()

A wrapper for AbstractDOMEntity.hide that only takes action if the balloon has not had its visibility explicitly adjusted. This enables manual handling of balloon toggling in addition to a default behavior. Additionally, if the balloon is in a suspended state (i.e. part-way through another action) the hide is queued until that action completes.

JavaScript
// Create a Balloon instance on the map ('map') with a balloon containing text
var myBalloon = new Telogis.GeoBase.MapLayers.Balloon({
    content: "<a href='http://www.telogis.com'>Telogis</a>",
    location: new Telogis.GeoBase.LatLon(33.587137,-117.742878),
    show: true,
    map: map
});

// Call a test function when the canvas is clicked
document.onclick = myTestFunction;
function myTestFunction() {
    // Hide the Balloon object
    myBalloon.hide();
};
setAlignment (Number hAlign, Number vAlign)

Sets the horizontal and vertical alignments of the balloon, relative to its target element.

JavaScript
// Create a Balloon instance on the map ('map') with a balloon containing text or HTML
var myBalloon = new Telogis.GeoBase.MapLayers.Balloon({
    content: "<a href='http://www.telogis.com'>Telogis</a>",
    location: new Telogis.GeoBase.LatLon(33.587137,-117.742878),
    show: true,
    map: map
});

// Call a test function when the canvas is clicked
document.onclick = myTestFunction;
function myTestFunction() {
    // Change Balloon alignment to bottom-left of the target location
    myBalloon.setAlignment(Telogis.GeoBase.MapLayers.Balloon.ALIGN_LEFT,
        Telogis.GeoBase.MapLayers.Balloon.ALIGN_BOTTOM);
};
Arguments
  • (Optional) hAlign (Number) - A static flag of the MapLayers.Balloon object representing the horizontal alignment of the balloon. For example, MapLayers.Balloon.ALIGN_LEFT causes the balloon to be positioned to the left of its target element. Defaults to this._hAlign.

  • (Optional) vAlign (Number) - A static flag of the MapLayers.Balloon object representing the vertical alignment of the balloon. For example, MapLayers.Balloon.ALIGN_TOP causes the balloon to be positioned above its target element. Defaults to this._vAlign.

setBehavior (Number behavior, Element target)

Sets up the balloon to behave in a certain way, as described at creation or passed as a parameter.

JavaScript
// Create a Balloon instance on the map ('map') with a balloon containing HTML or text
var myBalloon = new Telogis.GeoBase.MapLayers.Balloon({
    content: "<a href='http://www.telogis.com'>Telogis</a>",
    location: new Telogis.GeoBase.LatLon(33.587137,-117.742878),
    show: true,
    map: map
});

// Set the Balloon's behavior to hide on right-click
myBalloon.setBehavior(Telogis.GeoBase.MapLayers.Balloon.BALLOON_RIGHT_CLICK_HIDE);
Arguments
  • (Optional) behavior (Number) - The behavior pattern that determines how the balloon responds to UI events. This may be any meaningful combination of the MapLayers.Balloon object's static behavior flags. Defaults to this._behavior.

  • (Optional) target (Element) - The element from which the balloon should respond to events. Defaults to this._target.

setContent (String content, Element content)

Sets or changes the HTML displayed inside the balloon. This also re-calculates the dimensions of the balloon's body accordingly.

JavaScript
// Create a Balloon instance on the map ('map') with a balloon containing text
var myBalloon = new Telogis.GeoBase.MapLayers.Balloon({
    content: 'Click me to change this text content',
    location: new Telogis.GeoBase.LatLon(33.587137,-117.742878),
    show: true,
    map: map
});

// Call a test function when the canvas is clicked
document.onclick = myTestFunction;
function myTestFunction() {
    // Change the balloon's content
    myBalloon.setContent('You just clicked the balloon'); // Text or HTML
};
Arguments
  • content (String) - The HTML to display in the balloon's body element.

  • content (Element) - The DOM element to attach to the balloon's body. If the content is not a string, it is assumed to be a DOM element.

setContentFunc (Function contentFunc)

Sets or changes the function used to recalculate the HTML to display inside the balloon.

JavaScript
// Create some test functions
var newDiv = document.createElement('Div');
newDiv.appendChild(document.createTextNode('Click Me'));
newDiv.onclick = function() {alert('You clicked me! You should click a button next.')};
var updateDiv = document.createElement('Button');
updateDiv.appendChild(document.createTextNode('Now Click This Button'));
updateDiv.onclick = function() {alert('You clicked the button on '+ Date())};

// Create a Balloon instance on the map ('map') with balloon content generated from a function
var myBalloon = new Telogis.GeoBase.MapLayers.Balloon({
    contentFunc: function() {return newDiv},
    location: new Telogis.GeoBase.LatLon(33.587137,-117.742878),
    show: true,
    map: map
});

// Call a test function when the canvas is clicked
document.onclick = myTestFunction;
function myTestFunction() {
    // Change the balloon's content function
    myBalloon.setContentFunc(function() {return updateDiv});
};
Arguments
  • (Optional) contentFunc (Function) - The function to use. This should take no arguments, and return a HTML string. Defaults to this._contentFunc.

setLayer (Widgets.Map newLayer)

Sets the layer containing the balloon in the same way as for any other map object, but ensures that its alignment is correctly updated once this operation has completed.

Arguments
setLocation (Point pos)

Repositions the element used to display the MapLayers.Balloon.

JavaScript
// Create a Balloon instance on the map ('map') with a balloon containing text
var myBalloon = new Telogis.GeoBase.MapLayers.Balloon({
    content: 'Balloon Text',
    location: new Telogis.GeoBase.LatLon(33.587137,-117.742878),
    show: true,
    map: map
});

// Call a test function when the canvas is clicked
document.onclick = myTestFunction;
function myTestFunction() {
    // Move the location of the balloon to a new LatLon coordinate
    myBalloon.setLocation(new Telogis.GeoBase.LatLon(33.573873,-117.772208));
};
Arguments
  • pos (Point or LatLon) - The location to place the balloon at. This may be specified as a pair of x-y pixel coordinates on the map, or as a latitude-longitude location.

setUserShowCallback (Function showCallback)

Sets or changes a function to be called each time the balloon is displayed.

Arguments
  • (Optional) showCallback (Function) - The function to call. This should take no arguments. Defaults to this._userShowCallback.

show ()

A wrapper for AbstractDOMEntity.show that only takes action if the balloon has not had its visibility explicitly adjusted. This enables manual handling of balloon toggling in addition to a default behavior. Additionally, if the balloon is in a suspended state (i.e. part-way through another action) the show is queued until that action completes.

toggle ()

Manually toggles the balloon. Calls MapLayers.Balloon.toggleOut if the balloon is visible, or MapLayers.Balloon.toggleIn if it is not.

toggleIn ()

Manually toggles the balloon so it is visible. While this is a wrapper to MapLayers.Balloon.show, it should always be called in its stead if visibility control is desired: a balloon shown with MapLayers.Balloon.toggleIn may only be hidden by MapLayers.Balloon.toggleOut (i.e. is unaffected by mouse events).

toggleOut ()

Manually toggles the balloon so it is invisible. While this is a wrapper to MapLayers.Balloon.hide, it should always be called in its stead (and in complement with MapLayers.Balloon.toggleIn if visibility control is desired.

update (Number updateType)

Performs any alignment adjustments necessary for the MapLayers.Balloon's behavior when the map it has been placed on is updated.

Arguments
  • updateType (Number) - The flag or combination of flags specifying the type of update that has occurred. Each of these may be any of the static Map.UPDATE_* values.

Properties
NameTypeDescription
ALIGN_BOTTOMNumber

A flag specifying that the balloon's vertical alignment should be below its target marker.

ALIGN_CENTERNumber

A flag specifying that the balloon's horizontal alignment should be centered.

ALIGN_LEFTNumber

A flag specifying that the balloon's horizontal alignment should be to the left of its target marker.

ALIGN_RIGHTNumber

A flag specifying that the balloon's horizontal alignment should be to the right of its target marker.

ALIGN_TOPNumber

A flag specifying that the balloon's vertical alignment should be above its target marker.

BALLOON_LEFT_CLICK_HIDENumber

A flag specifying that a balloon should be hidden when the balloon itself is left-clicked.

BALLOON_RIGHT_CLICK_HIDENumber

A flag specifying that a balloon should be hidden when the balloon itself is right-clicked.

DRAGGABLENumber

A flag specifying that a balloon should be able to be re-positioned by dragging it within a certain constrained area.

EVENT_UNSUSPENDNumber

A flag to enable handling of the event triggered when the MapLayers.Balloon is unsuspended.

HOVER_ACTIVENumber

A flag specifying that a balloon should be shown when the mouse moves over its element, and hidden again once the mouse leaves both its element and the balloon itself.

LEFT_CLICK_TOGGLENumber

A combination of MapLayers.Balloon.BALLOON_LEFT_CLICK_HIDE and MapLayers.Balloon.TARGET_LEFT_CLICK_TOGGLE.

MANUAL_TOGGLENumber

A flag specifying no automated toggling behavior for a balloon.

REALIGN_TO_VIEWPORTNumber

A flag specifying that a balloon should have its alignment automatically changed to keep it in the map viewport for as long as possible (when it may otherwise be moved off the edge by a pan). This behavior is overridden by MapLayers.Balloon.DRAGGABLE.

RIGHT_CLICK_TOGGLENumber

A combination of MapLayers.Balloon.BALLOON_RIGHT_CLICK_HIDE and MapLayers.Balloon.TARGET_RIGHT_CLICK_TOGGLE.

TAG_ALIGN_AUTONumber

A flag specifying that the balloon's tag should be aligned either horizontally or vertically depending on which fits best.

TAG_ALIGN_HORIZONTALNumber

A flag specifying that the balloon's tag should be aligned horizontally, i.e., either above or below the balloon. This is the default.

TAG_ALIGN_VERTICALNumber

A flag specifying that the balloon's tag should be aligned vertically, i.e., either to the left or to the right of the balloon.

TARGET_LEFT_CLICK_TOGGLENumber

A flag specifying that a balloon should be toggled when its target element is left-clicked.

TARGET_RIGHT_CLICK_TOGGLENumber

A flag specifying that a balloon should be toggled when its target element is right-clicked.

UnsuspendEventHandler

An event handler used to queue callbacks (such as calls to MapLayers.Balloon.hide) that cannot be executed while another action is being performed (i.e. the balloon is suspended). Such suspending actions include dragging the balloon, since the balloon should not be hidden during the drag's duration. This handler is triggered once the suspending action completes.