Telogis.GeoBase.MapLayers.Balloon |
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.
// ** 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' });
Type | Description |
---|---|
Errors.ConfigurationError | If no valid MapLayers.BalloonSkin could be found. |
Name | Description | |||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
MapLayers.Balloon(config) | Arguments
|
Name | Description |
---|---|
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); };
|
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);
|
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 };
|
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}); };
|
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)); }; |
setUserShowCallback (Function showCallback) | Sets or changes a function to be called each time the balloon is displayed. Arguments
|
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
|
Name | Type | Description |
---|---|---|
ALIGN_BOTTOM | Number | A flag specifying that the balloon's vertical alignment should be below its target marker. |
ALIGN_CENTER | Number | A flag specifying that the balloon's horizontal alignment should be centered. |
ALIGN_LEFT | Number | A flag specifying that the balloon's horizontal alignment should be to the left of its target marker. |
ALIGN_RIGHT | Number | A flag specifying that the balloon's horizontal alignment should be to the right of its target marker. |
ALIGN_TOP | Number | A flag specifying that the balloon's vertical alignment should be above its target marker. |
BALLOON_LEFT_CLICK_HIDE | Number | A flag specifying that a balloon should be hidden when the balloon itself is left-clicked. |
BALLOON_RIGHT_CLICK_HIDE | Number | A flag specifying that a balloon should be hidden when the balloon itself is right-clicked. |
DRAGGABLE | Number | A flag specifying that a balloon should be able to be re-positioned by dragging it within a certain constrained area. |
EVENT_UNSUSPEND | Number | A flag to enable handling of the event triggered when the MapLayers.Balloon is unsuspended. |
HOVER_ACTIVE | Number | 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_TOGGLE | Number | A combination of MapLayers.Balloon.BALLOON_LEFT_CLICK_HIDE and MapLayers.Balloon.TARGET_LEFT_CLICK_TOGGLE. |
MANUAL_TOGGLE | Number | A flag specifying no automated toggling behavior for a balloon. |
REALIGN_TO_VIEWPORT | Number | 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_TOGGLE | Number | A combination of MapLayers.Balloon.BALLOON_RIGHT_CLICK_HIDE and MapLayers.Balloon.TARGET_RIGHT_CLICK_TOGGLE. |
TAG_ALIGN_AUTO | Number | A flag specifying that the balloon's tag should be aligned either horizontally or vertically depending on which fits best. |
TAG_ALIGN_HORIZONTAL | Number | 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_VERTICAL | Number | 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_TOGGLE | Number | A flag specifying that a balloon should be toggled when its target element is left-clicked. |
TARGET_RIGHT_CLICK_TOGGLE | Number | A flag specifying that a balloon should be toggled when its target element is right-clicked. |
Unsuspend | EventHandler | 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. |