Personal tools
You are here: Home Development Developers guide gvSIG GVSIG Views View MapOverview

A MapOverview is a subclass of the MapControl, with the particularity that is linked to the MapControl within the View document. By default it is on the lower left corner, and it allows for any kind of layer to be loaded onto it and for the management of its legend. It is usually used as a locator, showing some location layers and a rectangle that shows the visible rectangle of the associated MapControl.

The MapOverview is a listener of the MapControl, so that any change in the visualisation of an area makes the MapOverview to update and show the corresponding area shown by the MapControl.

The code responsible of this behaviour is:

public void setModel(MapContext model) {
    this.setMapContext(model);
    model.setProjection(m_MapAssoc.getMapContext().getProjection());
    m_MapAssoc.getMapContext().getViewPort().addViewPortListener(this);
    getMapContext().getViewPort().addViewPortListener(this);
}

On having associated the MapOverview model, this is added as a listener to the viewPort of the main MapControl.

public void extentChanged(ExtentEvent evExtent) {
    // We get the new extent of the associated FMap, so we draw our
    // rectangle to show the drawing area of the other map.
    repaint();
}

protected void paintComponent(Graphics g) {
    super.paintComponent(g);
        if ((m_MapAssoc.getMapContext().getViewPort().getExtent() != null) &&
                (getMapContext().getViewPort().getExtent() != null)) {
            if (first) {
                first = false;
                repaint();
                return;
            }
            image = new BufferedImage(this.getWidth(), this.getHeight(),
                        BufferedImage.TYPE_INT_ARGB);
            ViewPort vp = getMapContext().getViewPort();
            Rectangle2D extentView=vp.getAdjustedExtent();
            ViewPort vpOrig = m_MapAssoc.getMapContext().getViewPort();
            if (extent==null)
                extent=vpOrig.getAdjustedExtent();
            // We draw the extent of the associated map.
            Graphics2D g2 = (Graphics2D) image.getGraphics();
            g2.setTransform(vp.getAffineTransform());

            g2.setStroke(new BasicStroke((float) vp.getDist1pixel()));

            g2.setColor(Color.red);
            g2.draw(extent);
            g2.setColor(new Color(100,100,100,100));
            g2.fill(extent);
            // We draw the vertical and horizontal lines.
            Point2D pRightUp = vp.toMapPoint(getWidth(), 0);

            Line2D.Double linVert = new Line2D.Double(extent.getCenterX(),
                    extentView.getMinY(), extent.getCenterX(),
                    pRightUp.getY());
            Line2D.Double linHoriz = new Line2D.Double(extentView.getMinX(),
                    extent.getCenterY(), pRightUp.getX(),
                    extent.getCenterY());

            g2.setColor(Color.darkGray);
            g2.draw(linVert);
            g2.draw(linHoriz);
            g.drawImage(image,0,0,this);
            g2.setTransform(new AffineTransform());
            extent=null;
        }

}

MapOverview implements the ViewPortListener interface:

/**
 * <p>Defines the interface for an object that listens to changes in a view port.</p>
*/
public interface ViewPortListener {
    /**
     * <p>Called when the <i>extent</i> of the view port has changed.</p>
     *
     * @param e an extend event object
     */
    void extentChanged(ExtentEvent e);

    /**
     * <p>Called when the background color of the view port has changed.</p>
     * 
     * @param e a color event object
     */
    void backColorChanged(ColorEvent e);

    /**
     * <p>Called when the projection of the view port has changed.</p>
     *
     * @param e a projection event object
     */
    void projectionChanged(ProjectionEvent e);
}

So that it can respond to changes of the extent of the main MapControl.


Powered by Plone CMS, the Open Source Content Management System

This site conforms to the following standards: