<%// UseOLAPData:%>


<%
// To use OLAP data, you must know the name of the OLAP host server and
// connect to that server using a valid username and password. To build
// a graph, you can pass a valid SQL query statement to the OLAP server.

/************************************************************************
 * To run this sample, you must edit the String and int declarations    *
 * below so that they define a valid SQL query, username, and password  *
 * for accessing your OLAP data                                         *
 ************************************************************************/

// This sample application generates an ESRI map chart that shows product sums
// for selected products and years, displayed on the states of the US. The sample
//    1) Creates strings to store the SQL query, the OLAP server name,
//       and the connection port. The result set from the query is
//       used to create an OLAPDataSet.
//    2) Creates a ESRIMapChartOLAPDataModel. The model's constructor
//       specifies the OLAPDataSet as an argument.
//    3) Creates an OLAPESRIMapChart and specifies the
//       ESRIMapOLAPDataModel as its data model.
%>

<%@page import="
        com.sas.servlet.tbeans.olapgraphics.html.OLAPESRIMapChart,
        com.sas.graphics.components.esrimap.ESRIMapOLAPDataModel,
        com.sas.storage.olap.sasmdx.OLAPDataSet"
%>

<%
   // 1) Create strings to store the SQL query, the OLAP server name,
   // and an int to store the connection port.

   /******* modify query to access your data **********/
String OLAP_QUERY="SELECT CROSSJOIN({[GEOGRAPHY].[USREGION].MEMBERS},"
                   + "{[PRODUCTLINE].[PRODUCT].MEMBERS}) ON COLUMNS,"
                   + "{[TIME].[YEAR].MEMBERS} ON ROWS "
                   + "FROM MYOLAPCUBE WHERE ([Measures].[ACTUAL_SUM])"; // specify valid OLAP source
   String OLAP_SERVER="myOLAPServer.com"; // specify a valid server name
   int OLAP_PORT=9999;  // specify a valid port

   // 2) Create an ESRIMapOLAPDataModel and specify
   // an OLAPDataSet as an argument on the constructor.
      ESRIMapOLAPDataModel olapDataModel = null;
      try {
          // OLAPDataSet arguments: host, port, username, pwd, query
             olapDataModel=new ESRIMapOLAPDataModel(
             new OLAPDataSet(OLAP_SERVER, OLAP_PORT, "myLoginName", "myPwd",
                             OLAP_QUERY), true);
          } catch (Exception ex) { ex.printStackTrace(); }
%>

<%
   // 3) Create an OLAPESRIMapChart and specify the
   // ESRIMapOLAPDataModel as its data model.
      OLAPESRIMapChart mapChart=new OLAPESRIMapChart();
      mapChart.setDataModel(olapDataModel);

   // Set a width and height for the chart
      mapChart.setWidth(640);
      mapChart.setHeight(520);

   // Set the ESRI server connection information
      mapChart.setConnectionProperties( "ESRIServerName", "ESRIDomainName", "USERID" "PASSWORD" );

   // Set which map service to use on that server.  We want a US map.
      mapChart.setMapService( "ContinentalUS_Projected" );

   // Set HTTP-specific response and request functionality
      mapChart.setResponse(response);
      mapChart.setRequest(request);

   // Set the level to layer information
      Map levelToLayerMap = new java.util.HashMap();
      levelToLayerMap.put( "[geography].[usregion]", "usregions" );
      levelToLayerMap.put( "[geography].[statecode]", "states" );
      levelToLayerMap.put( "[geography].[county_name]", "counties" );
      mapChart.setLevelToLayerMap( levelToLayerMap );

   // Set the layer to field information
      Map layerToFieldMap = new java.util.HashMap();
      layerToFieldMap.put( "usregions", "SUB_REGION" );
      layerToFieldMap.put( "states", "STATE_FIPS" );
      layerToFieldMap.put( "counties", "FIPS" );
      mapChart.setLayerToFieldMap( layerToFieldMap );

   // Write the chart to the display
      mapChart.write(out);
%>