Tuesday, June 28, 2011

Cognos - Google Map Report with Distance Calculation and Direction Tracking

In this example, we are going to create a Cognos report with Google maps which shows the distance between the two markers and also the route and direction between the two markers.

  1. Take the example which we previously did.
  2. Declare the below variables:

  3. var isCreateHeadPoint = true;
    var headMarker, tailMarker;
  4. Add the below line in the LoadMapGadget() function.

  5. gdirection = new GDirections(map, document.getElementById("directions"));
  6. Add the below lines to the GEvent.addListener of ShowAddress()

  7. if (isCreateHeadPoint) {
              //add the head marker
              headMarker = marker;
              isCreateHeadPoint = false;
             //add the tail marker
             tailMarker = marker;
             isCreateHeadPoint = true;
             // create a path from head to tail
             gdirection.load("from:" + headMarker.getPoint().lat()+ ", " +headMarker.getPoint().lng() +" to:" + tailMarker.getPoint().lat() + "," + tailMarker.getPoint().lng(), {preserveViewport:true});
  8. Add a row in the table.
  9. Add a html item in the last row.
    • Source Type : Text
    • Set the text to the following.

    • <div id="directions" style="width: 275px"></div>
  10. Save and run the report.
  11. To find the route and directions, click on any two markers.
Report Page

Report Output

Thursday, June 23, 2011

Integrating Google Maps with Cognos - Sample

  1.  Login with your google account into the below url.
  2. https://www.google.com/accounts/ServiceLogin?hl=en&continue=http://www.google.co.in/
  3. Sign up for the Google Maps API using the following URL:
  4. http://code.Google.com/apis/maps/signup.html
  5. Enter the IP address of the Cognos server where the reports will be running.
  6. Click on the Generate API Key button to generate a unique key. The unique key that is generated is only valid for the server that you entered earlier to generate the key, and it will be used in the script for working with the Google Maps API. Please remember that the key is only valid for a single Cognos server IP.
  7. Create a new Blank report using Go Sales(Query) Package.
  8. From the insertable objects toolbox, add a Repeater object to the body of the report.
  9. Right-click on the new repeater object and select Go To Query.
  10. Add to the query the Data Items you want to display. This data will be used to assemble a JavaScript array (in a subsequent step).
  11. If you plan to have more than one row in the query (i.e. more than one marker on the map) you will need a column that contains a comma for all but the first row. This comma will be used as a separator for the elements in the JavaScript array. To Do this:
    • Add a Data Item to the query named RowCount. Set the expression to:
    • rank([Address 1])
    • Add another Data Item named ElementSeparator. Set the expression to:
    • If ( [RowCount] = 1 ) THEN
      ( ” )
      ( ‘, ‘ )
  12. Return to the page (Page1).
  13. Click on the repeater and edit the Data->Properties. Click check-boxes by each data item that you will want to use. This will allow you to use them in a report expression.
  14. Change the repeater’s Data->Rows Per Page to 99999(otherwise, Report Studio will try to create a new page for every 20 rows in your repeater)
  15. Create a table with 1 row and 2 columns.
  16. Place the repeater in the second column.
  17. Add an HTML Item to the left of the table. This will contain the start of the JavaScript.
    • Source Type : Text
    • Set the HTML text to the following
    • <html>
      <script src="http://maps.google.com/maps?file=api&v=2&key=ABQIAAAAx7vAbzXFBJGQEupKGA51dBQTTvU48baM3A06e5jSe_wpl0bp3RShVke5jiOCbv1e64rD40-_wur7QA" type="text/javascript">
  18. Add a second HTML Item immediately to the left of repeater.
    • Source Type : Text
    • HTML text to following:
    • <div id="map" style="width: 700px; height: 400px"></div>
      <script type="text/javascript">
      var map = new GMap2(document.getElementById("map"));
      var geocoder = new GClientGeocoder();
      var locations=[
  19. Add a third HTML Item inside the repeater. This will be the assembly of the array containing your data.
    • Source Type : Report Expression
    • Set the report expression to the following, modifying it to fit your data:
    • [Query1].[ElementSeparator] + '{Address:"' + [Query1].[Address 1] + '",City:"' + [Query1].[City] + '",Country:"' + [Query1].[Country] + '"}'
  20. Immediately to the right of the repeater, add a fourth HTML Item
    • Source Type : Text
    • Set the HTML text to the following:
    • ];
      function showAddress(i, j) {
                if (!geocoder)
               var address = locations[i].Address.concat(",".concat(locations[i].City));
               var html="<B>";
               html=html.concat(", ");
               html=html.concat("<a href=/"">
               html=html.concat("\" target=\"_blank \"> Click here to view Sales Report </a>");
               var customIcon = new GIcon(G_DEFAULT_ICON);
               customIcon.image = "http://maps.google.com/mapfiles/marker_yellow.png";
               geocoder.getLatLng(address, function(point) {
                         if (!point) {
                         map.setCenter(point, 1);
                         var marker = new GMarker(point, {icon: customIcon});
                         GEvent.addListener(marker, "click", function() {
                         if(j == 1)
                         map.addControl(new GSmallMapControl());
                         map.addControl(new GMapTypeControl());
               function loadMapGadget()
                      for (var i = 0; i < locations.length; i++)
                            showAddress(i, 0);
          <body onload="loadMapGadget();">
  21. Add a list to the first column of the table. Add a HTML item to the list.
    • Source Type : Report Expression
    • Set Report Expression to the following:
    • '<a href="#" onClick="showAddress('''+ number2string ([Query1].[RowCount]-1) + ''', 1)" >' + [Query1].[Address 1] + ", " + [Query1].[City] + ' </a>'
  22. Goto Page properties. Under Data, Select the Query and in properties add all the DataItems.
  23. Save and run the report.
Report Page
Report Output

Monday, June 20, 2011

Integrating Google Maps with Cognos

Even though IBM Cognos has its own maps as a powerful feature, some users like to see their data integrated or represented using some commonly used tools as Google Maps. With Google Maps, we can obtain a view for any geography, choose the desired location, and open reports related to that particular location.

Architecture : 

Advantages :

  1. All the functionalities of Google Maps can be integrated with cognos like direction tracking, distance calculation etc.
  2. Drill down to another cognos report from the map.