Statistics
| Revision:

svn-gvsig-desktop / trunk / extensions / extCatalogYNomenclator / src / es / gva / cit / gvsig / gazetteer / loaders / FeatureLoader.java @ 3480

History | View | Annotate | Download (4.8 KB)

1
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
2
*
3
* Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
4
*
5
* This program is free software; you can redistribute it and/or
6
* modify it under the terms of the GNU General Public License
7
* as published by the Free Software Foundation; either version 2
8
* of the License, or (at your option) any later version.
9
*
10
* This program is distributed in the hope that it will be useful,
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
* GNU General Public License for more details.
14
*
15
* You should have received a copy of the GNU General Public License
16
* along with this program; if not, write to the Free Software
17
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
18
*
19
* For more information, contact:
20
*
21
*  Generalitat Valenciana
22
*   Conselleria d'Infraestructures i Transport
23
*   Av. Blasco Ib??ez, 50
24
*   46010 VALENCIA
25
*   SPAIN
26
*
27
*      +34 963862235
28
*   gvsig@gva.es
29
*      www.gvsig.gva.es
30
*
31
*    or
32
*
33
*   IVER T.I. S.A
34
*   Salamanca 50
35
*   46005 Valencia
36
*   Spain
37
*
38
*   +34 963163400
39
*   dac@iver.es
40
*/
41
package es.gva.cit.gvsig.gazetteer.loaders;
42

    
43

    
44
import java.awt.Color;
45
import java.awt.geom.Rectangle2D;
46

    
47
import com.iver.andami.PluginServices;
48
import com.iver.cit.gvsig.fmap.core.FPoint2D;
49
import com.iver.cit.gvsig.fmap.core.IGeometry;
50
import com.iver.cit.gvsig.fmap.core.ShapeFactory;
51
import com.iver.cit.gvsig.fmap.core.v02.FConstant;
52
import com.iver.cit.gvsig.fmap.core.v02.FSymbol;
53
import com.iver.cit.gvsig.fmap.layers.GraphicLayer;
54
import com.iver.cit.gvsig.fmap.rendering.FGraphicLabel;
55

    
56
import es.gva.cit.gazetteer.querys.Feature;
57
import es.gva.cit.gvsig.catalogClient.loaders.AbstractLoader;
58

    
59

    
60
/**
61
 * This class is used to load a new feature like a layer in gvSIG
62
 * 
63
 * @author Jorge Piera Llodra (piera_jor@gva.es)
64
 */
65
public class FeatureLoader extends AbstractLoader{     
66
    /**
67
     * It makes a zoom in gvSIG
68
     * @param
69
     * feature
70
     * @param focus
71
     * If the view must be focused in the toponim place
72
     * @param
73
     * removeOld
74
     * If the old searches have to be removed
75
     * @return
76
     * true or false if fail
77
     */
78
    public boolean load(Feature feature,boolean isGotoClicked,boolean isRemoveOldClicked) {
79
        
80
        addAndDrawLabel(feature,isRemoveOldClicked);
81
        
82
        if (isGotoClicked){
83
            focusCenter(feature);
84
        }        
85
       
86
                return true;
87
        }    
88
    
89
    /**
90
     * This method focus the toponim in the center of the view 
91
     * @param feature
92
     * Feature that contains the coordinates
93
     */
94
    private void focusCenter(Feature feature){
95
        com.iver.cit.gvsig.gui.View activeView = 
96
                        (com.iver.cit.gvsig.gui.View) PluginServices.getMDIManager().getActiveView();
97
               
98
        if ((feature.getCoordinates().getX() + feature.getCoordinates().getY()/2) < 100){
99
            activeView.getMapControl().getViewPort().setExtent(new Rectangle2D.Double(feature.getCoordinates().getX() - 0.05,
100
                feature.getCoordinates().getY() - 0.05,
101
                0.1,
102
                0.1));
103
        }else{            
104
            activeView.getMapControl().getViewPort().setExtent(new Rectangle2D.Double(feature.getCoordinates().getX() - 5000,
105
                feature.getCoordinates().getY() - 5000,
106
                10000,
107
                10000));
108
        }          
109
    } 
110
    
111
    /**
112
     * It adds a new Label to the current view
113
     * @param feature
114
     * To obtain the coordinates and the toponim name
115
     * @param isRemoveOldClicked
116
     * To remove or keep the old searches
117
     */
118
    private void addAndDrawLabel(Feature feature,boolean isRemoveOldClicked){
119
        com.iver.cit.gvsig.gui.View activeView = 
120
                        (com.iver.cit.gvsig.gui.View) PluginServices.getMDIManager().getActiveView();
121
        
122
        GraphicLayer lyr = activeView.getMapControl().getMapContext().getGraphicsLayer();
123
        if (isRemoveOldClicked){
124
            lyr.clearAllGraphics();
125
        }
126
        
127
        FSymbol theSymbol = new FSymbol(FConstant.SYMBOL_TYPE_TEXT); 
128
        theSymbol.setColor(Color.RED);
129
        theSymbol.setStyle(FConstant.SYMBOL_STYLE_MARKER_CIRCLE);
130
        theSymbol.setFontColor(Color.BLACK);
131
                   
132
        int idSymbol = lyr.addSymbol(theSymbol);
133
        
134
        IGeometry geom = ShapeFactory.createPoint2D(new FPoint2D(feature.getCoordinates()));
135
              
136
        FGraphicLabel theLabel = new FGraphicLabel(geom, idSymbol, feature.getName());
137
        lyr.addGraphic(theLabel);
138
       
139
        activeView.getMapControl().drawGraphics();
140
        
141
        //This line could look stupid, but is necessary because grawGraphics does't
142
        //remove the old Graphics searched
143
        activeView.getMapControl().getViewPort().setExtent(activeView.getMapControl().getViewPort().getExtent());
144
    }
145
}