Statistics
| Revision:

root / branches / v05 / extensions / extCatalogYNomenclator / src / es / gva / cit / gvsig / gazetteer / loaders / FeatureLoader.java @ 4392

History | View | Annotate | Download (5.25 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 org.cresques.cts.ProjectionPool;
48

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

    
58
import es.gva.cit.gazetteer.querys.Feature;
59
import es.gva.cit.gazetteer.querys.Query;
60
import es.gva.cit.gvsig.gazetteer.DeleteSearchesModule;
61

    
62

    
63
/**
64
 * This class is used to load a new feature like a layer in gvSIG
65
 * 
66
 * @author Jorge Piera Llodra (piera_jor@gva.es)
67
 */
68
public class FeatureLoader {     
69
    /**
70
     * It makes a zoom in gvSIG
71
     * @param
72
     * feature
73
     * @param
74
     * query
75
     * Query that contains advanced options to search and
76
     * to show the results
77
     * @return
78
     * true or false if fail
79
     */
80
    public boolean load(Feature feature,Query query) {
81
        
82
        addAndDrawLabel(feature,
83
                        query.getOptions().getAspect().isKeepOld(),
84
                        query.getOptions().getAspect().isPaintCurrent());
85
        
86
        if (query.getOptions().getAspect().isGoTo()){
87
            focusCenter(feature);
88
        }        
89
       
90
                return true;
91
        }    
92
    
93
    /**
94
     * This method focus the toponim in the center of the view 
95
     * @param feature
96
     * Feature that contains the coordinates
97
     */
98
    private void focusCenter(Feature feature){
99
        com.iver.cit.gvsig.gui.View activeView = 
100
                        (com.iver.cit.gvsig.gui.View) PluginServices.getMDIManager().getActiveView();
101
        
102
      if (activeView.getProjection().getDatum().toString().indexOf("European_Datum_1950") > 0){
103
                      activeView.getMapControl().getViewPort().setExtent(new Rectangle2D.Double(feature.getCoordinates().getX() - 5000,
104
                                      feature.getCoordinates().getY() - 5000,
105
                                      10000,
106
                                      10000));
107
              }else{//WGS_1984
108
                      activeView.getMapControl().getViewPort().setExtent(new Rectangle2D.Double(feature.getCoordinates().getX() - 0.05,
109
                  feature.getCoordinates().getY() - 0.05,
110
                  0.1,
111
                  0.1));
112
      }    
113
     
114
    } 
115
    
116
    /**
117
     * It adds a new Label to the current view
118
     * @param feature
119
     * To obtain the coordinates and the toponim name
120
     * @param isRemoveOldClicked
121
     * To remove or keep the old searches
122
     */
123
    private void addAndDrawLabel(Feature feature,boolean isRemoveOldClicked,boolean isMarkedPlaceClicked){
124
        com.iver.cit.gvsig.gui.View activeView = 
125
                        (com.iver.cit.gvsig.gui.View) PluginServices.getMDIManager().getActiveView();
126
        
127
        GraphicLayer lyr = activeView.getMapControl().getMapContext().getGraphicsLayer();
128
        //lyr.setProjection(ProjectionPool.get("EPSG:4326"));
129
        //lyr.setCoordTrans(ct);
130
        
131
        if (isRemoveOldClicked){
132
            lyr.clearAllGraphics();
133
        }
134
        
135
        if (isMarkedPlaceClicked){
136
                FSymbol theSymbol = new FSymbol(FConstant.SYMBOL_TYPE_TEXT); 
137
                theSymbol.setColor(Color.RED);
138
                theSymbol.setStyle(FConstant.SYMBOL_STYLE_MARKER_CIRCLE);
139
                theSymbol.setFontColor(Color.BLACK);
140
                theSymbol.setSizeInPixels(true);
141
                theSymbol.setSize(10);
142
                   
143
                int idSymbol = lyr.addSymbol(theSymbol);
144
        
145
                IGeometry geom = ShapeFactory.createPoint2D(new FPoint2D(feature.getCoordinates()));
146
                           
147
                FGraphicLabel theLabel = new FGraphicLabel(geom, idSymbol, feature.getName());
148
                lyr.addGraphic(theLabel);
149
                
150
                DeleteSearchesModule.setVisible();
151
                PluginServices.getMainFrame().enableControls();
152
            }
153
        
154
        activeView.getMapControl().drawGraphics();
155
        
156
        //This line could look stupid, but is necessary because grawGraphics does't
157
        //remove the old Graphics searched
158
        activeView.getMapControl().getViewPort().setExtent(activeView.getMapControl().getViewPort().getExtent());
159
    }
160
    
161
   
162
  }