MapViewer How To

How To Build Dynamic Maps Using JDeveloper 10g and Oracle Application Server MapViewer

An Oracle JDeveloper How To Document
Justin Lokitz
October 2004

Contents

     Introduction
     Setting up the MapViewer Extension for JDeveloper 10g
     Using the JDeveloper 10g, MapViewer Tag Libraries and API to Create Dynamic, Web-based Maps
     Conclusion

Introduction

In this document we will discuss how to use Oracle JDeveloper 10g and Oracle Application Server MapViewer to create dynamic, web-based maps. Oracle Application Server MapViewer is a J2EE service for rendering maps using spatial data managed by Oracle Locator or Spatial. Oracle Application Server MapViewer provides Java and XML API's as well as a JavaServer Page Tag Library such that anyone, from a beginning developer to a more advanced developer, will find it easy (and quite powerful) to integrate maps into existing and new development projects.

For more information on Oracle Application Server MapViewer see: http://www.oracle.com/technology/products/mapviewer/index.html

Setting up the MapViewer Extension for JDeveloper 10g

Setting up the Oracle Application Server MapViewer (MapViewer) extension for JDeveloper 10g is quite easy to do. After you have downloaded and deployed the MapViewer kit from OTN (http://download.oracle.com/otn/other/mapviewer/mapviewer1012pre_ear.zip), download the MapViewer extension here: http://download.oracle.com/otn/other/spatial/mapviewer1012_jdev_10g.zip. The MapViewer Extension for JDeveloper 10g comes with three JAR files, mvclient.jar (MapViewer Client Java API), mvpalette.jar (JSP tags that will appear in JDeveloper's Component Palette), and mvconnection.jar (MapViewer metadata connection that will enable you to make a MapViewer metadata connection from which you can browse the existing mapping metadata such as styles, themes and basemaps). To install these, shutdown JDeveloper 10g and simply unzip the three JARS into the JDeveloper 10g extensions directory, found at $JDEV_HOME/jdev/lib/ext. Then restart JDeveloper 10g.

Using the JDeveloper 10g, MapViewer Tag Libraries and API to Create Dynamic, Web-based Maps

In the following sections, we will step through creating a very simple dynamic, web-based map using the MapViewer JavaServer Page Tag Library. After we have created our simple JSP, we will gradually add functionality to this map using standard JavaServer Page and MapViewer API's

Creating a map using the MapViewer JavaServer Page Tag Library:

Open JDeveloper 10g and add a new Application Workspace called "WebMap" using the "Web Application [default]" Application Template. Expand the newly created WebMap workspace, right click on the "View Controller", click "new" then select the"JavaServer Pages (JSP)" and "JSP Page"; click "ok". Change the title of your JSP to "webmap.jsp" and click "ok".

  • With your new JSP (webmap.jsp) open in design mode, center and add a text title of your choice (like "MapViewer WebMap"). Push return to go to the next line.
  • Now, in the "Component Palette" (usually at the top right of JDeveloper 10g), select "MapViewer Tag Library".
  • From the "MapViewer Tag Library" drag the "init" tag to the page.
    • Fill out the "init" tag fields with your MapViewer instance (http://www.yourserver.com/mapviewer/omserver) and datasource (mvdemo) information as well as a user-defined ID (mvHandle).

  • Next, drag the "setParam" tag to the page.
    • Notice that although the "setParam" tag does not pop up an info window, if you select the "setParam" tag on your page you can set the MapViewer parameters in the Property Inspector (usually at the bottom right of JDeveloper 10g).
    • While the "setParam" tag is select fill in the the following parameters: antialiasing (true), basemap (density_map), centerX (-122.4), centerY (37.8), height (450), size (10), title (My Web Map), width (600).

  • Once you have finished filling out the parameters for the "setParam" tag, drag the "run" tag to the page; this tag does not need any parameters so you can leave it as it is.
  • With the cursor to the right on the "run" tag, from the page design bar select the center icon so that our resulting map will be centered on the page.

  • As the map that will drawn on the page is really just an image coming from the MapViewer service, we will need to add an HTML image tag to the page.
    • In the "Component Palette" select "HTML" and drag the "Image" tag to the page.
    • Click on the "source" tab to see the JSP/HTML source for our page.
    • In the "Component Palette" select "MapViewer Tag Library" and drag the "getMapURL" tag between the empty quotes of image tag (the image tag should now look like this <img src="<mapviewer:getMapURL />"/>).

Now we are ready to test our map. With your MapViewer instance running and initialized against your database, save your webmap.jsp and click on the run button at the top of your page. You should now see your JSP WebMap.

Adding to the WebMap using standard JavaServer Page and MapViewer API's:

Now, we will add some interactivity and features to our WebMap via JSP and MapViewer API's as well as URL parameters.

  • On the source tab of the webmap.jsp, place the cursor between the </head> and <body> tags and create a little white space by pressing the return key.
  • In the "Component Palette" select "JSP" and click "Scriptlet". This will allow us to insert some Java code directly into our JSP.
  • Within the scriptlet box add the following code and press "ok":
    // This code will allow you to set JSP parameters from the URL
    String X = request.getParameter("X");
    String Y = request.getParameter("Y");
    String size = request.getParameter("size");

  • Now, place cursor between the <mapviewer:setParam.../> and <mapviewer:run /> tags and create a little space for another scriptlet.
  • Click "Scriptlet" again.
  • This time place the following code in the scriptlet box and press "ok":
    // This logic will tell the webmap.jsp when to run the following MapViewer API code
    if (X != null & Y != null)
    // This is a MapViewer API that is used to draw a point feature (or layer) on top of the map.
    // You can view the Java Documentation for this here: http://www.yourserver.com/mapviewer/mapclient
    mvHandle.addPointFeature(Double.parseDouble(X),Double.parseDouble(Y),8307,"M.STAR",null,null,null);

Once again, we are ready to run our map.

  • Save your webmap.jsp and click on the run button at the top of your page. You should now see your JSP WebMap, however, it will not have any zoom or center on it.
  • In the Address or URL box of your browser, add the following to the end of your webmap.jsp URL and press enter: ?X=-122.4&Y=37.8&size=1 (your entire URL should look something like this http://www.yourserver.com/WebMap-ViewController-context-root/webmap.jsp?X=-122.4&Y=37.8&size=1).

The WebMap should be centered around San Francisco, California (-122.4,37.8) and should be zoomed into to a level of "2". Also, you will notice that a red star has appeared at the center of the map (-122.4,37.8). This of course was drawn dynamically via the MapViewer API (addPointFeature()) we inserted before the "run" tag.

Conclusion

Oracle Application Server MapViewer provides a powerful and flexible way to create dynamic, web-based maps based on location data managed by Oracle Locator or Spatial. With the addition of the MapViewer API's and extension for JDeveloper 10g, map (GIS) application development just became easier, more efficient and more effective.

For more information about Oracle Locator, Spatial and Mapviewer, please see the following:
http://www.oracle.com/technology/products/spatial/index.html
http://www.oracle.com/technology/products/mapviewer/index.html

E-mail this page
Printer View Printer View
Oracle Is The Information Company About Oracle | Oracle RSS Feeds | Careers | Contact Us | Site Maps | Legal Notices | Terms of Use | Privacy