Embedded Google Maps

So first off, your probably thinking the has been covered a million times right… Well I have UTFSE to no avail.

I want to imbed a Google map into Web Intelligence. So I have a stack of LatLong data which I am retrieving through WEBI, being 2 columns EG:

Latitude:        Longitude:
-40.34            175.62
-36.67            150.59

I’ve built a variable [GMAP]:

=[Latitude]+ " ;"+[Longitude]+"#"

And written some Javascript TEST code:

<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <title>Heatmaps</title>
    <style>
      html, body, #map-canvas {
        height: 100%;
        margin: 0px;
        padding: 0px
      }
      #panel {
        position: absolute;
        top: 5px;
        left: 50%;
        margin-left: -180px;
        z-index: 5;
        background-color: #fff;
        padding: 5px;
        border: 1px solid #999;
      }
    </style>
    <script src="https://maps.googleapis.com/maps/api/js?v=3.exp&amp;sensor=false&amp;libraries=visualization"></script>
    <script>
// Adding 500 Data Points
var map, pointarray, heatmap;

var gmapText = [GMAP];

var tmpData = gmapText.split("#");
var taxiData = [];
for (var idx in tmpData) {
	var td = tmpData[idx].split(";");
	taxiData.push(new google.maps.LatLng(td[0],td[1]));
}


function initialize() {
  var mapOptions = {
    zoom: 6,
    center: new google.maps.LatLng(-37.678, 175.52),
    mapTypeId: google.maps.MapTypeId.SATELLITE
  };

  map = new google.maps.Map(document.getElementById('map-canvas'),
      mapOptions);

  var pointArray = new google.maps.MVCArray(taxiData);

  heatmap = new google.maps.visualization.HeatmapLayer({
    data: pointArray
  });

  heatmap.setMap(map);
}

function toggleHeatmap() {
  heatmap.setMap(heatmap.getMap() ? null : map);
}

function changeGradient() {
  var gradient = [
    'rgba(0, 255, 255, 0)',
    'rgba(0, 255, 255, 1)',
    'rgba(0, 191, 255, 1)',
    'rgba(0, 127, 255, 1)',
    'rgba(0, 63, 255, 1)',
    'rgba(0, 0, 255, 1)',
    'rgba(0, 0, 223, 1)',
    'rgba(0, 0, 191, 1)',
    'rgba(0, 0, 159, 1)',
    'rgba(0, 0, 127, 1)',
    'rgba(63, 0, 91, 1)',
    'rgba(127, 0, 63, 1)',
    'rgba(191, 0, 31, 1)',
    'rgba(255, 0, 0, 1)'
  ]
  heatmap.setOptions({
    gradient: heatmap.get('gradient') ? null : gradient
  });
}

function changeRadius() {
  heatmap.setOptions({radius: heatmap.get('radius') ? null : 20});
}

function changeOpacity() {
  heatmap.setOptions({opacity: heatmap.get('opacity') ? null : 0.2});
}

google.maps.event.addDomListener(window, 'load', initialize);

    </script>
  </head>

  <body>
    <div id="panel">
      <button onclick="toggleHeatmap()">Toggle Heatmap</button>
      <button onclick="changeGradient()">Change gradient</button>
      <button onclick="changeRadius()">Change radius</button>
      <button onclick="changeOpacity()">Change opacity</button>
    </div>
    <div id="map-canvas"></div>
  </body>
</html>

So what’s going on here is var GMAP is raw SQL data being split, looped and pushed into the array TaxiData. Forward of that TaxiData is plotted onto the map, or heatmap in this case. There’s also some HTML toggle functions. The HTML is then plastered into a cell on the webi report, which is set to HTML. So when the query is executed VAR [GMAP] should change, and subsequenty the map is refreshed, or the request executed.

Onto my problem (assuming there is no inherrient flaws in the plan above):
The map is coming up blank, well it is rendering the HTML, so I can see the toggle boxes availiable, but zip, ziltch where the map should be - just white space. I can’t seem to get ANY <a href www. to work. For example www.google.com is returning the same blank white page.
My first thought was perhaps Rich Client wouldn’t work for this, so I have tried launchpad, in both web & rich internet versions, all options I have the same result.
So, next thought is that the server does not have internet enabled for security reasons. Would the execution of this code be through the server?
And finally, I have attempted various different <a href syntax variations.

Any thoughts, or anyone have any success embedding any websites to WEBI?

Thanks,
Thomas

[Moderator Edit: Added code formatting - Andreas]


Thomas Evans :new_zealand: (BOB member since 2013-10-17)

Hi Thomas, greetings from Brazil!!
I was abble to embed a web page with google maps into webi 3.x
What worked for me:

  • Publish the document to Infoview;
  • Open the document in web mode;
  • it only worked for me in Google Chrome. I wasn’t abble to get it to work on IE.
    Cheers,
    Rogerio

rgoulart :brazil: (BOB member since 2011-08-21)

Rogerio,

Thanks for that.

I haven’t tried chrome - will do so :slight_smile:

Was this using the method I just explained or a different method?

EDIT:

Tried Chrome, didn’t work. I think it’s a network secutiry issue so trying to change firewall permissions to enable the SRC.

Thanks,
Thomas


Thomas Evans :new_zealand: (BOB member since 2013-10-17)

Did you try embeding a simple web page with a , again, simple javascript code? It worked?


rgoulart :brazil: (BOB member since 2011-08-21)

<a href=“www.google.com”

Give me nothing, just a blank white cell / box, which isn’t displaying “<a href=“www.google.com”” words at least…

I think the web version must execute this request via the server, in your implementation does your server have web access?


Thomas Evans :new_zealand: (BOB member since 2013-10-17)

Update…

I have google maps working within Business Objects WEBI now, and have also begun building in the Google Maps Watypoints functionality, excuse the rough Javascript…

<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <title>Waypoint Test</title>
    <style>
      html, body, #map-canvas {
        height: 100%;
        margin: 0px;
        padding: 0px
      }
    </style>
    <script src="https://maps.googleapis.com/maps/api/js?v=3.exp&amp;sensor=false&amp;libraries=visualization"></script>
    <script type="text/javascript">
    
	var directionsDisplay;
	var directionsService = new google.maps.DirectionsService();
	var map = null;
    
    function initialize() {
    	directionsDisplay = new google.maps.DirectionsRenderer();
    	var NZ = new google.maps.LatLng(-36.840417, 174.739869);
    	var mapOptions = {
    			zoom: 6,
    			centre: NZ
    	}
    	
        map = new google.maps.Map(document.getElementById('map-canvas'), mapOptions);
        	directionsDisplay.setMap(map);
        }
    	
    function getQueryVariable(variable) {
    	var query = window.location.search.substring(1);
    	var vars = query.split("&amp;");
    	for (var i=0;i<vars.length;i++) {
    		var pair = vars [i].split("=");
    		if (pair[0] == variable) {
    			return pair [1];
    		}
    	}
    }

    
    function calcRoute(){
    	var start = document.getElementById('start').value;
    	var end = document.getElementById('end').value;
    	var waypts = [];
    	var Array = document.getElementById('waypoints');
    	for (var i = 0; i < Array.length; i++) {
    		if (Array.options[i].selected == true) {
    			waypts.push({
    				location:Array[i].value,
    			     stopover:true});
    		}
    	} 	
    	
    var request = {
        origin: start,
        destination: end,
        waypoints: waypts,
        optimizeWaypoints: true,
        travelMode: google.maps.TravelMode.DRIVING
        };
    
    directionsService.route(request, function(response, status) {
        if (status == google.maps.DirectionsStatus.OK) {
          directionsDisplay.setDirections(response);
          var route = response.routes[0];
          
        }

    });
    }
    
    
    google.maps.event.addDomListener(window, 'load', initialize);
    
    </script>
  </head>
  <body onload="calcRoute()" onunload="GUnload()">
<div id="map-canvas"></div>
<input type="text" id="start" value="Auckland"></input>
<input type="text" id="end" value="Wellington"></input>
<input type="text" id="point" value="Cambridge"></input>
<select id="waypoints">
<option>Taupo</option>
<option>Hamilton</option>
<option>Matamata</option>
<option>Tokoroa</option>
<option>Wellington</option>
</select>
  </body>
</html>

Thomas Evans :new_zealand: (BOB member since 2013-10-17)

Hi Thomas

Could you explain in some words how you perform this ? I can’t see how you can embeld the java code in the webi report. Thank you in advance

Bernard


bernard timbal :fr: (BOB member since 2003-05-26)

Hi Bernard,
Drop a blank cell onto the report , set it to show as html , drop the code inside the cell and open it in WEB or interactive mode.
Cheers,
Rogerio


rgoulart :brazil: (BOB member since 2011-08-21)

…and FYI - needs to be done within BI Launchpad - wont work in client tools, and the server where BI Platform is installed needs to have access to the internet.

Bernard, the script needs to be hosted on your BO server within Tomcat WEBAPPS folder, I am pushing variables from my queries to the Tomcat hosted script via iFrame.


Thomas Evans :new_zealand: (BOB member since 2013-10-17)

Thank you, I will try this soon and let you know

Regards

Bernard


bernard timbal :fr: (BOB member since 2003-05-26)

Ok, I cut past the code in a read-as-html cell and i see as result the picture in attachment

which script ? another one ? embelding google maps in webi reports remains me still very obscurs :frowning:
test_gmap.jpg


bernard timbal :fr: (BOB member since 2003-05-26)

Hi Thomas,
It seems to me that you aren´t passing the variable [GMAP] to the script. I think that you need to , instead of writing [GMAP] directly on the script, you need to concatenate it , something like

… "+ [GMAP] +" in order to your script to work.

Bernard, try this link out
https://bi.ondemand.com/embed/1dwrCOE-jnuth6GhlgO8IUTA1i
login
rgoulart123@gmail.com
Cic@1234
Alter the data on the input controls in order to dinamically change the colors on the map.
< 30 RED

30 and <80 GREEN
80 BLUE

Cheers,
Rogerio


rgoulart :brazil: (BOB member since 2011-08-21)

Hi Rgoulart

Thank you so much to let have mee use your account. Yes, i have been able to see your gmap working but as I wasn’t able to edit the report, the “behind the scene” remind a mystery

Thank you in all case
Regards
Bernard


bernard timbal :fr: (BOB member since 2003-05-26)

Bernard,
I´m attaching the wid uploaded to BiOnDemand. It was built onn 3.1, so I don´t know whether it will work on 4.x. If you need further details on the conbstruction of the document, feel free to contact me through my e-amil.
Cheers,
Rogerio
amsterdam.wid (121.0 KB)


rgoulart :brazil: (BOB member since 2011-08-21)

Thank you, yes, it works on my bi 4 test platform :lol:

I have just to understand how it works now. I will keep you in touch

Thank you again !

Bernard


bernard timbal :fr: (BOB member since 2003-05-26)

Hi Bernard & Rogerio,

I’m sorry for my my notes, they are a tad haphazard, but rest assured I will continue to follow this thread and assist with your queries where possible, be aware however my javascript isn’t the best but I generally get the right outcome - see some of my post history on custom javascript token generation…

As for the GMAP variable, the first script at the top of the page was something I had initially written blindly (I couldn’t get the cell to render correctly, which was due to my server not having internet access) and I moved from that proof of concept to the more recent code.

I’d suggest checking out the link below as it gave me the inital idea based on iFrame:

http://bihappyblog.com/2012/01/20/google-maps-in-webi-4-0-mashup/

And also and more relevent the following post - this one is more around rendering the javascript in the client side cell, iFrame deals with a map hosted on your Tomcat.

To get you started really quickly (with an executable map hosted on your server) do the following:

  1. log into your server

  2. create a folder called ‘mashup’ at program files/SAP Business Objects/Tomcat6/webapps/

  3. drop the attached file in the mashup folder and change the extension to .html

  4. check that the file is accessable from your local machine by going to:

http://YOUR ADDRRESS:YOUR PORT/mashup/file5.html?address=boston

(The map should execute in your browser resolving whatever address you parse)

So now you want it to work from WEBI with an iFrame…

  1. create a dimension in a webi report using the following forumla:
="<iframe id=\"mapFrame\" name=\"mapFrame\" src=\"about:blank\" width=\"1000\" height=\"600\" frameborder=\"0\" scrolling=\"no\"></iframe>"
  1. create another dimension which does your address work, this will take some messing around with if you are using lat longs or addresses concatenating values etc, here’s an example using some concat address data:
="<a href=\"../../../../../../mashup/file5.html?address= "+URLEncode([City])+"\" target=\"mapFrame\">"+[Address]+" "+[City]+" "+[State]+" "+[Zip Code]+"</a>"
  1. Drop your address list into your report and define an element link between address and iframe

  2. Click addresses in list and watch the magic.

If that doesn’t work, check the mode of webi you are in, I think it has to be interactive from memory, and ensure the server can get internet as it needs to push these requests to google API.

Good luck and let me know if you have problems!!
file5.txt (1.0 KB)


Thomas Evans :new_zealand: (BOB member since 2013-10-17)

Hi Thomas

Thank you for this step-by-step tutorial. Could you just explain the steps 6 an 7 (the “define an element link” ???) as i can’t understand the links and actions between the objects [adress], [city], [zip code] and the two previously created technical objects containing i-frame and urls.

thank you in advance
Bernard


bernard timbal :fr: (BOB member since 2003-05-26)