Debugging using JavaScript | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
FusionMaps XT uses FusionCharts JavaScript Class that takes care of all the products of FusionCharts Suite XT including FusionMaps XT. FusionCharts JavaScript class provides a developer-friendly mechanism to debug maps. You can debug your maps in three ways:
Using the FusionCharts JavaScript Debug Mode FusionCharts JavaScript Class has its own debugMode. This allows users to watch the map's JavaScript activities and debug maps accordingly. To enable the JavaScript Debug Mode, you need to write the following lines of code: FusionCharts.debugMode.enabled(true); Next, you need to specify where you will like to display the debugMode output. In case you want to see the error within the browser’s JavaScript console, you need to write the following lines of code. FusionCharts.debugMode.outputTo( function() { console.log(arguments); } ); Note that, depending upon your browser, you may need to specifically enable “JavaScript Console”. In case, you want detailed information regarding each event, you may use a more advanced JavaScript debugger such as FireBug (available for FireFox) or FireBug-Lite (can be used on most browsers). If you are using an advanced JavaScript console (like Firebug) that can display object hierarchy, you may want to change the debugMode output format.To set the output format to ‘verbose’, use the following line of code: FusionCharts.debugMode.outputFormat('verbose'); All the above lines can be written in one compact line of code: FusionCharts.debugMode.enabled( function() { console.log(arguments); }, 'verbose'); The supported debugMode output formats are: text (default), verbose and event. When the outputFormat is set to event, the output function assigned to the debugger (using debugMode.outputTo method) is sent arguments exactly matching FusionCharts Advanced events model: eventObject, argumentsObject. FusionCharts also provides an interesting function to remotely auto-include Firebug-Lite within your browser. This helps in case you are running a browser with reduced features of ‘console’.
To use this feature, write the following lines of code: FusionCharts.debugMode._enableFirebugLite();
This method takes time for the console to load (also needs internet connectivity) as the Firebug script is remotely loaded. FusionCharts.debugMode._enableFirebugLite('firebug-lite.js'); |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Error Code and Description | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
FusionCharts JavaScript Class displays or logs errors messages when an error occurs while rendering a map. The error message contains an error code. The table below contains the list of Error codes and the description of each error.
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Using simple error events | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
There are three error events which can be listened to using simple event listening. They are described as follows:
To know more on how to listen to simple events like the ones listed above read FusionCharts and JavaScript > Listening to events page. The image and the code below shows how InvalidXMLText error is listened to and shown an alert message when the event is fired. <html> <head> <title>Listening to simple error event NoDataToDisplay</title> <script type="text/javascript" src="../../Maps/FusionCharts.js" ></script> </head> <body> <div id="mapContainer">FusionMaps XT will load here </div> <script type="text/javascript"><!-- var myMap = new FusionCharts("../../Maps/FCMap_World.swf", "myMapId", "400", "200", "0"); myMap.setXMLData("<map>"); myMap.render("mapContainer"); function FC_DataXMLInvalid(DOMId) { alert("Invalid data is passed to the map having id - " + DOMId); } // --> </script> </body> </html> In the above code, we have created a map and set an empty XML with just the root element <map/>. This makes the XML devoid of any map data. Hence, the error event FC_NoDataToDisplay is being fired. We listen to that event declaring a function of the same name. The function gets automatically called by the map in this case. We show an alert message when the function is called. |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Using advanced Error and Warning Events | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
FusionCharts JavaScript Class provides two error events.
You can listen to the above events globally or on a per-map basis. To listen to an error event globally, use the following line of code: FusionCharts.addEventListener('Error', function (eventObject, argumentsObject) { alert('There was an error with maps!\n' + argumentsObject.message); }); You can also use the legacy simple event method: function FC_Error(eventObject, argumentsObject) { alert('There was an error with maps! \n' + argumentsObject.message); } The arguments of the event are:
To know more on events and listening to the events read FusionMaps XT and JavaScript > Listening to Events page. |