A few days back a friend of mine who works as an Oracle DBA was asking me what would be the easiest way to publish maps on the internet. His company, an Oracle shop, has just started dealing with (simple- mainly point) Oracle spatial data but had almost zero experience of GIS software. My advice was to use the existing Oracle tools which allow you to easily publish online maps without the need for any coding. For his benefit and others who may be in the same situation, this post explains how to do this using Oracle’s MapViewer. Using Mapviewer you can easily create simple web mapping sites to publish not only your Oracle Spatial data but also include external data, such as shapefiles, WMS Services and even Google or Bing Maps backrounds without writing a single line of code!. The sites come complete with simple pan and zoom tools, overview window, legene and AJAX-like zooming similar to the ones found in Google, Bing and ArcGIS Server web mapping.
This will seems like a long-winded process but once you got everything setup it should only take a few minutes to publish your maps.
You will also need to install Oracle MapViewer which is a a J2EE service for rendering maps, MapBuilder the admin tool to create layers, symbology and base maps and the eLocation Look & Feel which includes various map symbols to render your maps. All of the above, are available at http://www.oracle.com/technetwork/middleware/mapviewer/overview/index.html
Installing the MapViewer J2EE service
The easiest way is to download the QuickStart Kit which includes OC4J (Oracle Containers for J2EE) standalone with MapViewer 11g patch 4 (126.96.36.199.1).
Once downloaded, unzip it to a folder (e.g. c:\oc4jmv) and edit the start.bat file to point to your JDK and OC4J installs e.g.:
C: cd C:\oc4jmv\oc4j\j2ee\home "C:\Program Files (x86)\Java\jdk1.6.0\bin\java" -server -Xmx768M -jar oc4j.jar
Run the start.bat file. A DOS window will popup which will ask you for a password for the OC4J admin site:
Enter and confirm you password. You should now be able to go to the mapviewer site at: http://localhost:8888/mapviewer
Click on the [Admin] link and enter the oc4j admin username (oc4jadmin), the password you specified in the previous step, and you should be redirected to the page below:
Create a Data Source
To create a Data Source:
Click on the Data Sources link and add the connection info:
Click on [Submit] to create the data source. We are going to use the data source when we create our web site.
The web server which will host our web mapping application is up and running but we have not defined any spatial data or layers yet. To do this, we will need to use Map Builder.
Download Oracle Mapbuilder and symbol styles
- Download the Map Builder zip file
- Unzip the mapbuilder.ear file to a folder of your choice. Create a batch file to run it, e.g.:
- java -Xmx512m -jar mapbuilder.jar
- Download the Oracle eLocation Look & Feel styles from http://download.oracle.com/otn/other/mapviewer/zip/elocation_styles.zip
- This is basically various symbols for use with Map Builder. In typical Oracle style this is not as simple as it sounds. The zip file included a dmp file which the readme file says you can can import to any of your schemas using:
imp system/***** fromuser=mapper_wld touser=scott file=elocation_styles.dmp
Well- not quite. The import expects to find a MAP_WLD_DATA tablespace which –I guess- you don’t have. So you need to create this before you run the import. The import will create three additional tables in your schema: SDO_MAPS, SDO_THEMES and SDO_STYLES. In this case we are only interested in the SDO_STYLES table, which we would need to copy into to the USER_SDO_STYLES table so they will be available in Map Builder.
- Run the following statement in sql:
insert into user_sdo_styles select * from sdo_styles;
- Now start Map Builder using the batch file you created. Create a new connection using the connection details for the user you imported the styles for.
- Expand the [Styles] leaf in the tree and have a look at the various styles you imported
TIP: These styles are held in the USER_SDO_STYLES table.
Now that we have the styles in we are ready to import some spatial data (or use our own).
In Map Builder have a look at the [Themes] leaf. For now we would be looking only Geometry themes (basically vector data stored in Oracle as the SDO_GEOMETRY type).
Assuming you already have some spatial data, these are the steps to register the spatial table :
- Right-click on the Geometry themes and select [Create Geometry Theme]
- A wizard will display. Enter the name of the theme you want to create and select from the available spatial tables.
- Select the symbology for your theme depending on its geometry type. In this example, I selected a Marker symbol since I am creating a point theme.
- Accept the defaults in the next screens to complete the theme creation. You should now be able to view your spatial data on a map by selecting the [Preview] tab.
You can always edit your data and change symbology, labelling, etc.
If you don’t have any spatial data and want to have a play around, I will also show how to import a shapefile. For this example, I used Greece’s administrative boundaries ( you can download it here) ) but obviously you can use any shapefile.
Select Tools->Import Shapefile
Select your shapefile path on the next screen and enter the spatial table’s name and spatial column
Mapbuilder does not seem to recognize the correct SRID for the shapefile (although in this example my shapefile did have a prj file) so you have to type this in. In this case my data is on WGS84, so I used 4326 as the SRID.
Click on the [Create Predefined Theme] to also create the Geometry theme. Select the style to draw the theme
Once finished, you should be able to view the new theme on the map.
Creating a Base Map
We have now created two themes. What we need to do next is create a Base Map. Base Maps are basically a container for a collection for themes. We can defined as many base maps we want with different themes for each.. It will be the Base Map we will be referring to when we create our mapping app. The Base Map will also control the individual layer zoom scales. Base Map data is held in the USER_SDO_MAPS table.
Creating a Base Map is a simple 2-step process. First right-click on Base Maps in the tree view and select [Create Base Map]. Enter the name of the Base Map and click on the [Next] button.
In the next window, select the Geometry themes you want to include in you base map and click the green button to add them to the map. You can also define the Minimum and Maximum zoom scales the map will display on.
Click [Next] and [Finish] to complete the Base Map creation. You should end up with something similar to the screenshot below:
Creating Tile Layers
The next step is to create the Map Tiles. Mapviewer has the concept of a map tile server which will basically take a base map that you define and create map tiles for different zoom scales. Very similar to how Bing and Google maps work.
To create the map tiles:
Right-click on Tile Layers and select [Create Map Tile Layer]. Mapbuilder will ask you which Base Map to use. Select the Base Map and click ok. On the next wizard screen enter the name of your TileLayer:
On the next screen, first press the green arrow to preview the full extent of your data and then click on [Update from Map] button to set the Tile Layer Bounds:
Now click on the [Zoom Levels] tab and:
For Minimum Scale click on the [From Map] button.
For Maximum scale zoom in to where you want to set your maximum scale to and then click on [From Map]
Set how many zoom level you want between Minimum-Maximum scale (default is 10) and click on [Generate]. You should end up with something like this:
Accept the Default values in the next steps and click on [Finish]. The last screen will display the Tile Layer Definition:
Make sure the Mapviewer server has the correct URL and the Mapviewer Data Source displays the Data Source you created in the previews steps. Click on [OK]. The new TileLayer should appear in Mapbuilder’s tree view.
Creating the Mapping site (finally)
If you read that far, congratulations! You are finally ready to create that elusive web mapping app with the data you created in the previous steps. Simply right click on the Tile Layer you have just created and select [Application Builder]
This will open a wizard dialog. I won’t go through every single step as most of the steps are pretty much self-explanatory. Things to note are:
Features Of Interest (FOI) themes (Step 3). A FOI according to Oracle is :
This is a nutshell means that Legends and Show/Hide Layer controls only apply for FOI themes. In this example –for demonstration purposes only- we will use the same themes we used for the Tile Layer (Admin Bounds and POIS). In effect we will duplicate them.
Legend Styles (Step 4)
If you defined FOI themes you should also define the styles for them. Mapbuilder does not give any indication as to what style corresponds to which theme, but it looks like its using the order of the FOI themes. You can change the Style Label as it defaults to the (ugly) style name
Additional Application Parameters
- Make sure that the Mapviewer server setting has the correct URL- it defaults to a different port.
- Click on [Get Data Sources] to pick up the Data Source you created in the previous steps.
- Click on the [File] button to define the HTML filename and full path
Click on [Finish] to create the HTML file. Only a single file is created so you can either run it by double-clicking on it or copy it your web server directory. In either case what should display is something similar to the image below: