svn-gvsig-desktop / branches / v10 / extensions / extArcims / src / es / prodevelop / cit / gvsig / arcims / fmap / layers / FFeatureLyrArcIMS.java @ 20976
History | View | Annotate | Download (32.3 KB)
1 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
---|---|
2 |
*
|
3 |
* Copyright (C) 2006 Prodevelop 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 |
* Prodevelop Integraci?n de Tecnolog?as SL
|
34 |
* Conde Salvatierra de ?lava , 34-10
|
35 |
* 46004 Valencia
|
36 |
* Spain
|
37 |
*
|
38 |
* +34 963 510 612
|
39 |
* +34 963 510 968
|
40 |
* gis@prodevelop.es
|
41 |
* http://www.prodevelop.es
|
42 |
*/
|
43 |
package es.prodevelop.cit.gvsig.arcims.fmap.layers; |
44 |
|
45 |
import com.hardcode.driverManager.DriverLoadException; |
46 |
|
47 |
import com.hardcode.gdbms.engine.data.DataSource; |
48 |
|
49 |
import com.iver.andami.PluginServices; |
50 |
|
51 |
import com.iver.cit.gvsig.fmap.DriverException; |
52 |
import com.iver.cit.gvsig.fmap.MapContext; |
53 |
import com.iver.cit.gvsig.fmap.ViewPort; |
54 |
import com.iver.cit.gvsig.fmap.core.DefaultFeature; |
55 |
import com.iver.cit.gvsig.fmap.core.IGeometry; |
56 |
import com.iver.cit.gvsig.fmap.core.ISymbol; |
57 |
import com.iver.cit.gvsig.fmap.core.v02.FSymbol; |
58 |
import com.iver.cit.gvsig.fmap.crs.CRSFactory; |
59 |
import com.iver.cit.gvsig.fmap.drivers.DriverIOException; |
60 |
import com.iver.cit.gvsig.fmap.edition.VectorialEditableAdapter; |
61 |
import com.iver.cit.gvsig.fmap.layers.FBitSet; |
62 |
import com.iver.cit.gvsig.fmap.layers.FLyrText; |
63 |
import com.iver.cit.gvsig.fmap.layers.FLyrVect; |
64 |
import com.iver.cit.gvsig.fmap.layers.LegendListener; |
65 |
import com.iver.cit.gvsig.fmap.layers.XMLException; |
66 |
import com.iver.cit.gvsig.fmap.layers.layerOperations.InfoByPoint; |
67 |
import com.iver.cit.gvsig.fmap.operations.Cancel; |
68 |
import com.iver.cit.gvsig.fmap.rendering.Legend; |
69 |
import com.iver.cit.gvsig.fmap.rendering.LegendChangedEvent; |
70 |
import com.iver.cit.gvsig.fmap.rendering.VectorialLegend; |
71 |
|
72 |
import com.iver.utiles.XMLEntity; |
73 |
import com.iver.utiles.connections.ConnectionException; |
74 |
import com.iver.utiles.swing.threads.Cancellable; |
75 |
import com.iver.utiles.swing.threads.DefaultCancellableMonitorable; |
76 |
|
77 |
import es.prodevelop.cit.gvsig.arcims.fmap.drivers.ArcImsInMemoryAttsTableDriver; |
78 |
import es.prodevelop.cit.gvsig.arcims.fmap.drivers.ArcImsVectorialAdapter; |
79 |
import es.prodevelop.cit.gvsig.arcims.fmap.drivers.FMapFeatureArcImsDriver; |
80 |
|
81 |
import org.apache.log4j.Logger; |
82 |
|
83 |
import org.cresques.cts.ICoordTrans; |
84 |
import org.cresques.cts.IProjection; |
85 |
|
86 |
import org.gvsig.remoteClient.arcims.ArcImsClientP; |
87 |
import org.gvsig.remoteClient.arcims.ArcImsFeatureClient; |
88 |
import org.gvsig.remoteClient.arcims.ArcImsProtocolHandler; |
89 |
import org.gvsig.remoteClient.arcims.ArcImsVectStatus; |
90 |
import org.gvsig.remoteClient.arcims.exceptions.ArcImsException; |
91 |
import org.gvsig.remoteClient.arcims.utils.FieldInformation; |
92 |
import org.gvsig.remoteClient.arcims.utils.MyCancellable; |
93 |
import org.gvsig.remoteClient.arcims.utils.ServiceInfoTags; |
94 |
import org.gvsig.remoteClient.arcims.utils.ServiceInformation; |
95 |
import org.gvsig.remoteClient.arcims.utils.ServiceInformationLayerFeatures; |
96 |
import org.gvsig.remoteClient.utils.Utilities; |
97 |
|
98 |
import java.awt.Color; |
99 |
import java.awt.Graphics2D; |
100 |
import java.awt.Point; |
101 |
import java.awt.geom.AffineTransform; |
102 |
import java.awt.geom.NoninvertibleTransformException; |
103 |
import java.awt.geom.Point2D; |
104 |
import java.awt.geom.Rectangle2D; |
105 |
import java.awt.image.BufferedImage; |
106 |
|
107 |
import java.io.IOException; |
108 |
|
109 |
import java.net.MalformedURLException; |
110 |
import java.net.ProtocolException; |
111 |
import java.net.URL; |
112 |
|
113 |
import java.util.ArrayList; |
114 |
import java.util.HashMap; |
115 |
import java.util.Map; |
116 |
import java.util.Vector; |
117 |
|
118 |
import javax.print.attribute.PrintRequestAttributeSet; |
119 |
|
120 |
import javax.swing.ImageIcon; |
121 |
|
122 |
|
123 |
public class FFeatureLyrArcIMS extends FLyrVect implements InfoByPoint, |
124 |
LegendListener { |
125 |
// ClassifiableVectorial, Selectable, AlphanumericData, VectorialData,
|
126 |
// Labelable, SingleLayer, RandomVectorialData {
|
127 |
private static Logger logger = Logger.getLogger(FFeatureLyrArcIMS.class.getName()); |
128 |
private URL host; |
129 |
private String service; |
130 |
private String serviceType; |
131 |
private Rectangle2D fullExtent; |
132 |
private boolean firstLoad = true; |
133 |
private ArcImsVectStatus arcimsStatus = new ArcImsVectStatus(); |
134 |
private String SRS; |
135 |
private String srsAbrev; |
136 |
private String layerQuery; |
137 |
private VisualStatusArcIms visualStatus = new VisualStatusArcIms(); |
138 |
private int transparency = -1; |
139 |
private boolean arcImsTransparency = true; |
140 |
private int shapeType = 0; |
141 |
|
142 |
// private ArrayList initialColors = new ArrayList();
|
143 |
private ArrayList geometries; |
144 |
private MyCancellable myCanc;
|
145 |
|
146 |
// from ancestor FLyrVect:
|
147 |
// private VectorialAdapter source;
|
148 |
// private SelectableDataSource sds; --> is created like this --> new SelectableDataSource(source.getRecordSet())
|
149 |
public FFeatureLyrArcIMS(VectorialEditableAdapter vectAdapter) {
|
150 |
myCanc = new MyCancellable(new DefaultCancellableMonitorable()); |
151 |
|
152 |
setSource(vectAdapter); |
153 |
|
154 |
// try {
|
155 |
// // setRecordset(((FMapFeatureArcImsDriver) getSource().getDriver()).getRecordSet());
|
156 |
// shapeType = vectAdapter.getShapeType();
|
157 |
// // ((VectorialLegend) getLegend()).setShapeType(shapeType);
|
158 |
// } catch (Exception e) {
|
159 |
// logger.error("Unexpected error while getting shape type ", e);
|
160 |
// }
|
161 |
addLegendListener(this);
|
162 |
|
163 |
// loadInitialColors();
|
164 |
} |
165 |
|
166 |
public FFeatureLyrArcIMS() {
|
167 |
} |
168 |
|
169 |
public void setShapeType(int shpType) { |
170 |
shapeType = shpType; |
171 |
} |
172 |
|
173 |
public void setAdapter(VectorialEditableAdapter edapter) { |
174 |
setSource(edapter); |
175 |
|
176 |
try {
|
177 |
shapeType = edapter.getShapeType(); |
178 |
|
179 |
// ((VectorialLegend) getLegend()).setShapeType(shapeType);
|
180 |
} |
181 |
catch (DriverIOException e) {
|
182 |
logger.error("Unexpected error while getting shape type ", e);
|
183 |
} |
184 |
|
185 |
addLegendListener(this);
|
186 |
myCanc = new MyCancellable(new DefaultCancellableMonitorable()); |
187 |
|
188 |
// loadInitialColors();
|
189 |
} |
190 |
|
191 |
/*
|
192 |
public void setLegend(VectorialLegend r)
|
193 |
throws DriverException, FieldNotFoundException {
|
194 |
VectorialLegend oldLegend = legend;
|
195 |
legend = r;
|
196 |
|
197 |
try {
|
198 |
legend.setDataSource(getRecordset());
|
199 |
|
200 |
if (legend.getLabelField() != null) {
|
201 |
// sds.start();
|
202 |
// int idLabelField = getRecordset().getFieldIndexByName(legend.getLabelField());
|
203 |
createLabelLayer(sds);
|
204 |
// sds.stop();
|
205 |
}
|
206 |
else
|
207 |
removeLabels();
|
208 |
} catch (DriverException e) {
|
209 |
throw new DriverException(e);
|
210 |
} catch (FieldNotFoundException e) {
|
211 |
// TODO Auto-generated catch block
|
212 |
e.printStackTrace();
|
213 |
}
|
214 |
|
215 |
LegendChangedEvent e = LegendChangedEvent.createLegendChangedEvent(oldLegend, legend);
|
216 |
callLegendChanged(e);
|
217 |
}
|
218 |
*/
|
219 |
|
220 |
// private void loadInitialColors() {
|
221 |
// // Color[] cols =
|
222 |
// initialColors.add(new Color(179, 226, 205));
|
223 |
// initialColors.add(new Color(253, 205, 172));
|
224 |
// initialColors.add(new Color(203, 213, 232));
|
225 |
// initialColors.add(new Color(230, 245, 201));
|
226 |
// initialColors.add(new Color(141, 211, 199));
|
227 |
// initialColors.add(new Color(255, 255, 179));
|
228 |
// initialColors.add(new Color(190, 186, 218));
|
229 |
// initialColors.add(new Color(251, 128, 114));
|
230 |
// initialColors.add(new Color(128, 177, 211));
|
231 |
// }
|
232 |
|
233 |
/**
|
234 |
*
|
235 |
*/
|
236 |
public void draw(BufferedImage image, Graphics2D g, ViewPort viewPort, |
237 |
Cancellable cancel, double scale) throws DriverException { |
238 |
if (!isVisible()) {
|
239 |
return;
|
240 |
} |
241 |
|
242 |
if (!isWithinScale(scale)) {
|
243 |
return;
|
244 |
} |
245 |
|
246 |
// In case gvSIG calls the getVisualStatus method... (?)
|
247 |
visualStatus.width = viewPort.getImageWidth(); |
248 |
visualStatus.height = viewPort.getImageHeight(); |
249 |
visualStatus.minX = viewPort.getAdjustedExtent().getMinX(); |
250 |
visualStatus.minY = viewPort.getAdjustedExtent().getMinY(); |
251 |
visualStatus.maxX = viewPort.getAdjustedExtent().getMaxX(); |
252 |
visualStatus.maxY = viewPort.getAdjustedExtent().getMaxY(); |
253 |
|
254 |
IGeometry geom; |
255 |
IGeometry clonedGeom; |
256 |
ICoordTrans layerTransf = getCoordTrans(); |
257 |
Rectangle2D bBox = viewPort.getAdjustedExtent();
|
258 |
|
259 |
// CSV-WKT or LIBARCIMS
|
260 |
boolean test = false; |
261 |
|
262 |
if (test) {
|
263 |
// -------------------------- TEST START ---------------------------------
|
264 |
// geometries = ((FMapFeatureArcImsDriver) getSource().getDriver()).getGeometries();
|
265 |
for (int i = 0; i < geometries.size(); i++) { |
266 |
geom = (IGeometry) geometries.get(i); |
267 |
|
268 |
if (geom.intersects(bBox)) {
|
269 |
clonedGeom = geom.cloneGeometry(); |
270 |
|
271 |
ISymbol symbol = (ISymbol) ((VectorialLegend) getLegend()).getSymbol(i); |
272 |
|
273 |
// FSymbol symbol = ((VectorialLegend) getLegend()).getSymbol(i);
|
274 |
if (layerTransf != null) { |
275 |
geom.reProject(layerTransf); |
276 |
} |
277 |
|
278 |
clonedGeom.draw(g, viewPort, symbol); |
279 |
} |
280 |
} |
281 |
|
282 |
// -------------------------- TEST END ---------------------------------
|
283 |
} |
284 |
else {
|
285 |
// -------------------------- NOT TEST START ---------------------------------
|
286 |
arcimsStatus.setExtent(bBox); |
287 |
arcimsStatus.setHeight(viewPort.getImageHeight()); |
288 |
arcimsStatus.setWidth(viewPort.getImageWidth()); |
289 |
|
290 |
// one-item vector:
|
291 |
arcimsStatus.setLayerIds(Utilities.createVector(layerQuery, ",")); |
292 |
arcimsStatus.setServer(host.toString()); |
293 |
arcimsStatus.setService(service); |
294 |
arcimsStatus.setSrs(this.getProjection().getAbrev());
|
295 |
arcimsStatus.setTransparency(this.arcImsTransparency);
|
296 |
|
297 |
FMapFeatureArcImsDriver drv = (FMapFeatureArcImsDriver) getSource() |
298 |
.getDriver(); |
299 |
|
300 |
try {
|
301 |
// ********************************************
|
302 |
// first item in query must contain ID or #ALL#
|
303 |
// ********************************************
|
304 |
geometries = (ArrayList) drv.getMap(arcimsStatus);
|
305 |
} |
306 |
catch (ProtocolException e) { |
307 |
DriverException de = new DriverException(e.getMessage());
|
308 |
logger.error("While getting map (ArrayList of geometries) ", e);
|
309 |
throw de;
|
310 |
} |
311 |
catch (ArcImsException e) {
|
312 |
DriverException de = new DriverException(e.getMessage());
|
313 |
logger.error("While getting map (ArrayList of geometries) ", e);
|
314 |
throw de;
|
315 |
} |
316 |
catch (IOException e) { |
317 |
DriverException de = new DriverException(e.getMessage());
|
318 |
logger.error("While getting map (ArrayList of geometries) ", e);
|
319 |
throw de;
|
320 |
} |
321 |
|
322 |
for (int i = 0; i < geometries.size(); i++) { |
323 |
geom = (IGeometry) ((DefaultFeature) geometries.get(i)).getGeometry(); |
324 |
|
325 |
if (geom == null) { |
326 |
logger.error("Retrieved null geometry ");
|
327 |
} |
328 |
else {
|
329 |
clonedGeom = geom.cloneGeometry(); |
330 |
|
331 |
int ov_index = drv.getOverallIndex(i);
|
332 |
ISymbol symbol = (ISymbol) getSymbolOrSelected(ov_index, |
333 |
(FSymbol) ((VectorialLegend) getLegend()).getSymbol( |
334 |
ov_index)); |
335 |
|
336 |
// FSymbol symbol = getSymbolOrSelected(ov_index, ((VectorialLegend) getLegend()).getSymbol(ov_index));
|
337 |
if (layerTransf != null) { |
338 |
geom.reProject(layerTransf); |
339 |
} |
340 |
|
341 |
clonedGeom.draw(g, viewPort, symbol); |
342 |
} |
343 |
} |
344 |
|
345 |
FLyrText possibleLabels = getLayerText(); |
346 |
|
347 |
if (possibleLabels != null) { |
348 |
possibleLabels.createLabels(this);
|
349 |
possibleLabels.draw(image, g, viewPort, cancel, scale); |
350 |
} |
351 |
|
352 |
// -------------------------- NOT TEST END ---------------------------------
|
353 |
} |
354 |
} |
355 |
|
356 |
private FSymbol getSymbolOrSelected(int i, FSymbol symbol) { |
357 |
boolean sel = false; |
358 |
|
359 |
try {
|
360 |
sel = getRecordset().getSelectionSupport().isSelected(i); |
361 |
} |
362 |
catch (DriverException e) {
|
363 |
logger.error("While getting selection", e);
|
364 |
} |
365 |
|
366 |
if (sel) {
|
367 |
return new FSymbol(shapeType, Color.YELLOW); |
368 |
} |
369 |
else {
|
370 |
return symbol;
|
371 |
} |
372 |
} |
373 |
|
374 |
/**
|
375 |
*
|
376 |
*/
|
377 |
public void print(Graphics2D g, ViewPort viewPort, Cancellable cancel, |
378 |
double scale, PrintRequestAttributeSet properties) |
379 |
throws DriverException {
|
380 |
draw(null, g, viewPort, cancel, scale);
|
381 |
} |
382 |
|
383 |
/**
|
384 |
*
|
385 |
*/
|
386 |
public String queryByPoint(Point p) throws DriverException { |
387 |
Point2D screenCoords;
|
388 |
Point2D geoCoords;
|
389 |
double screenTol;
|
390 |
double geoTol;
|
391 |
|
392 |
screenCoords = new Point2D.Double(p.getX(), p.getY()); |
393 |
geoCoords = new Point2D.Double(p.getX(), p.getY()); |
394 |
|
395 |
AffineTransform af = getMapContext().getViewPort().getAffineTransform();
|
396 |
|
397 |
try {
|
398 |
af.inverseTransform(screenCoords, geoCoords); |
399 |
} |
400 |
catch (NoninvertibleTransformException e) { |
401 |
logger.error("Non invertible AffineTransform ", e);
|
402 |
} |
403 |
|
404 |
screenTol = 2.0;
|
405 |
geoTol = 1.0;
|
406 |
geoTol = screenTol / af.getScaleX(); |
407 |
|
408 |
FBitSet fbs = queryByPoint(geoCoords, geoTol); |
409 |
|
410 |
// this invoques the client to get attrs.
|
411 |
try {
|
412 |
((ArcImsVectorialAdapter) getSource()).requestFeatureAttributes(fbs); |
413 |
} |
414 |
catch (ArcImsException e) {
|
415 |
DriverException de = new DriverException(e.getMessage());
|
416 |
logger.error("While querying by point ", de);
|
417 |
throw de;
|
418 |
} |
419 |
|
420 |
String resp = getFormattedFieldsFromSetFeatures(fbs);
|
421 |
return resp;
|
422 |
} |
423 |
|
424 |
// TODO: move this to another class:
|
425 |
private String getFormattedFieldsFromSetFeatures(FBitSet fbs) { |
426 |
String r = "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>"; |
427 |
r = r + "<FeatureInfoResponse>";
|
428 |
r = r + "<LAYER ID=\"" + layerQuery + "\" NAME=\"" + getName() + "\">"; |
429 |
|
430 |
for (int i = fbs.nextSetBit(0); i >= 0; i = fbs.nextSetBit(i + 1)) { |
431 |
r = r + getFormattedFieldsFromFeature(i); |
432 |
} |
433 |
|
434 |
r = r + "</LAYER>";
|
435 |
r = r + "</FeatureInfoResponse>";
|
436 |
|
437 |
return r;
|
438 |
} |
439 |
|
440 |
// TODO: move this to another class:
|
441 |
private String getFormattedFieldsFromFeature(int j) { |
442 |
String r = "<FIELDS "; |
443 |
String fieldName;
|
444 |
String fieldValue;
|
445 |
DataSource ds = null; |
446 |
|
447 |
try {
|
448 |
ds = getSource().getRecordset(); |
449 |
} |
450 |
catch (DriverLoadException e1) {
|
451 |
logger.error("DriverException while getting field values. ", e1);
|
452 |
} |
453 |
|
454 |
int count;
|
455 |
|
456 |
try {
|
457 |
count = ds.getFieldCount(); |
458 |
|
459 |
for (int i = 0; i < count; i++) { |
460 |
fieldName = ds.getFieldName(i); |
461 |
fieldName = ArcImsInMemoryAttsTableDriver.replaceUnwantedCharacters(fieldName); |
462 |
|
463 |
fieldValue = restoreSpecialChars(ds.getFieldValue((long) j, i)
|
464 |
.toString()); |
465 |
logger.debug("fieldvalue = " + fieldValue);
|
466 |
r = r + " " + fieldName + "=" + "\"" + fieldValue + "\""; |
467 |
} |
468 |
|
469 |
// <FIELDS NOMBRE="LR-542" OBSERVACIO="" TIPO="CAUT3" _SHAPE_="[Geometry]" _ID_="1975" />
|
470 |
r = r + "/>";
|
471 |
} |
472 |
catch (com.hardcode.gdbms.engine.data.driver.DriverException e) {
|
473 |
logger.error("DriverException while getting field values. ", e);
|
474 |
} |
475 |
|
476 |
return r;
|
477 |
} |
478 |
|
479 |
private String restoreSpecialChars(String str) { |
480 |
/*
|
481 |
* < 60 3c, > 62 3e, & 38 26, " 34 22, ' 39 27
|
482 |
*/
|
483 |
String resp = str.replaceAll("\\x26", "&"); |
484 |
resp = resp.replaceAll("\\x3c", "<"); |
485 |
resp = resp.replaceAll("\\x3e", ">"); |
486 |
|
487 |
resp = resp.replaceAll("\\x22", """); |
488 |
resp = resp.replaceAll("\\x27", "'"); |
489 |
|
490 |
return resp;
|
491 |
} |
492 |
|
493 |
public void setInitialLegend() { |
494 |
FMapFeatureArcImsDriver drv = (FMapFeatureArcImsDriver) getSource() |
495 |
.getDriver(); |
496 |
|
497 |
//Try to get the legend from the service information
|
498 |
try {
|
499 |
Legend initialleg = drv.getClient() |
500 |
.getLegend((String) this.arcimsStatus.getLayerIds() |
501 |
.get(0));
|
502 |
|
503 |
if (initialleg != null) { |
504 |
setLegend((VectorialLegend) initialleg); |
505 |
} |
506 |
|
507 |
return;
|
508 |
} |
509 |
catch (Exception e) { |
510 |
logger.error("While setting initial legend ", e);
|
511 |
} |
512 |
|
513 |
// //If no legend is returned create a default legend
|
514 |
// if (drv.getShapeType() == FShape.MULTIPOINT) {
|
515 |
// SingleSymbolLegend initialleg = new SingleSymbolLegend();
|
516 |
// initialleg.setShapeType(drv.getShapeType());
|
517 |
// try {
|
518 |
// setLegend(initialleg);
|
519 |
// } catch (Exception e) {
|
520 |
// logger.error("While setting initial legend ", e);
|
521 |
// }
|
522 |
// return;
|
523 |
// }
|
524 |
//
|
525 |
// try {
|
526 |
// int colorind = (int) (System.currentTimeMillis() % ((long) initialColors
|
527 |
// .size()));
|
528 |
// FSymbol symb = new FSymbol(drv.getShapeType(),
|
529 |
// (Color) initialColors.get(colorind));
|
530 |
// SingleSymbolLegend initialleg = new SingleSymbolLegend(symb);
|
531 |
// initialleg.setShapeType(drv.getShapeType());
|
532 |
// setLegend(initialleg);
|
533 |
// } catch (FieldNotFoundException e) {
|
534 |
// logger.error("Whuile setting initial legend ", e);
|
535 |
// } catch (DriverException e) {
|
536 |
// logger.error("Whuile setting initial legend ", e);
|
537 |
// }
|
538 |
} |
539 |
|
540 |
// Classifiable
|
541 |
public int getShapeType() throws DriverException { |
542 |
FMapFeatureArcImsDriver drv = (FMapFeatureArcImsDriver) getSource().getDriver(); |
543 |
return drv.getShapeType();
|
544 |
} |
545 |
|
546 |
public void setServiceInformationInStatus(ServiceInformation si) { |
547 |
this.arcimsStatus.setServiceInformation(si);
|
548 |
} |
549 |
|
550 |
public ArcImsVectStatus getArcimsStatus() {
|
551 |
return arcimsStatus;
|
552 |
} |
553 |
|
554 |
public void setArcimsStatus(ArcImsVectStatus arcimsStatus) { |
555 |
this.arcimsStatus = arcimsStatus;
|
556 |
} |
557 |
|
558 |
public boolean isFirstLoad() { |
559 |
return firstLoad;
|
560 |
} |
561 |
|
562 |
public void setFirstLoad(boolean firstLoad) { |
563 |
this.firstLoad = firstLoad;
|
564 |
} |
565 |
|
566 |
public URL getHost() { |
567 |
return host;
|
568 |
} |
569 |
|
570 |
public void setHost(URL host) { |
571 |
this.host = host;
|
572 |
} |
573 |
|
574 |
public String getLayerQuery() { |
575 |
return layerQuery;
|
576 |
} |
577 |
|
578 |
public void setLayerQuery(String lQuery) { |
579 |
this.layerQuery = lQuery;
|
580 |
|
581 |
if (layerQuery.substring(0, 1).compareTo(",") == 0) { |
582 |
layerQuery = layerQuery.substring(1);
|
583 |
} |
584 |
} |
585 |
|
586 |
public String getService() { |
587 |
return service;
|
588 |
} |
589 |
|
590 |
public void setService(String service) { |
591 |
this.service = service;
|
592 |
} |
593 |
|
594 |
public String getServiceType() { |
595 |
return serviceType;
|
596 |
} |
597 |
|
598 |
public void setServiceType(String serviceType) { |
599 |
this.serviceType = serviceType;
|
600 |
} |
601 |
|
602 |
public String getSRS() { |
603 |
return SRS;
|
604 |
} |
605 |
|
606 |
public void setSRS(String srs) { |
607 |
SRS = srs; |
608 |
} |
609 |
|
610 |
public boolean getArcImsTransparency() { |
611 |
return arcImsTransparency;
|
612 |
} |
613 |
|
614 |
public void setArcImsTransparency(boolean arcImsTransparency) { |
615 |
this.arcImsTransparency = arcImsTransparency;
|
616 |
} |
617 |
|
618 |
public int getTransparency() { |
619 |
return transparency;
|
620 |
} |
621 |
|
622 |
public void setTransparency(int transparency) { |
623 |
this.transparency = transparency;
|
624 |
} |
625 |
|
626 |
public HashMap getProperties() { |
627 |
HashMap info = new HashMap(); |
628 |
String[] layerNames = getLayerQuery().split(","); |
629 |
Vector layers = new Vector(layerNames.length); |
630 |
FMapFeatureArcImsDriver drv = (FMapFeatureArcImsDriver) getSource() |
631 |
.getDriver(); |
632 |
|
633 |
try {
|
634 |
if (drv.connect(myCanc)) {
|
635 |
info.put("layerName", this.getName()); |
636 |
info.put("serverUrl", this.getHost()); |
637 |
info.put("serviceName", this.getService()); |
638 |
info.put("serviceType", this.getServiceType()); |
639 |
|
640 |
for (int i = 0; i < layerNames.length; i++) |
641 |
layers.add(layerNames[i]); |
642 |
|
643 |
info.put("layerIds", layers);
|
644 |
|
645 |
return info;
|
646 |
} |
647 |
} |
648 |
catch (Exception e) { |
649 |
logger.error("Error in FRasterLyrArcIMS.getProperties() ", e);
|
650 |
} |
651 |
|
652 |
return null; |
653 |
} |
654 |
|
655 |
public void setLayerIdsInStatus(Vector idsv) { |
656 |
arcimsStatus.setLayerIds(idsv); |
657 |
} |
658 |
|
659 |
public void setProjectionInStatus(String abbrev_srs) { |
660 |
arcimsStatus.setSrs(abbrev_srs); |
661 |
} |
662 |
|
663 |
public void setHostInStatus(URL url) { |
664 |
arcimsStatus.setServer(url.toString()); |
665 |
} |
666 |
|
667 |
public void setServiceInStatus(String srv) { |
668 |
arcimsStatus.setService(srv); |
669 |
} |
670 |
|
671 |
public void setSubfieldsInStatus() { |
672 |
String[] subfields = new String[2]; |
673 |
String id = (String) arcimsStatus.getLayerIds().get(0); |
674 |
ServiceInformationLayerFeatures silf = (ServiceInformationLayerFeatures) arcimsStatus.getServiceInfo() |
675 |
.getLayerById(id); |
676 |
FieldInformation fi = (FieldInformation) silf.getFieldInformationByType(FieldInformation.ID) |
677 |
.get(0);
|
678 |
subfields[1] = fi.getName();
|
679 |
fi = (FieldInformation) silf.getFieldInformationByType(FieldInformation.SHAPE) |
680 |
.get(0);
|
681 |
subfields[0] = fi.getName();
|
682 |
arcimsStatus.setSubfields(subfields); |
683 |
} |
684 |
|
685 |
public void legendChanged(LegendChangedEvent e) { |
686 |
MapContext fmap = getMapContext(); |
687 |
|
688 |
if (fmap != null) { |
689 |
fmap.invalidate(); |
690 |
} |
691 |
} |
692 |
|
693 |
public void setXMLEntity(XMLEntity xml) throws XMLException { |
694 |
try {
|
695 |
setHost(new URL(xml.getStringProperty("_host"))); |
696 |
} |
697 |
catch (MalformedURLException e) { |
698 |
logger.error("Bad url ", e);
|
699 |
} |
700 |
|
701 |
setService(xml.getStringProperty("_service"));
|
702 |
setLayerQuery(xml.getStringProperty("layerQuery"));
|
703 |
setSrsAbrev(xml.getStringProperty("srs_abrev"));
|
704 |
|
705 |
FMapFeatureArcImsDriver drv = new FMapFeatureArcImsDriver(host.toString(),
|
706 |
service, layerQuery); |
707 |
|
708 |
if (!(drv.connect(myCanc))) {
|
709 |
throw new XMLException(new DriverException( |
710 |
"Unable to connect to server"));
|
711 |
} |
712 |
|
713 |
drv.setLayer(this);
|
714 |
|
715 |
Vector ids = new Vector(); |
716 |
ids.add(getLayerQuery()); |
717 |
setLayerIdsInStatus(ids); |
718 |
|
719 |
ArcImsClientP cli = drv.getClient(); |
720 |
ServiceInformation si = cli.getServiceInformation(); |
721 |
arcimsStatus.setServiceInformation(si); |
722 |
|
723 |
String srs = getSrsAbrev();
|
724 |
arcimsStatus.setSrs(srs); |
725 |
|
726 |
if ((si.getFeaturecoordsys() == null) || |
727 |
(si.getFeaturecoordsys().equals(""))) {
|
728 |
si.setFeaturecoordsys(srs.substring( |
729 |
ServiceInfoTags.vINI_SRS.length()).trim()); |
730 |
logger.warn("Server provides no SRS. ");
|
731 |
} |
732 |
|
733 |
Rectangle2D fext = null; |
734 |
|
735 |
try {
|
736 |
fext = ((ArcImsFeatureClient) drv.getClient()).getLayerExtent(arcimsStatus); |
737 |
} |
738 |
catch (Exception e) { |
739 |
logger.error("While loading ArcIMS layer ", e);
|
740 |
} |
741 |
|
742 |
arcimsStatus.setExtent(fext); |
743 |
drv.setFullExtent(fext); |
744 |
|
745 |
setSubfieldsInStatus(); |
746 |
|
747 |
// drv.loadRecordSet();
|
748 |
ArcImsVectorialAdapter oldadapter = new ArcImsVectorialAdapter(drv);
|
749 |
VectorialEditableAdapter adapter = new VectorialEditableAdapter();
|
750 |
|
751 |
String recordsetName = xml.getStringProperty("recordset-name"); |
752 |
|
753 |
try {
|
754 |
adapter.setOriginalDataSource(drv.getRecordSet(recordsetName)); |
755 |
} |
756 |
catch (com.hardcode.gdbms.engine.data.driver.DriverException e) {
|
757 |
logger.error("While setting original data source ", e);
|
758 |
} |
759 |
|
760 |
adapter.setOriginalVectorialAdapter(oldadapter); |
761 |
|
762 |
setAdapter(adapter); |
763 |
|
764 |
drv.setAdapter(adapter); |
765 |
|
766 |
setInitialLegend(); |
767 |
|
768 |
try {
|
769 |
setRecordset(((FMapFeatureArcImsDriver) getSource().getDriver()).getRecordSet()); |
770 |
} |
771 |
catch (Exception e) { |
772 |
logger.error("While setting data source ", e);
|
773 |
} |
774 |
|
775 |
super.setXMLEntity(xml);
|
776 |
} |
777 |
|
778 |
public XMLEntity getXMLEntity() throws XMLException { |
779 |
XMLEntity resp = super.getXMLEntity();
|
780 |
|
781 |
// PluginServices.getMDIManager().addView(null);
|
782 |
resp.putProperty("srs_abrev", getMapContext().getProjection().getAbrev());
|
783 |
resp.putProperty("_host", host.toString());
|
784 |
resp.putProperty("_service", service);
|
785 |
resp.putProperty("layerQuery", layerQuery);
|
786 |
|
787 |
return resp;
|
788 |
} |
789 |
|
790 |
public String getSrsAbrev() { |
791 |
return srsAbrev;
|
792 |
} |
793 |
|
794 |
public void setSrsAbrev(String srsAbrev) { |
795 |
this.srsAbrev = srsAbrev;
|
796 |
} |
797 |
|
798 |
/**
|
799 |
* The extCatalogYNomenclator needs this creator.
|
800 |
*
|
801 |
* @param p a Map object with the following keys:
|
802 |
*
|
803 |
* (key, object type returned)
|
804 |
* ---------------------------
|
805 |
* "host", String (with or without the servlet path)
|
806 |
* "service_name", String (remote service name)
|
807 |
* "srs", String (coordinate system)
|
808 |
* "layer_id", String (*single* remote layer's ID)
|
809 |
* "layer_name", String (local layer name)
|
810 |
*
|
811 |
* @return a FRasterLyrArcIMS layer
|
812 |
* @throws ConnectionException
|
813 |
*/
|
814 |
|
815 |
/*
|
816 |
|
817 |
public FFeatureLyrArcIMS(Map m) throws ConnectionException {
|
818 |
|
819 |
String _host = (String) m.get("host");
|
820 |
|
821 |
try {
|
822 |
|
823 |
String _layer_id = (String) m.get("layer_id");
|
824 |
String _service_name = (String) m.get("service_name");
|
825 |
String _layer_name = (String) m.get("layer_name");
|
826 |
String _srs = (String) m.get("srs");
|
827 |
|
828 |
// ----------------------------------
|
829 |
|
830 |
URL _true_host = ArcImsProtocolHandler.getUrlWithServlet(new URL(_host));
|
831 |
IProjection _true_srs = CRSFactory.getCRS(_srs);
|
832 |
|
833 |
|
834 |
FMapFeatureArcImsDriver _drv = new FMapFeatureArcImsDriver(_true_host.toString(),
|
835 |
_service_name, _layer_id);
|
836 |
if (!(_drv.connect(myCanc))) throw new Exception();
|
837 |
ArcImsVectorialAdapter _oldadapter = new ArcImsVectorialAdapter(_drv);
|
838 |
VectorialEditableAdapter _adapter = new VectorialEditableAdapter();
|
839 |
_drv.setLayer(this);
|
840 |
|
841 |
ServiceInformation _si = _drv.getClient().getServiceInformation();
|
842 |
ServiceInformationLayerFeatures _silf = (ServiceInformationLayerFeatures)
|
843 |
_si.getLayerById(_layer_id);
|
844 |
|
845 |
setProjectionInStatus(_true_srs.getAbrev());
|
846 |
setHostInStatus(_true_host);
|
847 |
setServiceInStatus(_service_name);
|
848 |
|
849 |
String _units = _si.getMapunits();
|
850 |
int _theDpi = _si.getScreen_dpi();
|
851 |
long _scale;
|
852 |
if (_silf.getMaxscale()!=-1) {
|
853 |
_scale = LayerScaleData.getTrueScaleFromRelativeScaleAndMapUnits(
|
854 |
_silf.getMaxscale(), _units, _theDpi);
|
855 |
setMaxScale((double) _scale);
|
856 |
}
|
857 |
if (_silf.getMinscale()!=-1) {
|
858 |
_scale = LayerScaleData.getTrueScaleFromRelativeScaleAndMapUnits(
|
859 |
_silf.getMinscale(), _units, _theDpi);
|
860 |
setMinScale((double) _scale);
|
861 |
}
|
862 |
|
863 |
setServiceInformationInStatus(_si);
|
864 |
Vector _ids = new Vector(); _ids.add(_layer_id);
|
865 |
setLayerIdsInStatus((Vector) _ids.clone());
|
866 |
setSubfieldsInStatus();
|
867 |
|
868 |
setHost(_true_host);
|
869 |
setService(_service_name);
|
870 |
setServiceType(ServiceInfoTags.vFEATURESERVICE);
|
871 |
setTransparency(0);
|
872 |
setLayerQuery(_layer_id);
|
873 |
setProjection(_true_srs);
|
874 |
setName(_layer_name);
|
875 |
|
876 |
Rectangle2D _fext = ((ArcImsFeatureClient)
|
877 |
_drv.getClient()).getLayerExtent(getArcimsStatus());
|
878 |
_drv.setFullExtent(_fext);
|
879 |
// individualLayers[i].setF. setFullExtent(((ArcImsProtImageHandler) drv.getClient().getHandler()).getServiceExtent(srs, individualLayers[i].getArcimsStatus()));
|
880 |
|
881 |
// ------ -------------
|
882 |
_drv.setAdapter(_adapter);
|
883 |
// adapter.setRecordSet(drv.getRecordSet());
|
884 |
_adapter.setOriginalDataSource(_drv.getRecordSet());
|
885 |
_adapter.setOriginalVectorialAdapter(_oldadapter);
|
886 |
_drv.declareTable();
|
887 |
|
888 |
setSource(_adapter);
|
889 |
_adapter.setDriver(_drv);
|
890 |
|
891 |
getSource().setDriver(_drv);
|
892 |
setInitialLegend();
|
893 |
setShapeType(_adapter.getShapeType());
|
894 |
setRecordset(_drv.getRecordSet());
|
895 |
// ------ -------------
|
896 |
|
897 |
if ((_si.getFeaturecoordsys() == null) ||
|
898 |
(_si.getFeaturecoordsys().equals(""))) {
|
899 |
_si.setFeaturecoordsys(_true_srs.getAbrev().substring(ServiceInfoTags.vINI_SRS.length()).trim());
|
900 |
logger.warn("Server provides no SRS. ");
|
901 |
}
|
902 |
} catch (Exception e) {
|
903 |
throw new ConnectionException("Unable to connect to host " + _host, e);
|
904 |
}
|
905 |
}
|
906 |
|
907 |
*/
|
908 |
public ImageIcon getTocImageIcon() { |
909 |
ImageIcon resp = null; |
910 |
|
911 |
try {
|
912 |
resp = createImageIcon("images/esrilogo.png");
|
913 |
} |
914 |
catch (Exception ex) { |
915 |
} |
916 |
|
917 |
if (resp == null) { |
918 |
return super.getTocImageIcon(); |
919 |
} |
920 |
else {
|
921 |
return resp;
|
922 |
} |
923 |
} |
924 |
|
925 |
protected ImageIcon createImageIcon(String path) { |
926 |
java.net.URL imgURL = createExtensionUrl(path); |
927 |
|
928 |
if (imgURL != null) { |
929 |
return new ImageIcon(imgURL); |
930 |
} |
931 |
else {
|
932 |
logger.error("File not found: " + path);
|
933 |
|
934 |
return null; |
935 |
} |
936 |
} |
937 |
|
938 |
protected java.net.URL createExtensionUrl(String path) { |
939 |
return PluginServices.getPluginServices(
|
940 |
"es.prodevelop.cit.gvsig.arcims").getClassLoader().getResource(path);
|
941 |
|
942 |
// return getClass().getClassLoader().getResource(path);
|
943 |
} |
944 |
|
945 |
/**
|
946 |
* Keeps the image's height and width or the image's tiles' height and
|
947 |
* width, if any. These values are the same as the viewPort's height and
|
948 |
* width,
|
949 |
*/
|
950 |
private class VisualStatusArcIms { |
951 |
protected int width = 0; |
952 |
protected int height = 0; |
953 |
protected double minX = 0D; |
954 |
protected double minY = 0D; |
955 |
protected double maxX = 0D; |
956 |
protected double maxY = 0D; |
957 |
} |
958 |
} |