Oracle Maps example - Dynamic (JDBC) theme, dynamic Piechart style and rendering rule


Instructions

This demo adds a dynamic query-based FOI layer to the map. It also creates a dynamic 5-slice Pie chart style to plot the population of five different races on each state. The SQL query looks like the following:
select geom, state, WHITE, BLACK, ASIANPI, state_abrv, AMINDIAN, HISPANIC from states
As you can see, in the middle of the five population columns is one state_abrv (state's abbreviation name) column. So how do you tell the Pie chart style which 5 columns should be used to draw the pie charts (and ignore the state_abrv column)? This is where the new (11g only) custom rendering rule comes into play.
Basically, with MapViewer 11g you can explicitly define the association between the columns in the underlying query and the Advanced style that needs to consume the values from such columns. Such association is specified through what we call Custom Rendering rules. This is illustrated in the theme definition listed in the following section.

Source code

The key JavaScript code for the above map is listed below.
  function createThemeFOI()
  {
    var baseQuery= "select geom, state, WHITE, BLACK, ASIANPI, state_abrv, AMINDIAN, HISPANIC from states";
    var theme = "<themes><theme name='MY_JDBC_THEME' >" +
                "<jdbc_query spatial_column='geom' jdbc_srid='8307' key_column='state' " +
                "render_style='C.COUNTIES' datasource='mvdemo'>" + baseQuery +
                "</jdbc_query>"+ 
                "<rendering>"+
                "   <style name='my_style' value_columns='white,black,asianpi,amindian,hispanic'/>"+
                "</rendering>"+ 
                "</theme></themes>" ; 
    themebasedfoi = new MVThemeBasedFOI('ajdbctheme',theme);    
    themebasedfoi.setBringToTopOnMouseOver(true);
	themebasedfoi.enableImageCaching(false);	
    mapview.addThemeBasedFOI(themebasedfoi); 
  }
	
In the above, we are defining a JDBC theme-based FOI layer. Note the element <rendering> and its sub-elements. This is how we can explicitly specify which (value) columns should be used by which style. In this case, the 5 race columns are associated with the style named "my_style", which is a dynamically created pie chart style. This custom rendering rule will override the theme's existing rendering style(s), which is C.COUNTIES in this example.
Note also that in the above code we tell the MapViewer server to not cache any of the generated pie chart images, via the method enableImageCaching(false). This is usually a good idea when working with advanced styles and thematic mapping. If the server caches the pie chart images, you may not see a different pie chart even if you modify the population data in the underlying table.