Personal tools
gvSIG Desktop
gvSIG Desktop

Cached time 11/21/13 16:31:32 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.

.. Tip::
    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.

.. _MapControl: Https://gvsig.org/web/reference_catalog/lookupObject?uuid=416853bc5bfba13f4c14bd1c71049170

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:
  
  .. code-block:: java

    mapControl.addBehavior(
      "zoom", 
      new Behavior[] {	
        new RectangleBehavior(new ZoomInListenerImpl(mapControl)),
        new PointBehavior(new ZoomOutRightButtonListener(mapControl))
      }
    );
    mapControl.addBehavior(
      "pan", 
      new MoveBehavior(
        new PanListenerImpl(mapControl)
      )
    );
    mapControl.setTool("pan");

- Add the buttons and links to tools that just
  register on our map:

  .. code-block:: java

    toolBar.add(
      new JButton(
        new AbstractAction("Zoom") {
          public void actionPerformed(ActionEvent e) {
            mapControl.setTool("zoom");
          }
        }
      )
    );

- We will create our layer of apples and add to the map:

  .. code-block:: java

    FLyrVect layer = (FLyrVect) MapContextLocator.getMapContextManager().createLayer(
      "Blocks", 
      manager.getBlocks()
    );
    mapControl.getMapContext().getLayers().addLayer(layer);

- And finally we will create our own tools and will record information
  on the map:
  
  .. code-block:: java

    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:

  .. code-block:: java
  
    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 ) {
            return;
          }
          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.

View source document


Powered by Plone CMS, the Open Source Content Management System

This site conforms to the following standards: