Re: [OpenMap Users] BasicMapPanel

From: Don Dietrick <dietrick@bbn.com>
Date: Thu Feb 19 2004 - 12:38:49 EST

Hi Rachel,

The BasicMapPanel *is* the JPanel you are looking for. In your code,
you aren't adding the MapPanel to the EVMap, which would make your code
work, too.

To prevent the BasicMapPanel from searching for an openmap.properties
file, create it with a PropertyHandler created from an empty
Properties. See code below, modified from your code to use the
BasicMapPanel:

import java.awt.*;
import javax.swing.*;
import java.util.Properties;

import com.bbn.openmap.*;
import com.bbn.openmap.layer.*;
import com.bbn.openmap.layer.shape.*;
import com.bbn.openmap.gui.*;

public class map {

     /** Creates a new instance of TestFile */
     public static void main(String args[]) {

         //BackgroundMap map = new BackgroundMap();
         EVMap ev = new EVMap();

         JFrame frame = new JFrame("Experiential Systems Group Map
Interface");

         frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

         frame.getContentPane().add(ev);

         frame.setVisible(true);

     }

     public static class EVMap extends BasicMapPanel {

         public EVMap() {
                // Prevent the BasicMapPanel from creating a PropertyHandler with no
                // properties, which would cause it to look for an openmap.properties
file:

             super(new PropertyHandler(new Properties()));
             try {

                 // Get the default MapBean that the BasicMapPanel
created.
                 MapBean mapBean = getMapBean();

                 // Set the map's center
                 mapBean.setCenter(new LatLonPoint(43.0f, -95.0f));
                 // Set the map's scale 1:120 million
                 mapBean.setScale(120000000f);

                 addMapComponent(new LayerHandler());
                 addMapComponent(new GraticuleLayer());

                 ShapeLayer shapeLayer = new ShapeLayer();

                 Properties shapeLayerProps = new Properties();
                 shapeLayerProps.put("prettyName", "Political Solid");
                 shapeLayerProps.put("lineColor", "000000");
                 shapeLayerProps.put("fillColor", "BDDE83");
                 shapeLayerProps.put("shapeFile",
                                            
"C:/openmap-4.6/ESGData/world.shp");
                 shapeLayer.setProperties(shapeLayerProps);
                 shapeLayer.setVisible(true);

                 addMapComponent(shapeLayer);

                 // Create the directional and zoom control tool
                 addMapComponent(new OMToolSet());
                 // Create an OpenMap toolbar
                 addMapComponent(new ToolPanel());

             } catch (MultipleSoloMapComponentException msmce) {
                 System.out.println(msmce.getMessage());
             }
         }

     }
}

- Don

On Feb 19, 2004, at 12:09 PM, Rachel Lee Knickmeyer wrote:

> I want to create a map widget that can be used across a variety of
> applications, thus it should be bundled as a simple JPanel that can be
> easily added to other interfaces.
>
> However, I can't seem to figure out a way to create a JPanel that
> displays
> the map functionality at all. It always requires use of an
> OpenMapFrame
> that is added to the MapHandler. the code is below. how can i make
> this
> into a working JPanel extension widget?
>
> public class TestFile {
>
> /** Creates a new instance of TestFile */
> public static void main(String args[]) {
>
> //BackgroundMap map = new BackgroundMap();
> EVMap ev = new EVMap();
>
> JFrame frame = new JFrame("Experiential Systems Group Map
> Interface");
>
> frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
>
> frame.getContentPane().add(ev);
>
> frame.setVisible(true);
>
> }
>
> }
>
> public class EVMap extends JPanel {
>
> public EVMap() {
>
> try {
>
> MapPanel mapPanel = new BasicMapPanel();
>
> // Get the default MapHandler the BasicMapPanel created.
> MapHandler mapHandler = mapPanel.getMapHandler();
>
> // Get the default MapBean that the BasicMapPanel created.
> MapBean mapBean = mapPanel.getMapBean();
>
> // Set the map's center
> mapBean.setCenter(new LatLonPoint(43.0f, -95.0f));
>
> // Set the map's scale 1:120 million
> mapBean.setScale(120000000f);
>
> mapHandler.add(new LayerHandler());
>
> mapHandler.add(new GraticuleLayer());
>
> ShapeLayer shapeLayer = new ShapeLayer();
>
> Properties shapeLayerProps = new Properties();
> shapeLayerProps.put("prettyName", "Political Solid");
> shapeLayerProps.put("lineColor", "000000");
> shapeLayerProps.put("fillColor", "BDDE83");
> shapeLayerProps.put("shapeFile",
> "C:/openmap-4.6/ESGData/world.shp");
> shapeLayer.setProperties(shapeLayerProps);
> shapeLayer.setVisible(true);
>
> mapHandler.add(shapeLayer);
>
> // Create the directional and zoom control tool
> OMToolSet omts = new OMToolSet();
> // Create an OpenMap toolbar
> ToolPanel toolBar = new ToolPanel();
>
> mapHandler.add(omts);
> mapHandler.add(toolBar);
> // Display the frame
> setVisible(true);
>
> } catch (MultipleSoloMapComponentException msmce) {
>
> }
> }
>
>
> --
> [To unsubscribe to this list send an email to "majdart@bbn.com"
> with the following text in the BODY of the message "unsubscribe
> openmap-users"]
>

--
[To unsubscribe to this list send an email to "majdart@bbn.com"
with the following text in the BODY of the message "unsubscribe openmap-users"]
Received on Thu Feb 19 12:39:04 2004

This archive was generated by hypermail 2.1.8 : Thu May 12 2005 - 07:18:37 EDT