RSS

Monthly Archives: November 2011

Intro to GIS using MapXtreme Java

Part of a small project i  worked on during the summer using NetBeans and MapXtreme Java.With Google Maps , YahooMaps and Openstreet Maps you are genrally spoilt for choice for mapping  applications to build on.However for a few of the more customizable map applications you can roll your own maps and have a suitable interface built using JavaBeans in no time at all.

Requirements

Netbeans
MapXtreme Java
Prepared Map (mdf format)

Rolling the code

The MapXtreme beans are based on swing tech so integrating them into any java project isnt that muchof a hassle.Main ones to be aware of are and the ones that will be used :

  • VisualMapJ Bean
  • Map ToolBar Bean
  • Tool Beans
  • LayerControl Bean

The visualmapj displays within its content pane built on MapJ base object from which they all inherit.The MapXtreme components come with buildt in webserver (tomcat) from which the map is loaded and served via jsp.After loading the map and checking that it displays ok on the browser.The next step is serving the data from the webserer to a desktop client.

Loading Map into tomcat webserver

Loading Map into tomcat webserver

and displaying the map in the browser:

Webview of Map

Webview of Map

finally putting the desktop app into shape:

imports added to the top of the app:

import com.mapinfo.beans.tools.MapTool;
import com.mapinfo.beans.tools.MapToolBar;
import com.mapinfo.beans.tools.RectangleSelectionMapTool;
import com.mapinfo.beans.vmapj.RendererParams;
import com.mapinfo.beans.vmapj.VisualMapJ;
import com.mapinfo.mapdefcontainer.FileMapDefContainer;
import com.mapinfo.xmlprot.mxtj.ImageRequestComposer;

preparing the colors for the display panel and the map:

int maxColors = ImageRequestComposer.MAX_COLORS_TRUECOLOR;
String mimeType = “image/gif”;
String filename = “working.mdf”; 

introducing the beans to hold the map and the control panel:

VisualMapJ vMapJ = new VisualMapJ();
MapToolBar mapToolBar1 = new MapToolBar();

specifying the address of the server running and the container that will receie the displayed map:

String m_mapxtremeURL = “http://Cass1opeA:8090/mapxtreme482/servlet/mapxtreme”;
FileMapDefContainer fmdc = new FileMapDefContainer(“/home/wakwanza/Cod/Maps/data/”); 

and finally putting it all together in a simple try catch to get our app running:

try
{
this.getContentPane().add(buttonPanel,BorderLayout.WEST);
this.getContentPane().add(mapPanel,BorderLayout.CENTER);
RendererParams myRendererParams = new RendererParams(m_mapxtremeURL,mimeType);
vMapJ.setRendererParams(myRendererParams);
fmdc.load(filename);
vMapJ.setStartupMapDefinition(new com.mapinfo.beans.vmapj.MapDefParams(fmdc, filename));
vMapJ.setBackground(Color.BLUE);
vMapJ.setSize(new Dimension(550,550));
mapPanel.setVisible(true);
}
catch(Exception e)
{
e.printStackTrace();
}

JavaApp pulling map from MapXtreme

JavaApp pulling map from MapXtreme

 
Leave a comment

Posted by on November 11, 2011 in code, Java, MapXtreme