Capturing Mouse events |
FusionMaps XT uses FusionCharts JavaScript Class that takes care of all the products of FusionCharts Suite XT including FusionMaps XT. Starting FusionMaps XT, you can capture the following mouse events:
Existing users: Prior to FusionMaps XT, entity roll over/out events could be captured through a single event - FC_Event. Although deprecated, you can continue to use this event in your existing code without any problem. These events can be particularly useful if you want to show additional information or perform additional processing for mouse click or hover on respective objects. In this section we will see how to capture and make use of these events. Note: Before you go further with this page, we recommend you to please see the previous section, Listening to events, as we start off from concepts explained in that page. LegendItemClicked event is raised when any of the legend items are clicked. The event can be listened using advanced event registration model. In the argumentsObject it provides the minimum (minRange) and maximum (maxRange) values of the color range represented by the legend item. The following example listens to LegendItemClicked event and shows the minimum and maximum values (of the color range associated with the clicked legend item) in a message box: <html> <head> <title>FusionMaps XT - listen to LegendItemClicked event</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", "300", "0" ); myMap.setXMLUrl("Data.xml"); myMap.render("mapContainer"); function myChartListener(eventObject, argumentsObject){ alert( "You have clicked the legend representing the color range having " + argumentsObject.minRange + " as minimum value and " + argumentsObject.maxRange + " as the maximum value." ); } FusionCharts("myMapId").addEventListener ("LegendItemClicked" , myChartListener ); // --> </script> </body> </html> Note: LegendItemClicked event is not applicable in Gradient Legend. MarkerClicked event is raised when a marker is clicked. The event can be listened using advanced event registration model. In the argumentsObject it provides the data and position of the marker through the following properties:
You can use this event to create external HTML based elements (like panels, information balloons etc.) having information related the marker, over/near the marker. For example, when clicked, you can show a big callout box on top of a city marker with detailed weather data (possibly fetched from web services etc.). The following example listens to MarkerClicked event and shows all the properties passed by the argumentsObject in a message box: <html> <head> <title>FusionMaps XT - listen to LegendItemClicked event</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", "300", "0" ); myMap.setXMLUrl("Data.xml"); myMap.render("mapContainer"); function myChartListener(eventObject, argumentsObject){ alert([ "ID: ", argumentsObject.id, "; Label: ", argumentsObject.label, "; x: ", argumentsObject.x, ", y: ", argumentsObject.x, "; scaledX: ", argumentsObject.scaledX, ", scaledY: ", argumentsObject.scaledY, "; chartX: ", argumentsObject.chartX, ", chartY: ", argumentsObject.chartY ].join("")); } FusionCharts("myMapId").addEventListener ("MarkerClicked" , myChartListener ); // --> </script> </body> </html> MarkerRollover event is raised when mouse hovers over a marker. The event can be listened using advanced event registration model. In the argumentsObject it provides the data and position of the marker through the following properties:
You can use this event to create external HTML based elements (like information balloons, quick callouts etc.) having information related the marker, over/near the marker. For example, when hovered, you can show a big callout on top of a city marker with detailed weather data (possibly fetched from web services etc.). The following example listens to MarkerRollover event and shows the label and the ID of the hovered marker in an HTML element: <html> <head> <title>FusionMaps XT - listen to MarkerRollover event</title> <script type="text/javascript" src="Maps/jquery.min.js"> <script type="text/javascript" src="Maps/FusionCharts.js"> </script> </head> <body> <div id="details"></div> <div id="mapContainer">FusionMaps XT will load here!</div> <script type="text/javascript"><!-- var myMap = new FusionCharts( "Maps/FCMap_World.swf", "myMapId", "400", "300", "0" ); myMap.setXMLUrl("Data.xml"); myMap.render("mapContainer"); function myChartListener(eventObject, argumentsObject){ $("#details").text( "You rolled over marker with label: " + argumentsObject.label + " and ID : " + argumentsObject.id ); } FusionCharts("myMapId").addEventListener ("MarkerRollover" , myChartListener ); // --> </script> </body> </html> MarkerRollout event is raised when mouse leaves a marker. The event can be listened using advanced event registration model. In the argumentsObject it provides the data and position of the marker through the following properties:
You can use this event in conjunction with MarkerRollover event to un-do all actions done through MarkerRollover event. For example, removing a callout detailed description box which was created using MouseRollover event. The following example listens to MarkerRollout event and shows the label and the ID of the hovered-out marker in an HTML element: <html> <head> <title>FusionMaps XT - listen to MarkerRollout event</title> <script type="text/javascript" src="Maps/FusionCharts.js"> <script type="text/javascript" src="Maps/FusionCharts.js"> </script> </head> <body> <div id="pastdetails"></div> <div id="mapContainer">FusionMaps XT will load here!</div> <script type="text/javascript"><!-- var myMap = new FusionCharts( "Maps/FCMap_World.swf", "myMapId", "400", "300", "0" ); myMap.setXMLUrl("Data.xml"); myMap.render("mapContainer"); function myChartListener(eventObject, argumentsObject){ $("#pastdetails").text( "You rolled out of marker with label: " + argumentsObject.label + " and ID : " + argumentsObject.id ); } FusionCharts("myMapId").addEventListener ("MarkerRollout" , myChartListener ); // --> </script> </body> </html> ConnectorClicked event is raised when marker connectors are clicked. The event can be listened using advanced event registration model. In the argumentsObject it provides the IDs of the connecting markers (fromMarkerId,toMarkerId). The following example listens to ConnectorClicked event and shows the IDs of the connecting markers in a message box: <html> <head> <title>FusionMaps XT - listen to ConnectorClicked event</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", "300", "0" ); myMap.setXMLUrl("Data.xml"); myMap.render("mapContainer"); function myChartListener(eventObject, argumentsObject){ alert( "From marker ID: "+ argumentsObject.fromMarkerId + ", To marker ID: " + argumentsObject.toMarkerId); } FusionCharts("myMapId").addEventListener ("ConnectorClicked" , myChartListener ); // --> </script> </body> </html> ConnectorRollover event is raised when mouse hovers over marker connectors. The event can be listened using advanced event registration model. In the argumentsObject it provides the IDs of the connecting markers (fromMarkerId,toMarkerId). The following example listens to ConnectorRollover event and shows the IDs of the connecting markers in an HTML element: <html> <head> <title>FusionMaps XT - listen to ConnectorRollover event</title> <script type="text/javascript" src="Maps/jquery.min.js"> <script type="text/javascript" src="Maps/FusionCharts.js"> </script> </head> <body> <div id="details"> </div> <div id="mapContainer">FusionMaps XT will load here!</div> <script type="text/javascript"><!-- var myMap = new FusionCharts( "Maps/FCMap_World.swf", "myMapId", "400", "300", "0" ); myMap.setXMLUrl("Data.xml"); myMap.render("mapContainer"); function myChartListener(eventObject, argumentsObject){ $("#details").text( "You rolled over Connector which draws from marker with ID: "+ argumentsObject.fromMarkerId + ", To marker with ID: " + argumentsObject.toMarkerId ); } FusionCharts("myMapId").addEventListener ("ConnectorRollover" , myChartListener ); // --> </script> </body> </html> ConnectorRollout event is raised when mouse leaves marker connectors. The event can be listened using advanced event registration model. In the argumentsObject it provides the IDs of the connecting markers (fromMarkerId,toMarkerId). The following example listens to ConnectorRollout event and shows the IDs of the connecting markers: <html> <head> <title>FusionMaps XT - listen to ConnectorRollout event</title> <script type="text/javascript" src="Maps/jquery.min.js"> <script type="text/javascript" src="Maps/FusionCharts.js"> </script> </head> <body> <div id="pastdetails"> </div> <div id="mapContainer">FusionMaps XT will load here!</div> <script type="text/javascript"><!-- var myMap = new FusionCharts( "Maps/FCMap_World.swf", "myMapId", "400", "300", "0" ); myMap.setXMLUrl("Data.xml"); myMap.render("mapContainer"); function myChartListener(eventObject, argumentsObject){ $("#pastdetails").text( "You rolled out from Connector which draws from marker with ID: "+ argumentsObject.fromMarkerId + ", To marker with ID: " + argumentsObject.toMarkerId ); } FusionCharts("myMapId").addEventListener ("ConnectorRollout" , myChartListener ); // --> </script> </body> </html> EntityRollover event is raised when mouse hovers over entities. The event can be listened using advanced event registration model. In the argumentsObject it provides the following properties:
The following example shows an HTML element getting updated with entity data and label when that entity is rolled over: <html> <head> <title>FusionMaps XT - listen to EntityRollover event</title> <script type="text/javascript" src="Maps/jquery.min.js"> <script type="text/javascript" src="Maps/FusionCharts.js"> </script> </head> <body> <div id="details"> </div> <div id="mapContainer">FusionMaps XT will load here!</div> <script type="text/javascript"><!-- var myMap = new FusionCharts( "Maps/FCMap_World.swf", "myMapId", "400", "300", "0" ); myMap.setXMLUrl("Data.xml"); myMap.render("mapContainer"); function myChartListener(eventObject, argumentsObject){ $("#details").text( "You are over entity named: "+ argumentsObject.label + " with value: " + argumentsObject.value ); } FusionCharts("myMapId").addEventListener ("EntityRollover" , myChartListener ); // --> </script> </body> </html> EntityRollout event is raised when mouse hovers out of entities. The event can be listened using advanced event registration model. In the argumentsObject it provides the following properties:
The following example updates an HTML element with entity name and its value when mouse moves out of an entity: <html> <head> <title>FusionMaps XT - listen to EntityRollout event</title> <script type="text/javascript" src="Maps/jquery.min.js"> <script type="text/javascript" src="Maps/FusionCharts.js"> </script> </head> <body> <div id="pastdetails"> </div> <div id="mapContainer">FusionMaps XT will load here!</div> <script type="text/javascript"><!-- var myMap = new FusionCharts( "Maps/FCMap_World.swf", "myMapId", "400", "300", "0" ); myMap.setXMLUrl("Data.xml"); myMap.render("mapContainer"); function myChartListener(eventObject, argumentsObject){ $("#pastdetails").text( "You are out of entity named: "+ argumentsObject.label + " with value: " + argumentsObject.value ); } FusionCharts("myMapId").addEventListener ("EntityRollout" , myChartListener ); // --> </script> </body> </html> |
Using FC_Event (deprecated) to capture roll over/out events on entities To track entity roll over/out through FC_Event, you need to do the following:
The following code shows an example of how to track roll-over events and display information about the entity in a DIV below the map.
<head>
<head>
<title>FusionMaps XT and JavaScript - Entity Hover Capture</title>
<script type="text/javascript" src="../Maps/FusionCharts.js"></script>
<script type="text/javascript">
function FC_Event(DOMId, eventType, objParams){
if (eventType=="rollOver"){
document.getElementById("content").innerHTML = "You rolled over entity with id as " + objParams.id + " having name as " + objParams.lName + " ("+ objParams.sName + ") and value as " + objParams.value;
}else{
document.getElementById("content").innerHTML = "Please roll over an entity to see details.";
}
}
</script>
</head>
<body>
<center>
<h2>FusionMaps XT and JavaScript - Entity Hover Capture Example</h2>
<div id="map1div">FusionMaps XT</div>
<script type="text/javascript">
var myMap = new FusionCharts("../../Maps/FCMap_World.swf", "map1Id", "750", "400", "0");
myMap.setXMLData("<map exposeHoverEvent='1' borderColor='005879' fillColor='D7F4FF' numberSuffix=' Mill.' includeValueInLabels='1' labelSepChar=': ' baseFontSize='9'><data> <entity id='NA' value='515' /><entity id='SA' value='373' /><entity id='AS' value='3875' /><entity id='EU' value='727' /><entity id='AF' value='885' /><entity id='AU' value='32' /></data></map>");
myMap.render("map1div");
</script>
<br /><div id='content'>Please roll over an entity to see details.</div>
</center>
</body>
</html>
The above code does the following:
|