X

Geertjan's Blog

  • May 8, 2012

OpenMap & NetBeans Platform

Geertjan Wielenga
Product Manager

OpenMap is an open-source map technology. Integrated into the NetBeans Platform, you can click on a map (below one of the sample maps that comes with the OpenMap download is shown), and then use Lookup to publish items of interest for display in other windows, which can be undocked at startup (and the application can start in full screen mode) with tabs removed, creating the start of a typical mapping solution, such as used in air traffic control systems:

(My mouse isn't shown in the screenshot above, but it is on Ouagadougou in Burkina Faso. Hi Constantine and other NetBeans users in Ouagadougou!) 

Here's the code in the MapTopComponent, which is in the "editor" position above, with the tab removed, so that it covers the whole frame of the application: 

public final class MapTopComponent extends TopComponent {
private final InstanceContent ic = new InstanceContent();
public MapTopComponent() {
initComponents();
setName(Bundle.CTL_MapTopComponent());
setToolTipText(Bundle.HINT_MapTopComponent());
setLayout(new BorderLayout());
try {
//MapPanel:
MapPanel mapPanel = new BasicMapPanel();
//MapHandler:
MapHandler mapHandler = mapPanel.getMapHandler();
mapHandler.add(new LayerHandler());
mapHandler.add(this);
//MapBean:
MapBean mapBean = mapPanel.getMapBean();
mapBean.setScale(120000000f);
//Selection:
MouseDelegator mouseDelegator = new MouseDelegator();
mapHandler.add(mouseDelegator);
SelectMouseMode selectMouseMode = new SelectMouseMode();
mapHandler.add(selectMouseMode);
mouseDelegator.setActive(selectMouseMode);
//MapMouseListener:
final MyMapMouseListener myMapMouseListener = new MyMapMouseListener();
//ShapeLayer:
ShapeLayer shapeLayer = new ShapeLayer() {
@Override
public synchronized MapMouseListener getMapMouseListener() {
return myMapMouseListener;
}
};
//Properties:
Properties shapeLayerProps = new Properties();
shapeLayerProps.put("lineColor", "000000");
shapeLayerProps.put("fillColor", "BDDE83");
shapeLayerProps.put("shapeFile", "org/myatc/initializer/dcwpo-browse.shp");
shapeLayerProps.put("spatialIndex", "org/myatc/initializer/dcwpo-browse.ssx");
//Assign properties to ShapeLayer:
shapeLayer.setProperties(shapeLayerProps);
shapeLayer.setVisible(true);
//Assign ShapeLayer to MapHandler:
mapHandler.add(shapeLayer);
add(mapPanel.getMapBean(), BorderLayout.CENTER);
} catch (MultipleSoloMapComponentException msmce) {
}
associateLookup(new AbstractLookup(ic));
}
public class MyMapMouseListener implements MapMouseListener {
@Override
public String[] getMouseModeServiceList() {
return new String[]{SelectMouseMode.modeID};
}
@Override
public boolean mouseClicked(MouseEvent e) {
MapMouseEvent mme = (MapMouseEvent) e;
//Optionally:
//LatLonPoint latLonPoint = LatLonPoint.getFloat(mme.getLatLon());
//UTMPoint utmPoint = UTMPoint.LLtoUTM(latLonPoint);
//Publish something into Lookup:
ic.set(Collections.singleton(mme.getLatLon()), null);
return true;
}
@Override
public boolean mousePressed(MouseEvent e) {return true;}
@Override
public boolean mouseReleased(MouseEvent e) {return true;}
@Override
public void mouseEntered(MouseEvent e) {}
@Override
public void mouseExited(MouseEvent e) {}
@Override
public boolean mouseDragged(MouseEvent e) {return true;}
@Override
public boolean mouseMoved(MouseEvent e) {return true;}
@Override
public void mouseMoved() {}
}
...
...
...

Join the discussion

Comments ( 3 )
  • Ranga Thursday, May 31, 2012

    just one word - cool!


  • guest Thursday, June 28, 2012

    Greetings, I am interested in making the integration of OpenMap with NetBean platform, I tried to reproduce the guide published in this article but I have not managed to do, could give me the source of this example.


  • guest Wednesday, July 11, 2012

    woder if openmap can show the streets and streetname?


Please enter your name.Please provide a valid email address.Please enter a comment.CAPTCHA challenge response provided was incorrect. Please try again.