root / trunk / extensions / extCatalogYNomenclator / src / es / gva / cit / gvsig / gazetteer / loaders / FeatureLoader.java @ 3018
History | View | Annotate | Download (5.13 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 |
import java.awt.Graphics; |
44 |
import java.awt.Graphics2D; |
45 |
import java.awt.geom.Point2D; |
46 |
import java.awt.geom.Rectangle2D; |
47 |
import java.awt.image.BufferedImage; |
48 |
import java.io.File; |
49 |
import java.io.IOException; |
50 |
import java.net.MalformedURLException; |
51 |
import java.net.URL; |
52 |
import java.util.ArrayList; |
53 |
|
54 |
import javax.imageio.ImageIO; |
55 |
|
56 |
import org.cresques.cts.ICoordTrans; |
57 |
import org.cresques.cts.gt2.CoordSys; |
58 |
import org.cresques.cts.gt2.CoordTrans; |
59 |
import org.cresques.geo.Ellipsoid; |
60 |
import org.cresques.geo.Mercator; |
61 |
import org.cresques.geo.Projection; |
62 |
import org.cresques.geo.ViewPortData; |
63 |
|
64 |
import com.iver.andami.PluginServices; |
65 |
import com.iver.andami.plugins.Extension; |
66 |
import com.iver.andami.ui.mdiManager.ViewInfo; |
67 |
import com.iver.cit.gvsig.ProjectExtension; |
68 |
import com.iver.cit.gvsig.RasterizerLayer; |
69 |
import com.iver.cit.gvsig.fmap.DriverException; |
70 |
import com.iver.cit.gvsig.fmap.ViewPort; |
71 |
import com.iver.cit.gvsig.fmap.core.v02.FLabel; |
72 |
import com.iver.cit.gvsig.fmap.layers.FLayer; |
73 |
import com.iver.cit.gvsig.fmap.layers.FLyrText; |
74 |
import com.iver.cit.gvsig.fmap.operations.Cancellable; |
75 |
import com.iver.cit.gvsig.gui.layout.FLayoutDraw; |
76 |
import com.iver.cit.gvsig.project.Project; |
77 |
import com.iver.cit.gvsig.project.ProjectView; |
78 |
|
79 |
import es.gva.cit.gazetteer.querys.Feature; |
80 |
import es.gva.cit.gvsig.catalogClient.loaders.AbstractLoader; |
81 |
|
82 |
|
83 |
/**
|
84 |
* This class is used to load a new feature like a layer in gvSIG
|
85 |
*
|
86 |
* @author Jorge Piera Llodra (piera_jor@gva.es)
|
87 |
*/
|
88 |
public class FeatureLoader extends AbstractLoader{ |
89 |
|
90 |
/**
|
91 |
* It loads a new Layer into gvSIG
|
92 |
* @param feature
|
93 |
* @return
|
94 |
*/
|
95 |
public boolean load(Feature feature) { |
96 |
try {
|
97 |
FLayer flayer = createFeatureLayer(feature); |
98 |
if (flayer == null){ |
99 |
return false; |
100 |
}else{
|
101 |
addLayerToView(flayer); |
102 |
return true; |
103 |
} |
104 |
|
105 |
} catch (Exception e) { |
106 |
// TODO Auto-generated catch block
|
107 |
e.printStackTrace(); |
108 |
} |
109 |
return false; |
110 |
} |
111 |
/**
|
112 |
* It adds the new Feature layer into gvSIG
|
113 |
* @param feature
|
114 |
* Feature to load
|
115 |
* @return
|
116 |
* @throws DriverException
|
117 |
* @throws IOException
|
118 |
* @throws MalformedURLException
|
119 |
*/
|
120 |
private FLayer createFeatureLayer(Feature feature) throws DriverException, MalformedURLException, IOException { |
121 |
ProjectExtension pe = (ProjectExtension) PluginServices.getExtension(com.iver.cit.gvsig.ProjectExtension.class); |
122 |
Project p = pe.getProject(); |
123 |
ProjectView v = (ProjectView) p.getViews().get(0);
|
124 |
v.getMapContext().getViewPort().setExtent(new Rectangle2D.Double(feature.getCoordinates().getX() - 0.05, |
125 |
feature.getCoordinates().getY() - 0.05,
|
126 |
0.1,
|
127 |
0.1));
|
128 |
|
129 |
//ViewPort viewPort = new ViewPort(Mercator.getProjection(Ellipsoid.ed50));
|
130 |
|
131 |
/*
|
132 |
FLabel label = new FLabel(feature.getName(),feature.getCoordinates(),20,0);
|
133 |
|
134 |
ArrayList al = new ArrayList();
|
135 |
al.add(0,label);
|
136 |
|
137 |
FLyrText ft = new FLyrText(al);
|
138 |
ft.setName(feature.getName());
|
139 |
|
140 |
*/
|
141 |
//ICoordTrans ct = new CoordTrans((CoordSys) proj,
|
142 |
// (CoordSys) wi.getProjection());
|
143 |
|
144 |
//ft.setCoordTrans(ct);
|
145 |
|
146 |
|
147 |
/*
|
148 |
FLayoutDraw fld = new FLayoutDraw(new Layout());
|
149 |
Graphics2D g2d = null;
|
150 |
|
151 |
BufferedImage img = ImageIO.read(new URL("http://sercartlin:8080/geonetwork/srv/es/resources.getgraphover?id=78&fname=31es.jpg"));
|
152 |
|
153 |
BufferedImage image = new BufferedImage(100, 100, BufferedImage.TYPE_INT_RGB);
|
154 |
g2d = (Graphics2D) image.getGraphics();
|
155 |
|
156 |
fld.drawLayout(g2d, img);
|
157 |
*/
|
158 |
Cancellable cancel = new Cancellable() {
|
159 |
public boolean isCanceled() { |
160 |
return false; |
161 |
} |
162 |
}; |
163 |
|
164 |
//ft.draw(null,null,v.getMapContext().getViewPort(),cancel,1);
|
165 |
|
166 |
|
167 |
return null; |
168 |
|
169 |
} |
170 |
} |