When using FusionMaps Export component, you can configure the component to invoke a callback JavaScript method, when the map has been saved by user. This is useful for tracking whether the exported maps have been saved by your user.

By default, the invoked function name is FC_Exported(objRtn). You can, however, call a different function as well by specifying the following in your map XML:

<map .. exportCallback='myCallBackFunction' ...>

And you then need to define this function in your JavaScript code. However, if you do not define any call back function in your XML, the default callback function FC_Exported is invoked. In either case, an object is passed to the function as FC_Exported(objRtn) or myCallBackFunction(objRtn), which contains the following parameters (returned from Export Component):

  • statusCode - Has the value of 1 in case of success, and 0 in case of failure.
  • statusMessage - In case of failure, this parameter contains a string description of the error (returned by server)
  • fileName - If saving was successful, this parameter contains the HTTP reference to the image/PDF file saved on server
  • width & height - If saving was successful, these parameters contain the width/height of saved image. Else, they contain 0.
  • DOMId - DOMId of the map that was successfully exported.

Let's quickly see an example code where a callback function has been implemented. In this example, once the user has saved the exported map on his disk (after clicking the Save button for the same), we just show it in a JavaScript alert.

<html>
<head>
<script language="JavaScript" src="../../FusionMaps/FusionMaps.js"></script>
<script language="JavaScript" src="../../FusionMaps/FusionMapsExportComponent.js"></script>
<script type="text/javascript">
  //Default callback function that gets invoked when user has finished saving the exported output to his disk
  function FC_Exported(objRtn){
   if (objRtn.statusCode=="1"){
    alert("The map was successfully saved. Its DOM Id is " + objRtn.DOMId);
   } else{
    alert("There was an error saving the map. Error message: " + objRtn.statusMessage + ". Its DOM Id is " + objRtn.DOMId);
   }
  }

</script>
</head>

<body bgcolor="#ffffff">
<div id="mapdiv" align="center">The map will appear within this DIV. This text will be replaced by the map.</div>
<script type="text/javascript">
//Create the map.
//Note that you necessarily need to set the registerWithJS attribute as 1, as JavaScript is used for client-
//side communication between the map and FusionMaps Exporter Component.

var myMap = new FusionMaps("../../../Maps/FCMap_World.swf", "myMapId", "500", "266", "0", "1");
myMap.setDataURL("Callback.xml");
myMap.render("mapdiv");
</script>

<!-- We also create a DIV to contain the FusionMaps client-side exporter component -->
<div id="fcexpDiv" align="center">FusionMaps Export Handler Component</div>
<script type="text/javascript">
//Render the export component in this
//Note: fcExporter1 is the DOM ID of the DIV and should be specified as value of exportHandler
//attribute of map XML.

var myExportComponent = new FusionMapsExportObject("fcExporter1", "../../../Maps/FCExporter.swf");

//Render the exporter SWF in our DIV fcexpDiv
myExportComponent.Render("fcexpDiv");
</script>

</body>
</html>

 
FC_ExportReady event

At times, you might want to track the event when the map has finished its capture phase and has passed the data to export component, but user has not saved the image/PDF on his disk. Between initiation of map export and till the time FC_ExportReady event is raised, you might show a waiting message/alert to the user that the map is in processing stage.

The syntax of event is FC_ExportReady(DOMId). You can use DOMId (string) as the identifier for each map to check which map has finished processing.

The following code explains its usage:

<script type="text/javascript">
   //This event is raised when the map has finished capture phase and passed the data to
   //Export Component for further processing
   function FC_ExportReady(DOMId){
      alert("The map with DOM ID as " + DOMId + " has finished capture mode. It's now ready to be downloaded");
   }
</script>