Demo

LocationBox JavaScript Demos

Add Coloring Analysis

Add:     Remove:  

Instructions

Use the "Add" button to add a predefined color analysis on the map. Use "Remove" button to remove the coloring. 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, 5);
  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.createColoringAnalysis("IL", mouseClick);
      var xml = "<table>"+
                "<tr><th>IL</th><th>COLOR</th><th>INFO-1</th><th>INFO-2</th></tr>"+
                "<tr><td>34</td><td>1</td><td>2</td><td>3479</td></tr>"+
                "<tr><td>42</td><td>2</td><td>3</td><td>4956</td></tr>"+
                "<tr><td>35</td><td>3</td><td>4</td><td>32372</td></tr>"+
                "<tr><td>23</td><td>4</td><td>5</td><td>3</td></tr>"+
                "<tr><td>9</td><td>5</td><td>6</td><td>223</td></tr>"+
                "<tr><td>48</td><td>6</td><td>7</td><td>123</td></tr>"+
                "<tr><td>44</td><td>7</td><td>8</td><td>22</td></tr>"+
                "<tr><td>55</td><td>3</td><td>9</td><td>1</td></tr>"+

				"<tr><td>1</td><td>0</td><td>1</td><td>2387</td></tr>"+
                "<tr><td>2</td><td>1</td><td>2</td><td>3479</td></tr>"+
                "<tr><td>3</td><td>2</td><td>3</td><td>4956</td></tr>"+
                "<tr><td>4</td><td>3</td><td>4</td><td>32372</td></tr>"+
                "<tr><td>5</td><td>4</td><td>5</td><td>3</td></tr>"+
                "<tr><td>6</td><td>5</td><td>6</td><td>223</td></tr>"+
                "<tr><td>7</td><td>6</td><td>7</td><td>123</td></tr>"+
                "<tr><td>8</td><td>7</td><td>8</td><td>22</td></tr>"+                
				"<tr><td>10</td><td>9</td><td>1</td><td>2387</td></tr>"+

				...

				"<tr><td>71</td><td>0</td><td>1</td><td>2387</td></tr>"+
                "<tr><td>72</td><td>1</td><td>2</td><td>3479</td></tr>"+
                "<tr><td>73</td><td>2</td><td>3</td><td>4956</td></tr>"+
                "<tr><td>74</td><td>3</td><td>4</td><td>32372</td></tr>"+
                "<tr><td>75</td><td>4</td><td>5</td><td>3</td></tr>"+
                "<tr><td>76</td><td>5</td><td>6</td><td>223</td></tr>"+
                "<tr><td>77</td><td>6</td><td>7</td><td>123</td></tr>"+
                "<tr><td>78</td><td>7</td><td>8</td><td>22</td></tr>"+
                "<tr><td>79</td><td>8</td><td>9</td><td>1</td></tr>"+
				"<tr><td>80</td><td>9</td><td>1</td><td>2387</td></tr>"+
				"<tr><td>81</td><td>1</td><td>1</td><td>2387</td></tr>"+
                "</table>";
      analysis.setAnalysisColoringData(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 coloring analysis. See this post on LocationBox blog.

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