Exporting Maps as PDF or Images > Batch export > Setting it up |
Here, we'll cover examples for setting up batch exporting of maps. We'll first start with the simplest example and then move ahead by configuring various parameters. Before you start, you'll need to follow these steps:
With that done, our next few steps are:
Let's see how to implement each of them in details. |
Configuring XML for client-side export |
In the XML of each map that you need to export, you need to do three things:
The following XML snippet shows how to attain these: |
<map borderColor='005879' fillColor='D7F4FF' numberSuffix=' Mill.' includeValueInLabels='0' labelSepChar=': ' baseFontSize='9' exportEnabled='1' exportAtClient='1' exportHandler='fcBatchExporter'> |
We now create 3 maps in our page. All these maps, for the sake of example, use the same XML. |
<div id="map1div" align="center">The map will appear within this DIV. This text will be replaced by the map.</div> <div id="map2div" align="center">The map will appear within this DIV. This text will be replaced by the map.</div> <div id="map3div" align="center">The map will appear within this DIV. This text will be replaced by the map.</div> |
Note that all the maps have registerWithJS set to 1 and their DOM IDs are myMapId1, myMapId2 and myMapId3 respectively. The next step is to add the exporter component to the page. |
Creating instance of Export Component in your web page |
The instance of the export component can be created in your web page easily using our FusionMapsExportComponent JavaScript class. So, you first need to include the JavaScript class in your page as under. Make sure to include this page after FusionMaps.js, as this class references some of the objects defined in FusionMaps.js. This order of inclusion is important. |
<head> <script language="JavaScript" src="../../FusionMaps/FusionMaps.js"></script> <script language="JavaScript" src="../../FusionMaps/FusionMapsExportComponent.js"></script> </head> |
Now, using this class, you need to create an instance of this component in your page. For that, you first define an empty DIV and name it, as shown under: |
<!-- We also create a DIV to contain the FusionMaps client-side exporter component --> <div id="fcexpDiv" align="center">FusionMaps Export Handler Component</div> |
As you can see above, the DIV has been named as fcexpDiv. Note that you can place this DIV anywhere in your page - it's not necessary to place it beside the map. However, since the UI of this export component shows a button for initiating export, it's better to place it somewhere near the map so that your users can recognize it. Next, you create an instance of the export component in your page using the following JavaScript code: |
<script type="text/javascript"> |
Here, we first create an instance of FusionMapsExportObject, which is the JavaScript class representation of FusionMaps Export Component. To this, we specify the DOM-Id of this export component instance - fcExporter1 in this case. We also specify the location of the component SWF file as second parameter. Next, we need to convey the list of maps that we intend to add to the batch. This is done by specifying all such DOM Ids of the maps in an array. This allows you to selectively configure the maps you want to add to your queue. Or, if you need to instantiate multiple batch exports, each with a different combination of maps, you can do so. |
//Add the maps to queue. The maps are referred to by their DOM Id. myExportComponent.sourceMaps = ['myMapId1','myMapId2','myMapId3']; |
After this, we configure the export component UI to show in full mode, allow saving of output as individual or single file and to allow user to select the saving format. This is done using the following code: |
//Set the mode as full mode myExportComponent.componentAttributes.fullMode='1'; //Set saving mode as both. This allows users to download individual maps/ as well as download all maps as a single file. myExportComponent.componentAttributes.saveMode='both'; //Show allowed export format drop-down myExportComponent.componentAttributes.showAllowedTypes = '1'; |
We also set the cosmetic attributes of UI. |
//Width and height myExportComponent.componentAttributes.width = '350'; myExportComponent.componentAttributes.height = '140'; //Message - caption of export component myExportComponent.componentAttributes.showMessage = '1'; myExportComponent.componentAttributes.message = 'Click on button above to begin export of maps. Then save from here.'; |
Finally, we call the Render method of the class with our DIV id as parameter. This generates an instance of the exporter component in the specified DIV at run-time. |
//Render the exporter SWF in our DIV fcexpDiv myExportComponent.Render("fcexpDiv"); |
Now, all we need to do is invoke the BeginExport() API of batch method. |
Invoking BeginExport method |
We place a button in our page, which when clicked invokes this. The code is shown under: |
//Define a function, which will be invoked when user clicks the batch-export-initiate button ... <input type='button' onClick="javascript:initiateExport();" value="Begin batch export" /> |
The final code of the page looks as under: |
<html> |
When you now fire up your HTML page, you'll see a screen as under. As you can see, the batch export component is present along with the maps, waiting for the user to initiate batch process. |
Once the button is clicked, all maps enter capture phase as shown below: |
Finally, when the maps have been exported to Export Component, it gets populated, as under. The maps exported can either be individually saved from this, or all maps can be saved as a single file (by clicking on Save All) button. |
If you do not wish to allow export of all the maps as a single file, you can just set: myExportComponent.componentAttributes.saveMode='individual'; Or, if you do not want the user to be able to save individual files, you can set this to: myExportComponent.componentAttributes.saveMode='batch'; You would then no longer be able to save individual maps. All the map export output get compiled in a single file, for which you can choose a saving format. In batch mode, the output file name is named as FusionCharts by default (extension depending on what format the user selected). To specify your own file name, you can set the following in JavaScript. myExportComponent.componentAttributes.defaultExportFileName = 'MyMaps'; The exportFileName attribute would NOT work in batch export, as that file name is map specific. The above line collectively specifies a name for all the maps in the batch - when exported as a single file in batch mode. Similarly, if you want to specify a default export format (JPG, PNG or PDF), and hide the combo box (to select formats), you can set: myExportComponent.componentAttributes.defaultExportFormat='PDF'; This results in a single button being shown, which when clicked downloads a single PDF file containing all the maps in batch. |
Customizing the Export Component UI |
The export component offers extensive UI customization options. Here, we'll see some of the basic configuration options. The entire list can be found in the section Component UI Customization. Consider the code below: |
<!-- We also create a DIV to contain the FusionMaps client-side exporter component --> //Add the maps to queue. The maps are referred to by their DOM Id. |
In this example, we've customized font properties, color properties and titles. You can also customize scroll bar properties, combo-box properties, padding and margins. Refer to the section Client-side Exporting > Component UI Customization to get an idea of the same. |