Personal tools
gvSIG Desktop
gvSIG Desktop

Cached time 11/21/13 11:24:39 Clear cache and reload


Direct translation fron google translator

So far we've seen pieces that made up the various loose components that we needed to do our small viewfinder. We will see Now how can we join all those pieces and some more to create a simple viewer let us try everything without having to boot all gvSIG.

To do this, we focus on the org.gvsig.visor.main project. It can find a main class with everything you need to present our map and test our components.

Our program presents a window with a map and a few buttons to zoom or pan tools enable or our information tool on parcels of an apple.


It may be useful to consult the existing literature on the component MapControl This documentation is not has been updated with the changes that have made in that component in version 2 of gvSIG broad lines but continues to provide the same functionality and help better understand the tool.

To do this we will:

  • Create our swing component to display a map:

    mapControlManager = MapControlLocator.getMapControlManager();

    mapControl = mapControlManager.createJMapControlPanel();

  • We add the standard tools of zoom and pan, and we will set pan tool as the active tool:

      new Behavior[] {  
        new RectangleBehavior(new ZoomInListenerImpl(mapControl)),
        new PointBehavior(new ZoomOutRightButtonListener(mapControl))
      new MoveBehavior(
        new PanListenerImpl(mapControl)
  • Add the buttons and links to tools that just register on our map:

      new JButton(
        new AbstractAction("Zoom") {
          public void actionPerformed(ActionEvent e) {
  • We will create our layer of apples and add to the map:

    FLyrVect layer = (FLyrVect) MapContextLocator.getMapContextManager().createLayer(
  • And finally we will create our own tools and will record information on the map:

    PropertiesOfBlockListener listener = new PropertiesOfBlockListener();
    mapControl.addBehavior(SHOWINFO_TOOL_NAME, new PointBehavior(listener));

    This will register a point-like behavior, which associates a listener to perform particular actions that do not interest you. The listener code would be:

    public class PropertiesOfBlockListener extends AbstractPointListener {
      public void point(PointEvent event) throws BehaviorException {
        VisorSwingManager swingManager = VisorSwingLocator.getSwingManager();
        VisorBlock block;
        try {
          block = swingManager.getManager().getBlock(event.getMapPoint());
          if( block == null ) {
          JPanel panel = swingManager.createJVisorBlockPanel(block);
          ToolsLocator.getWindowManager().showWindow(panel, "Block information", WindowManager.MODE.TOOL);
        } catch (VisorException e) {
          // FIXME: Process exception
          throw new RuntimeException("Can't show properties of selected block.",e);

    Primarily derived from AbstractPointListener overwriting the point method that is called to perform the action associated with this tool. This method is limited to call our getBlocks method from the position on the map that was clicked, and if get some apple at that point our panel will be created to report this information in a window.

    What might be more remarkable when viewed in the parameter event for the coordinates of the point that was clicked is done through the getMapPoint method to ensure that returns us to map coordinates and not screen.

Powered by Plone CMS, the Open Source Content Management System

This site conforms to the following standards: