Demo

LocationBox JavaScript Demos

Add Pie Analysis

Add:     Remove:  

Instructions

Use the "Add" button to add a predefined pie analysis on the map. Use "Remove" button to remove the analysis information. Edit the source code to .
See the JavaScript API for more information.

Source Code

The Javascript code for the above map is:

<script language="Javascript" 
	src="http://www.locationbox.com.tr/locationbox/services?
	Key=key&Cmd=API&Typ=JS"></script>

<script language="JavaScript">
var mapper  = new IMapper();
var analysis = new IAnalysis();

function startup() {
  mapper.initMap(40.2, 35.1, 1);
  mapper.addNavigationPanel();
  return;
} 

function mouseClick(pos, info) {
      var html = '<table border="0" height="100%" width="100%">';
      for( var i = 0; i < info.data.length; i++ ) {
        var data = info.data[i];
        var color = "#BBBBBB";
        if( (i & 1) != 0 ) color = "#DDDDDD";
        html += '<tr bgcolor=' + color + '>
                      <td>' + data.name + '</td>
                      <td>' + data.value + '</td></tr>';
      } // for()
      html += '</table>';
      mapper.displayInfoWindow(pos.y, pos.x, html, 180, 100, "Bilgi: " + info.id);
      return;
    } 

    function add() {
      analysis.createPieAnalysis("IL", mouseClick);
  
      var sty = { "radius": 20, "pies": [ {"name": "A", "color": "#FF0000"}, 
                                          {"name": "B", "color": "#00FF00"}, 
                                          {"name": "C", "color": "#0000FF"} ] 
                };
      analysis.setAnalysisPieStyle(sty);
  
      var xml = "<table>"+
          "<tr><th>IL</th><th>Item 1</th><th>Item 2</th><th>Item 3</th></tr>"+
          "<tr><td>35</td><td>500.0</td><td>200.0</td><td>1000.0</td></tr>"+
          "<tr><td>23</td><td>300.0</td><td>500.0</td><td>100.0</td></tr>"+
          "<tr><td>55</td><td>1500.0</td><td>800.0</td><td>600.0</td></tr>"+
          "<tr><td>1</td><td>500.0</td><td>200.0</td><td>1000.0</td></tr>"+          
          "</table>";
      analysis.setAnalysisPieData(xml);
      return;
    } 

    function remove() {
      analysis.removeAnalysis();
      return;
    } 

Buttons:


  <a href="javascript:add()"><img src="images/add.gif" border=0></a>
  <a href="javascript:remove()"><img src="images/remove.gif" border=0></a>
  
					
Notes

You may get "Request string is too long for Oracle Maps' non-AJAX remoting" error while creating a pie analysis. See this post on LocationBox blog.

Download working page
Remember that you need to use your key code as Key attribute.