svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.compat.cdc / org.gvsig.fmap.mapcontext / org.gvsig.fmap.mapcontext.api / src / main / java / org / gvsig / fmap / mapcontext / layers / vectorial / FLyrVect.java @ 42293
History | View | Annotate | Download (40 KB)
1 | 40559 | jjdelcerro | /**
|
---|---|---|---|
2 | * gvSIG. Desktop Geographic Information System.
|
||
3 | 40435 | jjdelcerro | *
|
4 | 40559 | jjdelcerro | * Copyright (C) 2007-2013 gvSIG Association.
|
5 | 40435 | jjdelcerro | *
|
6 | 42289 | jjdelcerro | * This program is free software; you can redistribute it and/or modify it under
|
7 | * the terms of the GNU General Public License as published by the Free Software
|
||
8 | * Foundation; either version 3 of the License, or (at your option) any later
|
||
9 | * version.
|
||
10 | 40435 | jjdelcerro | *
|
11 | 42289 | jjdelcerro | * This program is distributed in the hope that it will be useful, but WITHOUT
|
12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||
13 | * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
|
||
14 | * details.
|
||
15 | 40435 | jjdelcerro | *
|
16 | 42289 | jjdelcerro | * You should have received a copy of the GNU General Public License along with
|
17 | * this program; if not, write to the Free Software Foundation, Inc., 51
|
||
18 | * Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||
19 | 40435 | jjdelcerro | *
|
20 | 42289 | jjdelcerro | * For any additional information, do not hesitate to contact us at info AT
|
21 | * gvsig.com, or visit our website www.gvsig.com.
|
||
22 | 40435 | jjdelcerro | */
|
23 | package org.gvsig.fmap.mapcontext.layers.vectorial; |
||
24 | |||
25 | import java.awt.Graphics2D; |
||
26 | import java.awt.Point; |
||
27 | import java.awt.geom.AffineTransform; |
||
28 | import java.awt.geom.Point2D; |
||
29 | import java.awt.image.BufferedImage; |
||
30 | 42293 | jjdelcerro | import java.util.Iterator; |
31 | 40435 | jjdelcerro | import java.util.Set; |
32 | import java.util.TreeSet; |
||
33 | |||
34 | import org.cresques.cts.ICoordTrans; |
||
35 | import org.cresques.cts.IProjection; |
||
36 | import org.slf4j.LoggerFactory; |
||
37 | |||
38 | import org.gvsig.compat.print.PrintAttributes; |
||
39 | import org.gvsig.fmap.dal.DataStore; |
||
40 | import org.gvsig.fmap.dal.exception.DataException; |
||
41 | import org.gvsig.fmap.dal.exception.ReadException; |
||
42 | import org.gvsig.fmap.dal.feature.FeatureAttributeDescriptor; |
||
43 | import org.gvsig.fmap.dal.feature.FeatureQuery; |
||
44 | import org.gvsig.fmap.dal.feature.FeatureSet; |
||
45 | import org.gvsig.fmap.dal.feature.FeatureStore; |
||
46 | import org.gvsig.fmap.dal.feature.FeatureStoreNotification; |
||
47 | import org.gvsig.fmap.dal.feature.FeatureType; |
||
48 | import org.gvsig.fmap.dal.feature.exception.CreateGeometryException; |
||
49 | import org.gvsig.fmap.geom.Geometry; |
||
50 | import org.gvsig.fmap.geom.Geometry.SUBTYPES; |
||
51 | import org.gvsig.fmap.geom.Geometry.TYPES; |
||
52 | import org.gvsig.fmap.geom.GeometryLocator; |
||
53 | import org.gvsig.fmap.geom.GeometryManager; |
||
54 | import org.gvsig.fmap.geom.exception.CreateEnvelopeException; |
||
55 | import org.gvsig.fmap.geom.primitive.Circle; |
||
56 | import org.gvsig.fmap.geom.primitive.Envelope; |
||
57 | import org.gvsig.fmap.geom.type.GeometryType; |
||
58 | import org.gvsig.fmap.geom.type.GeometryTypeNotSupportedException; |
||
59 | import org.gvsig.fmap.geom.type.GeometryTypeNotValidException; |
||
60 | import org.gvsig.fmap.mapcontext.MapContextLocator; |
||
61 | import org.gvsig.fmap.mapcontext.MapContextManager; |
||
62 | import org.gvsig.fmap.mapcontext.ViewPort; |
||
63 | import org.gvsig.fmap.mapcontext.exceptions.LegendLayerException; |
||
64 | import org.gvsig.fmap.mapcontext.exceptions.LoadLayerException; |
||
65 | import org.gvsig.fmap.mapcontext.exceptions.ReloadLayerException; |
||
66 | import org.gvsig.fmap.mapcontext.exceptions.StartEditionLayerException; |
||
67 | import org.gvsig.fmap.mapcontext.layers.FLayer; |
||
68 | import org.gvsig.fmap.mapcontext.layers.FLyrDefault; |
||
69 | import org.gvsig.fmap.mapcontext.layers.LayerEvent; |
||
70 | import org.gvsig.fmap.mapcontext.layers.SpatialCache; |
||
71 | import org.gvsig.fmap.mapcontext.rendering.legend.ILegend; |
||
72 | import org.gvsig.fmap.mapcontext.rendering.legend.IVectorLegend; |
||
73 | import org.gvsig.fmap.mapcontext.rendering.legend.LegendException; |
||
74 | import org.gvsig.fmap.mapcontext.rendering.legend.events.FeatureDrawnNotification; |
||
75 | import org.gvsig.fmap.mapcontext.rendering.legend.events.LegendChangedEvent; |
||
76 | import org.gvsig.fmap.mapcontext.rendering.legend.events.LegendClearEvent; |
||
77 | import org.gvsig.fmap.mapcontext.rendering.legend.events.LegendContentsChangedListener; |
||
78 | import org.gvsig.fmap.mapcontext.rendering.legend.events.SymbolLegendEvent; |
||
79 | import org.gvsig.fmap.mapcontext.rendering.legend.styling.ILabelingStrategy; |
||
80 | import org.gvsig.fmap.mapcontext.rendering.symbols.CartographicSupport; |
||
81 | import org.gvsig.metadata.exceptions.MetadataException; |
||
82 | import org.gvsig.tools.ToolsLocator; |
||
83 | import org.gvsig.tools.dynobject.DynObjectSet; |
||
84 | import org.gvsig.tools.dynobject.DynStruct; |
||
85 | import org.gvsig.tools.exception.BaseException; |
||
86 | import org.gvsig.tools.locator.LocatorException; |
||
87 | import org.gvsig.tools.observer.Observable; |
||
88 | import org.gvsig.tools.observer.Observer; |
||
89 | import org.gvsig.tools.persistence.PersistenceManager; |
||
90 | import org.gvsig.tools.persistence.PersistentState; |
||
91 | import org.gvsig.tools.persistence.exception.PersistenceException; |
||
92 | import org.gvsig.tools.task.Cancellable; |
||
93 | 41840 | jjdelcerro | import org.gvsig.tools.util.Callable; |
94 | 40435 | jjdelcerro | |
95 | /**
|
||
96 | * Capa b?sica Vectorial.
|
||
97 | 42289 | jjdelcerro | *
|
98 | 40435 | jjdelcerro | */
|
99 | public class FLyrVect extends FLyrDefault implements VectorLayer, |
||
100 | 42289 | jjdelcerro | LegendContentsChangedListener, Observer {
|
101 | 40435 | jjdelcerro | |
102 | 42289 | jjdelcerro | final static private org.slf4j.Logger logger |
103 | = LoggerFactory.getLogger(FLyrVect.class); |
||
104 | private final GeometryManager geomManager |
||
105 | = GeometryLocator.getGeometryManager(); |
||
106 | 40435 | jjdelcerro | |
107 | 42289 | jjdelcerro | /**
|
108 | * Leyenda de la capa vectorial
|
||
109 | */
|
||
110 | 40435 | jjdelcerro | private IVectorLegend legend;
|
111 | private int typeShape = -1; |
||
112 | private FeatureStore featureStore = null; |
||
113 | private SpatialCache spatialCache = new SpatialCache(); |
||
114 | |||
115 | /**
|
||
116 | * An implementation of gvSIG spatial index
|
||
117 | */
|
||
118 | // protected ISpatialIndex spatialIndex = null;
|
||
119 | private IVectorLegend loadLegend = null; |
||
120 | |||
121 | private boolean isLabeled; |
||
122 | protected ILabelingStrategy strategy;
|
||
123 | // private ReprojectDefaultGeometry reprojectTransform;
|
||
124 | |||
125 | public FLyrVect() {
|
||
126 | super();
|
||
127 | } |
||
128 | 42289 | jjdelcerro | |
129 | public String getTocImageIcon() { |
||
130 | if (this.isAvailable()) { |
||
131 | 40435 | jjdelcerro | return MapContextLocator.getMapContextManager().getIconLayer(this.getDataStore()); |
132 | 42289 | jjdelcerro | } else {
|
133 | /*
|
||
134 | * data store can be be null,
|
||
135 | * for example, a layer not loaded from persistence
|
||
136 | */
|
||
137 | 40435 | jjdelcerro | return "layer-icon-unavailable"; |
138 | 42289 | jjdelcerro | } |
139 | 40435 | jjdelcerro | |
140 | 42289 | jjdelcerro | } |
141 | |||
142 | 40435 | jjdelcerro | /**
|
143 | * Devuelve el VectorialAdapater de la capa.
|
||
144 | 42289 | jjdelcerro | *
|
145 | 40435 | jjdelcerro | * @return VectorialAdapter.
|
146 | */
|
||
147 | public DataStore getDataStore() {
|
||
148 | if (!this.isAvailable()) { |
||
149 | return null; |
||
150 | } |
||
151 | return featureStore;
|
||
152 | } |
||
153 | 42289 | jjdelcerro | |
154 | 40435 | jjdelcerro | /**
|
155 | 42289 | jjdelcerro | * Asigna el data-store a la capa. Esta operacion no se deneria poder hacer
|
156 | * desde fuera de la clase.
|
||
157 | *
|
||
158 | 40435 | jjdelcerro | * @param dataStore
|
159 | * @throws LoadLayerException
|
||
160 | * @deprecated use {@link #bindToDataStore(DataStore)}
|
||
161 | */
|
||
162 | public void setDataStore(DataStore dataStore) throws LoadLayerException { |
||
163 | 42289 | jjdelcerro | bindToDataStore(dataStore); |
164 | 40435 | jjdelcerro | } |
165 | 42289 | jjdelcerro | |
166 | 40435 | jjdelcerro | /**
|
167 | * Enlaza la capa con el DataStore indicado.
|
||
168 | 42289 | jjdelcerro | *
|
169 | 40435 | jjdelcerro | * @param dataStore
|
170 | * @throws LoadLayerException
|
||
171 | */
|
||
172 | protected void bindToDataStore(DataStore dataStore) throws LoadLayerException { |
||
173 | if (this.featureStore != null && this.featureStore != dataStore) { |
||
174 | this.featureStore.deleteObserver(this); |
||
175 | } |
||
176 | |||
177 | featureStore = (FeatureStore) dataStore; |
||
178 | |||
179 | 42289 | jjdelcerro | MapContextManager mapContextManager |
180 | = MapContextLocator.getMapContextManager(); |
||
181 | |||
182 | 40435 | jjdelcerro | //Set the legend
|
183 | 42289 | jjdelcerro | IVectorLegend legend |
184 | = (IVectorLegend) mapContextManager.getLegend(dataStore); |
||
185 | 40435 | jjdelcerro | |
186 | if (legend == null) { |
||
187 | throw new LegendLayerException(this.getName()); |
||
188 | } |
||
189 | |||
190 | this.setLegend(legend);
|
||
191 | |||
192 | //Set the labeling strategy
|
||
193 | 42289 | jjdelcerro | ILabelingStrategy labeler |
194 | = (ILabelingStrategy) mapContextManager.getLabelingStrategy(dataStore); |
||
195 | 40435 | jjdelcerro | |
196 | if (labeler != null) { |
||
197 | labeler.setLayer(this);
|
||
198 | this.setLabelingStrategy(labeler);
|
||
199 | this.setIsLabeled(true); // TODO: ac? no s'hauria de detectar si t? |
||
200 | 42289 | jjdelcerro | // etiquetes?????
|
201 | 40435 | jjdelcerro | } |
202 | |||
203 | this.delegate(dataStore);
|
||
204 | |||
205 | dataStore.addObserver(this);
|
||
206 | |||
207 | ToolsLocator.getDisposableManager().bind(dataStore); |
||
208 | } |
||
209 | |||
210 | public Envelope getFullEnvelope() throws ReadException { |
||
211 | Envelope rAux; |
||
212 | try {
|
||
213 | rAux = getFeatureStore().getEnvelope(); |
||
214 | } catch (BaseException e) {
|
||
215 | throw new ReadException(getName(), e); |
||
216 | } |
||
217 | |||
218 | // Esto es para cuando se crea una capa nueva con el fullExtent de ancho
|
||
219 | // y alto 0.
|
||
220 | if (rAux == null || rAux.isEmpty() || rAux.getMaximum(0) - rAux.getMinimum(0) == 0 |
||
221 | 42289 | jjdelcerro | && rAux.getMaximum(1) - rAux.getMinimum(1) == 0) { |
222 | 40435 | jjdelcerro | try {
|
223 | 42289 | jjdelcerro | rAux |
224 | = geomManager.createEnvelope(0, 0, 90, 90, SUBTYPES.GEOM2D); |
||
225 | 40435 | jjdelcerro | } catch (CreateEnvelopeException e) {
|
226 | logger.error("Error creating the envelope", e);
|
||
227 | e.printStackTrace(); |
||
228 | } |
||
229 | } |
||
230 | // Si existe reproyecci?n, reproyectar el extent
|
||
231 | ICoordTrans ct = getCoordTrans(); |
||
232 | if (ct != null) { |
||
233 | 42289 | jjdelcerro | rAux = rAux.convert(ct); |
234 | 40435 | jjdelcerro | } |
235 | return rAux;
|
||
236 | |||
237 | } |
||
238 | |||
239 | /**
|
||
240 | * Draws using IFeatureIterator. This method will replace the old draw(...)
|
||
241 | * one.
|
||
242 | 42289 | jjdelcerro | *
|
243 | 40435 | jjdelcerro | * @autor jaume dominguez faus - jaume.dominguez@iver.es
|
244 | * @param image
|
||
245 | * @param g
|
||
246 | * @param viewPort
|
||
247 | * @param cancel
|
||
248 | * @param scale
|
||
249 | * @throws ReadDriverException
|
||
250 | */
|
||
251 | public void draw(BufferedImage image, |
||
252 | 42289 | jjdelcerro | Graphics2D g,
|
253 | ViewPort viewPort, |
||
254 | Cancellable cancel, |
||
255 | double scale) throws ReadException { |
||
256 | 40435 | jjdelcerro | |
257 | if (legend == null) { |
||
258 | return;
|
||
259 | } |
||
260 | |||
261 | if (!this.isWithinScale(scale)) { |
||
262 | return;
|
||
263 | } |
||
264 | if (cancel.isCanceled()) {
|
||
265 | return;
|
||
266 | } |
||
267 | |||
268 | if (spatialCache.isEnabled()) {
|
||
269 | spatialCache.clearAll(); |
||
270 | legend.addDrawingObserver(this);
|
||
271 | } |
||
272 | |||
273 | FeatureQuery featureQuery = null;
|
||
274 | try {
|
||
275 | 42289 | jjdelcerro | FeatureAttributeDescriptor featureAttributeDescriptor |
276 | = getFeatureStore().getDefaultFeatureType().getDefaultTimeAttribute(); |
||
277 | 40435 | jjdelcerro | |
278 | 42289 | jjdelcerro | if ((viewPort.getTime() != null) && (featureAttributeDescriptor != null)) { |
279 | 40435 | jjdelcerro | featureQuery = getFeatureStore().createFeatureQuery(); |
280 | 42289 | jjdelcerro | IntersectsTimeEvaluator intersectsTimeEvaluator |
281 | = new IntersectsTimeEvaluator(viewPort.getTime(), featureAttributeDescriptor.getName());
|
||
282 | 40435 | jjdelcerro | featureQuery.addFilter(intersectsTimeEvaluator); |
283 | } |
||
284 | } catch (DataException e1) {
|
||
285 | logger.error("Impossible to get the temporal filter", e1);
|
||
286 | } |
||
287 | |||
288 | try {
|
||
289 | 42289 | jjdelcerro | |
290 | 40435 | jjdelcerro | long tini = System.currentTimeMillis(); |
291 | 42289 | jjdelcerro | |
292 | 40435 | jjdelcerro | legend.draw(image, |
293 | 42289 | jjdelcerro | g, |
294 | viewPort, |
||
295 | cancel, |
||
296 | scale, |
||
297 | null,
|
||
298 | getCoordTrans(), |
||
299 | getFeatureStore(), |
||
300 | featureQuery); |
||
301 | 40435 | jjdelcerro | |
302 | 42289 | jjdelcerro | logger.debug("Layer " + this.getName() + " drawn in " |
303 | + (System.currentTimeMillis() - tini) + " milliseconds."); |
||
304 | |||
305 | 40435 | jjdelcerro | } catch (LegendException e) {
|
306 | this.setVisible(false); |
||
307 | this.setActive(false); |
||
308 | throw new ReadException(getName(), e); |
||
309 | } finally {
|
||
310 | if (spatialCache.isEnabled()) {
|
||
311 | legend.deleteDrawingObserver(this);
|
||
312 | } |
||
313 | } |
||
314 | } |
||
315 | |||
316 | public void print(Graphics2D g, |
||
317 | 42289 | jjdelcerro | ViewPort viewPort, |
318 | Cancellable cancel, |
||
319 | double scale,
|
||
320 | PrintAttributes properties) throws ReadException {
|
||
321 | 40435 | jjdelcerro | if (!this.isWithinScale(scale)) { |
322 | return;
|
||
323 | } |
||
324 | if (cancel.isCanceled()) {
|
||
325 | return;
|
||
326 | } |
||
327 | |||
328 | try {
|
||
329 | legend.print(g, |
||
330 | 42289 | jjdelcerro | viewPort, |
331 | cancel, |
||
332 | scale, |
||
333 | null,
|
||
334 | getCoordTrans(), |
||
335 | getFeatureStore(), |
||
336 | null,
|
||
337 | properties); |
||
338 | 40435 | jjdelcerro | |
339 | } catch (LegendException e) {
|
||
340 | this.setVisible(false); |
||
341 | this.setActive(false); |
||
342 | throw new ReadException(getName(), e); |
||
343 | } |
||
344 | } |
||
345 | |||
346 | public void setLegend(IVectorLegend legend) throws LegendLayerException { |
||
347 | if (this.legend == legend) { |
||
348 | return;
|
||
349 | } |
||
350 | if (this.legend != null && this.legend.equals(legend)) { |
||
351 | return;
|
||
352 | } |
||
353 | IVectorLegend oldLegend = this.legend;
|
||
354 | this.legend = legend;
|
||
355 | if (oldLegend != null) { |
||
356 | oldLegend.removeLegendListener(this);
|
||
357 | oldLegend.deleteDrawingObserver(this);
|
||
358 | } |
||
359 | if (legend != null) { |
||
360 | this.legend.addDrawingObserver(this); |
||
361 | this.legend.addLegendListener(this); |
||
362 | } |
||
363 | 42289 | jjdelcerro | LegendChangedEvent e |
364 | = LegendChangedEvent.createLegendChangedEvent(oldLegend, this.legend);
|
||
365 | 40435 | jjdelcerro | e.setLayer(this);
|
366 | updateDrawVersion(); |
||
367 | callLegendChanged(e); |
||
368 | } |
||
369 | |||
370 | /**
|
||
371 | * Devuelve la Leyenda de la capa.
|
||
372 | 42289 | jjdelcerro | *
|
373 | 40435 | jjdelcerro | * @return Leyenda.
|
374 | */
|
||
375 | public ILegend getLegend() {
|
||
376 | return legend;
|
||
377 | } |
||
378 | |||
379 | public int getShapeType() throws ReadException { |
||
380 | 42289 | jjdelcerro | if (typeShape == -1) { |
381 | FeatureType featureType = null;
|
||
382 | try {
|
||
383 | if (getDataStore() != null) { |
||
384 | featureType |
||
385 | = (((FeatureStore) getDataStore()).getDefaultFeatureType()); |
||
386 | } |
||
387 | } catch (DataException e) {
|
||
388 | throw new ReadException(getName(), e); |
||
389 | } |
||
390 | if (featureType != null) { |
||
391 | int indexGeom = featureType.getDefaultGeometryAttributeIndex();
|
||
392 | typeShape |
||
393 | = featureType.getAttributeDescriptor(indexGeom).getGeometryType(); |
||
394 | } |
||
395 | } |
||
396 | return typeShape;
|
||
397 | 40435 | jjdelcerro | } |
398 | |||
399 | /**
|
||
400 | * Returns the layer's geometry type
|
||
401 | 42289 | jjdelcerro | *
|
402 | 40435 | jjdelcerro | * @return the geometry type
|
403 | 42289 | jjdelcerro | *
|
404 | * @throws ReadException if there is an error getting the geometry type
|
||
405 | 40435 | jjdelcerro | */
|
406 | public GeometryType getGeometryType() throws ReadException { |
||
407 | FeatureType featureType = null;
|
||
408 | try {
|
||
409 | if (getDataStore() != null) { |
||
410 | 42289 | jjdelcerro | featureType |
411 | = (((FeatureStore) getDataStore()).getDefaultFeatureType()); |
||
412 | 40435 | jjdelcerro | } |
413 | } catch (DataException e) {
|
||
414 | throw new ReadException(getName(), e); |
||
415 | } |
||
416 | return featureType == null ? null : featureType |
||
417 | 42289 | jjdelcerro | .getDefaultGeometryAttribute().getGeomType(); |
418 | 40435 | jjdelcerro | } |
419 | |||
420 | public void saveToState(PersistentState state) throws PersistenceException { |
||
421 | |||
422 | 41807 | jjdelcerro | FeatureStore featureStore = null;
|
423 | |||
424 | 42289 | jjdelcerro | if (!this.isAvailable()) { |
425 | 41807 | jjdelcerro | logger.info("The '" + this.getName() + "' layer is not available, it will persist not."); |
426 | 40435 | jjdelcerro | return;
|
427 | } |
||
428 | 42289 | jjdelcerro | |
429 | 41807 | jjdelcerro | try {
|
430 | super.saveToState(state);
|
||
431 | 40435 | jjdelcerro | |
432 | 42289 | jjdelcerro | if (getLegend() != null) { |
433 | 41807 | jjdelcerro | state.set("legend", getLegend());
|
434 | } |
||
435 | 40435 | jjdelcerro | |
436 | 41807 | jjdelcerro | featureStore = getFeatureStore(); |
437 | 40435 | jjdelcerro | |
438 | 42289 | jjdelcerro | if (featureStore != null) { |
439 | 41807 | jjdelcerro | state.set("featureStore", featureStore);
|
440 | } |
||
441 | 40435 | jjdelcerro | |
442 | 41807 | jjdelcerro | state.set("isLabeled", isLabeled);
|
443 | 40435 | jjdelcerro | |
444 | 42289 | jjdelcerro | if (strategy != null) { |
445 | 41807 | jjdelcerro | state.set("labelingStrategy", strategy);
|
446 | } |
||
447 | 40435 | jjdelcerro | |
448 | 42289 | jjdelcerro | if (getLinkProperties() != null) { |
449 | 41807 | jjdelcerro | state.set("linkProperties", getLinkProperties());
|
450 | } |
||
451 | 40435 | jjdelcerro | |
452 | 41807 | jjdelcerro | state.set("typeShape", typeShape);
|
453 | } catch (PersistenceException ex) {
|
||
454 | logger.warn("Can't persist to state the layer '" + this.getName() + "'.", ex); |
||
455 | throw ex;
|
||
456 | } catch (RuntimeException ex) { |
||
457 | logger.warn("Can't persist to state the layer '" + this.getName() + "'.", ex); |
||
458 | throw ex;
|
||
459 | 40435 | jjdelcerro | } |
460 | |||
461 | } |
||
462 | |||
463 | public void loadFromState(PersistentState state) throws PersistenceException { |
||
464 | |||
465 | DataStore store = null;
|
||
466 | 41807 | jjdelcerro | IVectorLegend vectorLegend = null;
|
467 | ILabelingStrategy labelingStrategy = null;
|
||
468 | Boolean isLabeled = Boolean.FALSE; |
||
469 | 41146 | jldominguez | |
470 | 40435 | jjdelcerro | try {
|
471 | 42289 | jjdelcerro | super.loadFromState(state);
|
472 | store = (DataStore) state.get("featureStore");
|
||
473 | 40435 | jjdelcerro | |
474 | 41807 | jjdelcerro | try {
|
475 | this.bindToDataStore(store);
|
||
476 | } catch (LoadLayerException e) {
|
||
477 | 42289 | jjdelcerro | throw new PersistenceException("Can't bind layer '" + this.getName() + "' to store '" + store.getFullName() + "'.", e); |
478 | 41807 | jjdelcerro | } |
479 | 40435 | jjdelcerro | |
480 | 41807 | jjdelcerro | vectorLegend = (IVectorLegend) state.get("legend");
|
481 | |||
482 | try {
|
||
483 | this.setLegend(vectorLegend);
|
||
484 | } catch (LegendLayerException e) {
|
||
485 | throw new PersistenceException("Can't set vector legend to the layer.", e); |
||
486 | 40435 | jjdelcerro | } |
487 | |||
488 | 41807 | jjdelcerro | try {
|
489 | isLabeled = (Boolean) state.get("isLabeled"); |
||
490 | 42289 | jjdelcerro | if (isLabeled.booleanValue()) {
|
491 | 41807 | jjdelcerro | labelingStrategy = (ILabelingStrategy) state.get("labelingStrategy");
|
492 | } |
||
493 | } catch (Exception ex) { |
||
494 | throw new PersistenceException("Can't load labeling strategi from persistent state.", |
||
495 | ex); |
||
496 | } |
||
497 | 40435 | jjdelcerro | |
498 | 42289 | jjdelcerro | if (isLabeled.booleanValue()) {
|
499 | 41807 | jjdelcerro | this.setIsLabeled(true); |
500 | this.setLabelingStrategy(labelingStrategy);
|
||
501 | } else {
|
||
502 | this.setIsLabeled(false); |
||
503 | this.setLabelingStrategy(null); |
||
504 | } |
||
505 | 40435 | jjdelcerro | |
506 | 41807 | jjdelcerro | typeShape = state.getInt("typeShape");
|
507 | |||
508 | } catch (Throwable e) { |
||
509 | 42289 | jjdelcerro | String storeName = (store == null) ? "unknow" : store.getFullName(); |
510 | logger.warn("can't load layer '" + this.getName() + "' (store=" + storeName + ") from persisted state.", e); |
||
511 | 41807 | jjdelcerro | this.setAvailable(false); |
512 | return;
|
||
513 | } |
||
514 | |||
515 | 40435 | jjdelcerro | } |
516 | |||
517 | /**
|
||
518 | * Sobreimplementaci?n del m?todo toString para que las bases de datos
|
||
519 | * identifiquen la capa.
|
||
520 | 42289 | jjdelcerro | *
|
521 | 40435 | jjdelcerro | * @return DOCUMENT ME!
|
522 | */
|
||
523 | public String toString() { |
||
524 | /*
|
||
525 | * Se usa internamente para que la parte de datos identifique de forma
|
||
526 | * un?voca las tablas
|
||
527 | */
|
||
528 | String ret = super.toString(); |
||
529 | |||
530 | return "layer" + ret.substring(ret.indexOf('@') + 1); |
||
531 | } |
||
532 | |||
533 | public boolean isEditing() { |
||
534 | FeatureStore fs = getFeatureStore(); |
||
535 | if (fs == null) { |
||
536 | /*
|
||
537 | * This happens when layer is not available, for example,
|
||
538 | * it was not possible to load from persistence
|
||
539 | */
|
||
540 | return false; |
||
541 | } else {
|
||
542 | return fs.isEditing();
|
||
543 | } |
||
544 | } |
||
545 | 42289 | jjdelcerro | |
546 | 40435 | jjdelcerro | public void setEditing(boolean b) throws StartEditionLayerException { |
547 | 42289 | jjdelcerro | |
548 | 40435 | jjdelcerro | try {
|
549 | throw new RuntimeException(); |
||
550 | } catch (Throwable th) { |
||
551 | logger.info("This method is deprecated. ", th);
|
||
552 | } |
||
553 | 42289 | jjdelcerro | |
554 | 40435 | jjdelcerro | if (b == super.isEditing()) { |
555 | return;
|
||
556 | } |
||
557 | 42289 | jjdelcerro | |
558 | 40435 | jjdelcerro | super.setEditing(b);
|
559 | FeatureStore fs = getFeatureStore(); |
||
560 | if (b) {
|
||
561 | try {
|
||
562 | fs.edit(); |
||
563 | } catch (DataException e) {
|
||
564 | throw new StartEditionLayerException(getName(), e); |
||
565 | } |
||
566 | } |
||
567 | setSpatialCacheEnabled(b); |
||
568 | callEditionChanged(LayerEvent.createEditionChangedEvent(this, "edition")); |
||
569 | } |
||
570 | |||
571 | /**
|
||
572 | * @deprecated Use {@link #getSpatialCache()}
|
||
573 | */
|
||
574 | public void clearSpatialCache() { |
||
575 | spatialCache.clearAll(); |
||
576 | } |
||
577 | |||
578 | /**
|
||
579 | * @deprecated Use {@link #getSpatialCache()}
|
||
580 | */
|
||
581 | public boolean isSpatialCacheEnabled() { |
||
582 | return spatialCache.isEnabled();
|
||
583 | } |
||
584 | |||
585 | /**
|
||
586 | * @deprecated Use {@link #getSpatialCache()}
|
||
587 | */
|
||
588 | public void setSpatialCacheEnabled(boolean spatialCacheEnabled) { |
||
589 | spatialCache.setEnabled(spatialCacheEnabled); |
||
590 | } |
||
591 | |||
592 | public SpatialCache getSpatialCache() {
|
||
593 | return spatialCache;
|
||
594 | } |
||
595 | |||
596 | /**
|
||
597 | * Siempre es un numero mayor de 1000
|
||
598 | 42289 | jjdelcerro | *
|
599 | 40435 | jjdelcerro | * @param maxFeatures
|
600 | */
|
||
601 | public void setMaxFeaturesInEditionCache(int maxFeatures) { |
||
602 | if (maxFeatures > spatialCache.getMaxFeatures()) {
|
||
603 | spatialCache.setMaxFeatures(maxFeatures); |
||
604 | } |
||
605 | |||
606 | } |
||
607 | |||
608 | /**
|
||
609 | 42289 | jjdelcerro | * This method returns a boolean that is used by the FPopMenu to make
|
610 | * visible the properties menu or not. It is visible by default, and if a
|
||
611 | * later don't have to show this menu only has to override this method.
|
||
612 | *
|
||
613 | * @return If the properties menu is visible (or not)
|
||
614 | 40435 | jjdelcerro | */
|
615 | public boolean isPropertiesMenuVisible() { |
||
616 | return true; |
||
617 | } |
||
618 | |||
619 | public void reload() throws ReloadLayerException { |
||
620 | super.reload();
|
||
621 | try {
|
||
622 | getFeatureStore().refresh(); |
||
623 | } catch (Exception e) { |
||
624 | throw new ReloadLayerException(getName(), e); |
||
625 | } |
||
626 | } |
||
627 | |||
628 | protected void setLoadSelection(Object xml) { |
||
629 | // this.loadSelection = xml;
|
||
630 | } |
||
631 | |||
632 | protected void setLoadLegend(IVectorLegend legend) { |
||
633 | this.loadLegend = legend;
|
||
634 | } |
||
635 | |||
636 | protected void putLoadSelection() { |
||
637 | // if (this.loadSelection == null) return;
|
||
638 | // try {
|
||
639 | // this.getRecordset().getSelectionSupport().setXMLEntity(this.loadSelection);
|
||
640 | // } catch (ReadDriverException e) {
|
||
641 | // throw new XMLException(e);
|
||
642 | // }
|
||
643 | // this.loadSelection = null;
|
||
644 | |||
645 | } |
||
646 | |||
647 | protected void putLoadLegend() throws LegendLayerException { |
||
648 | if (this.loadLegend == null) { |
||
649 | return;
|
||
650 | } |
||
651 | this.setLegend(this.loadLegend); |
||
652 | this.loadLegend = null; |
||
653 | } |
||
654 | |||
655 | protected void cleanLoadOptions() { |
||
656 | this.loadLegend = null; |
||
657 | } |
||
658 | |||
659 | public boolean isWritable() { |
||
660 | return getFeatureStore().allowWrite();
|
||
661 | } |
||
662 | |||
663 | public FLayer cloneLayer() throws Exception { |
||
664 | FLyrVect clonedLayer = new FLyrVect();
|
||
665 | clonedLayer.bindToDataStore(getDataStore()); |
||
666 | // if (isJoined()) {
|
||
667 | // clonedLayer.setIsJoined(true);
|
||
668 | // }
|
||
669 | clonedLayer.setVisible(isVisible()); |
||
670 | // clonedLayer.setISpatialIndex(getISpatialIndex());
|
||
671 | clonedLayer.setName(getName()); |
||
672 | clonedLayer.setCoordTrans(getCoordTrans()); |
||
673 | |||
674 | clonedLayer.setLegend((IVectorLegend) getLegend().cloneLegend()); |
||
675 | |||
676 | clonedLayer.setIsLabeled(isLabeled()); |
||
677 | ILabelingStrategy labelingStrategy = getLabelingStrategy(); |
||
678 | if (labelingStrategy != null) { |
||
679 | clonedLayer.setLabelingStrategy(labelingStrategy); |
||
680 | } |
||
681 | |||
682 | return clonedLayer;
|
||
683 | } |
||
684 | |||
685 | protected boolean isOnePoint(AffineTransform graphicsTransform, |
||
686 | 42289 | jjdelcerro | ViewPort viewPort, |
687 | double dpi,
|
||
688 | CartographicSupport csSym, |
||
689 | Geometry geom, |
||
690 | int[] xyCoords) { |
||
691 | 40435 | jjdelcerro | return isOnePoint(graphicsTransform, viewPort, geom, xyCoords)
|
692 | 42289 | jjdelcerro | && csSym.getCartographicSize(viewPort, dpi, geom) <= 1;
|
693 | 40435 | jjdelcerro | } |
694 | |||
695 | private boolean isOnePoint(AffineTransform graphicsTransform, |
||
696 | 42289 | jjdelcerro | ViewPort viewPort, |
697 | Geometry geom, |
||
698 | int[] xyCoords) { |
||
699 | 40435 | jjdelcerro | boolean onePoint = false; |
700 | int type = geom.getType();
|
||
701 | if (type == Geometry.TYPES.NULL) {
|
||
702 | return false; |
||
703 | } |
||
704 | if (type != Geometry.TYPES.POINT && type != Geometry.TYPES.MULTIPOINT) {
|
||
705 | |||
706 | Envelope geomBounds = geom.getEnvelope(); |
||
707 | |||
708 | // ICoordTrans ct = getCoordTrans();
|
||
709 | // Se supone que la geometria ya esta reproyectada
|
||
710 | // if (ct!=null) {
|
||
711 | // // geomBounds = ct.getInverted().convert(geomBounds);
|
||
712 | // geomBounds = geomBounds.convert(ct);
|
||
713 | // }
|
||
714 | double dist1Pixel = viewPort.getDist1pixel();
|
||
715 | |||
716 | 42289 | jjdelcerro | onePoint |
717 | = (geomBounds.getLength(0) <= dist1Pixel && geomBounds.getLength(1) <= dist1Pixel); |
||
718 | 40435 | jjdelcerro | |
719 | if (onePoint) {
|
||
720 | // avoid out of range exceptions
|
||
721 | org.gvsig.fmap.geom.primitive.Point p; |
||
722 | try {
|
||
723 | 42289 | jjdelcerro | p |
724 | = geomManager.createPoint(geomBounds.getMinimum(0),
|
||
725 | geomBounds.getMinimum(1),
|
||
726 | SUBTYPES.GEOM2D); |
||
727 | 40435 | jjdelcerro | p.transform(viewPort.getAffineTransform()); |
728 | p.transform(graphicsTransform); |
||
729 | xyCoords[0] = (int) p.getX(); |
||
730 | xyCoords[1] = (int) p.getY(); |
||
731 | } catch (org.gvsig.fmap.geom.exception.CreateGeometryException e) {
|
||
732 | logger.error("Error creating a point", e);
|
||
733 | } |
||
734 | |||
735 | } |
||
736 | |||
737 | } |
||
738 | return onePoint;
|
||
739 | } |
||
740 | |||
741 | public boolean isLabeled() { |
||
742 | return isLabeled;
|
||
743 | } |
||
744 | |||
745 | public void setIsLabeled(boolean isLabeled) { |
||
746 | this.isLabeled = isLabeled;
|
||
747 | } |
||
748 | |||
749 | public ILabelingStrategy getLabelingStrategy() {
|
||
750 | return strategy;
|
||
751 | } |
||
752 | |||
753 | public void setLabelingStrategy(ILabelingStrategy strategy) { |
||
754 | this.strategy = strategy;
|
||
755 | if (strategy == null) { |
||
756 | return;
|
||
757 | } |
||
758 | strategy.setLayer(this);
|
||
759 | updateDrawVersion(); |
||
760 | } |
||
761 | |||
762 | public void drawLabels(BufferedImage image, |
||
763 | 42289 | jjdelcerro | Graphics2D g,
|
764 | ViewPort viewPort, |
||
765 | Cancellable cancel, |
||
766 | double scale,
|
||
767 | double dpi) throws ReadException { |
||
768 | 40435 | jjdelcerro | if (strategy != null && isWithinScale(scale)) { |
769 | 41676 | jjdelcerro | strategy.draw(image, g, scale, viewPort, cancel, dpi); |
770 | 40435 | jjdelcerro | } |
771 | } |
||
772 | |||
773 | public void printLabels(Graphics2D g, |
||
774 | 42289 | jjdelcerro | ViewPort viewPort, |
775 | Cancellable cancel, |
||
776 | double scale,
|
||
777 | PrintAttributes properties) throws ReadException {
|
||
778 | 40435 | jjdelcerro | if (strategy != null) { |
779 | 41676 | jjdelcerro | strategy.print(g, scale, viewPort, cancel, properties); |
780 | 40435 | jjdelcerro | } |
781 | } |
||
782 | |||
783 | /**
|
||
784 | * Return true, because a Vectorial Layer supports HyperLink
|
||
785 | 42289 | jjdelcerro | *
|
786 | 40435 | jjdelcerro | * @deprecated the hiperlink functionaliti is out the layer now
|
787 | */
|
||
788 | public boolean allowLinks() { |
||
789 | return false; |
||
790 | } |
||
791 | |||
792 | public void load() throws LoadLayerException { |
||
793 | super.load();
|
||
794 | } |
||
795 | |||
796 | public FeatureStore getFeatureStore() {
|
||
797 | return (FeatureStore) getDataStore();
|
||
798 | } |
||
799 | |||
800 | /**
|
||
801 | 42289 | jjdelcerro | * @deprecated use instead
|
802 | * {@link #queryByPoint(org.gvsig.fmap.geom.primitive.Point, double, FeatureType)}
|
||
803 | 40435 | jjdelcerro | */
|
804 | public FeatureSet queryByPoint(Point2D mapPoint, |
||
805 | 42289 | jjdelcerro | double tol,
|
806 | FeatureType featureType) throws DataException {
|
||
807 | 40435 | jjdelcerro | logger.warn("Deprecated use of queryByPoint.");
|
808 | GeometryManager manager = GeometryLocator.getGeometryManager(); |
||
809 | org.gvsig.fmap.geom.primitive.Point center; |
||
810 | try {
|
||
811 | 42289 | jjdelcerro | center |
812 | = (org.gvsig.fmap.geom.primitive.Point) manager.create(TYPES.POINT, |
||
813 | SUBTYPES.GEOM2D); |
||
814 | 40435 | jjdelcerro | center.setX(mapPoint.getX()); |
815 | center.setY(mapPoint.getY()); |
||
816 | 42289 | jjdelcerro | Circle circle |
817 | = (Circle) manager.create(TYPES.CIRCLE, SUBTYPES.GEOM2D); |
||
818 | 40435 | jjdelcerro | circle.setPoints(center, tol); |
819 | return queryByGeometry(circle, featureType);
|
||
820 | } catch (org.gvsig.fmap.geom.exception.CreateGeometryException e) {
|
||
821 | throw new CreateGeometryException(TYPES.CIRCLE, SUBTYPES.GEOM2D, e); |
||
822 | } |
||
823 | } |
||
824 | |||
825 | public FeatureSet queryByPoint(org.gvsig.fmap.geom.primitive.Point point,
|
||
826 | 42289 | jjdelcerro | double tol,
|
827 | FeatureType featureType) throws DataException {
|
||
828 | 40435 | jjdelcerro | GeometryManager manager = GeometryLocator.getGeometryManager(); |
829 | try {
|
||
830 | 42289 | jjdelcerro | Circle circle |
831 | = (Circle) manager.create(TYPES.CIRCLE, SUBTYPES.GEOM2D); |
||
832 | 40435 | jjdelcerro | circle.setPoints(point, tol); |
833 | return queryByGeometry(circle, featureType);
|
||
834 | } catch (org.gvsig.fmap.geom.exception.CreateGeometryException e) {
|
||
835 | throw new CreateGeometryException(TYPES.CIRCLE, SUBTYPES.GEOM2D, e); |
||
836 | } |
||
837 | } |
||
838 | |||
839 | 40941 | jldominguez | /**
|
840 | * Input geom must be in the CRS of the view.
|
||
841 | 42289 | jjdelcerro | *
|
842 | 40941 | jldominguez | * @param geom
|
843 | * @param featureType
|
||
844 | * @return
|
||
845 | * @throws DataException
|
||
846 | */
|
||
847 | 40435 | jjdelcerro | public FeatureSet queryByGeometry(Geometry geom, FeatureType featureType) throws DataException { |
848 | FeatureQuery featureQuery = featureStore.createFeatureQuery(); |
||
849 | 42289 | jjdelcerro | String geomName
|
850 | = featureStore.getDefaultFeatureType() |
||
851 | 40435 | jjdelcerro | .getDefaultGeometryAttributeName(); |
852 | featureQuery.setFeatureType(featureType); |
||
853 | 42289 | jjdelcerro | |
854 | 41813 | jjdelcerro | Geometry query_geo = this.transformToSourceCRS(geom, true); |
855 | 40435 | jjdelcerro | IProjection query_proj = getMapContext().getProjection(); |
856 | if (this.getCoordTrans() != null) { |
||
857 | 42289 | jjdelcerro | query_proj = this.getCoordTrans().getPOrig();
|
858 | 40435 | jjdelcerro | } |
859 | |||
860 | 42289 | jjdelcerro | IntersectsGeometryEvaluator iee |
861 | = new IntersectsGeometryEvaluator(
|
||
862 | query_geo, |
||
863 | query_proj, |
||
864 | featureStore.getDefaultFeatureType(), |
||
865 | geomName); |
||
866 | 40435 | jjdelcerro | featureQuery.setFilter(iee); |
867 | featureQuery.setAttributeNames(null);
|
||
868 | return getFeatureStore().getFeatureSet(featureQuery);
|
||
869 | |||
870 | } |
||
871 | |||
872 | /**
|
||
873 | * It return the {@link FeatureSet} that intersects with the envelope.
|
||
874 | 42289 | jjdelcerro | *
|
875 | * @param envelope envelope that defines the area for the query.
|
||
876 | * @param featureType only the features with this feature type are used in
|
||
877 | * the query.
|
||
878 | * @return the set of features that intersect with the envelope.
|
||
879 | 40435 | jjdelcerro | * @throws DataException
|
880 | */
|
||
881 | public FeatureSet queryByEnvelope(Envelope envelope, FeatureType featureType) throws DataException { |
||
882 | return queryByEnvelope(envelope, featureType, null); |
||
883 | } |
||
884 | |||
885 | /**
|
||
886 | * It return the {@link FeatureSet} that intersects with the envelope.
|
||
887 | 42289 | jjdelcerro | *
|
888 | * @param envelope envelope that defines the area for the query in viewport
|
||
889 | * CRS
|
||
890 | * @param featureType only the features with this feature type are used in
|
||
891 | * the query.
|
||
892 | * @param names the feature attributes that have to be checked.
|
||
893 | * @return the set of features that intersect with the envelope.
|
||
894 | 40435 | jjdelcerro | * @throws DataException
|
895 | */
|
||
896 | public FeatureSet queryByEnvelope(Envelope envelope,
|
||
897 | 42289 | jjdelcerro | FeatureType featureType, |
898 | String[] names) throws DataException { |
||
899 | 40435 | jjdelcerro | FeatureQuery featureQuery = featureStore.createFeatureQuery(); |
900 | if (names == null) { |
||
901 | featureQuery.setFeatureType(featureType); |
||
902 | } else {
|
||
903 | featureQuery.setAttributeNames(names); |
||
904 | featureQuery.setFeatureTypeId(featureType.getId()); |
||
905 | } |
||
906 | 41676 | jjdelcerro | String geomName = featureStore.getDefaultFeatureType()
|
907 | 40435 | jjdelcerro | .getDefaultGeometryAttributeName(); |
908 | 42289 | jjdelcerro | |
909 | 40435 | jjdelcerro | Envelope query_env = fromViewPortCRSToSourceCRS(this, envelope);
|
910 | IProjection query_proj = getMapContext().getProjection(); |
||
911 | if (this.getCoordTrans() != null) { |
||
912 | 42289 | jjdelcerro | query_proj = this.getCoordTrans().getPOrig();
|
913 | 40435 | jjdelcerro | } |
914 | 42289 | jjdelcerro | |
915 | IntersectsGeometryEvaluator iee |
||
916 | = new IntersectsGeometryEvaluator(
|
||
917 | query_env.getGeometry(), query_proj, |
||
918 | featureStore.getDefaultFeatureType(), |
||
919 | geomName); |
||
920 | 40435 | jjdelcerro | featureQuery.setFilter(iee); |
921 | return getFeatureStore().getFeatureSet(featureQuery);
|
||
922 | |||
923 | } |
||
924 | |||
925 | public DynObjectSet getInfo(Point p, double tolerance, Cancellable cancel) throws LoadLayerException, |
||
926 | 42289 | jjdelcerro | DataException { |
927 | 40435 | jjdelcerro | |
928 | return getInfo(p, tolerance, cancel, true); |
||
929 | } |
||
930 | |||
931 | public DynObjectSet getInfo(Point p, |
||
932 | 42289 | jjdelcerro | double tolerance,
|
933 | Cancellable cancel, |
||
934 | boolean fast) throws LoadLayerException, DataException { |
||
935 | 40435 | jjdelcerro | Point2D infop = new Point2D.Double(p.x, p.y); |
936 | Point2D pReal = this.getMapContext().getViewPort().toMapPoint(infop); |
||
937 | return queryByPoint(pReal,
|
||
938 | 42289 | jjdelcerro | tolerance, |
939 | getFeatureStore().getDefaultFeatureType()).getDynObjectSet(fast); |
||
940 | 40435 | jjdelcerro | } |
941 | |||
942 | public DynObjectSet getInfo(org.gvsig.fmap.geom.primitive.Point p,
|
||
943 | 42289 | jjdelcerro | double tolerance) throws LoadLayerException, DataException { |
944 | return queryByPoint(p, tolerance, getFeatureStore().getDefaultFeatureType()).getDynObjectSet(false); |
||
945 | 40435 | jjdelcerro | } |
946 | 42289 | jjdelcerro | |
947 | 40435 | jjdelcerro | public void legendCleared(LegendClearEvent event) { |
948 | this.updateDrawVersion();
|
||
949 | 42289 | jjdelcerro | LegendChangedEvent e |
950 | = LegendChangedEvent.createLegendChangedEvent(legend, legend); |
||
951 | 40435 | jjdelcerro | this.callLegendChanged(e);
|
952 | } |
||
953 | |||
954 | public boolean symbolChanged(SymbolLegendEvent e) { |
||
955 | this.updateDrawVersion();
|
||
956 | 42289 | jjdelcerro | LegendChangedEvent ev |
957 | = LegendChangedEvent.createLegendChangedEvent(legend, legend); |
||
958 | 40435 | jjdelcerro | this.callLegendChanged(ev);
|
959 | return true; |
||
960 | } |
||
961 | |||
962 | public void update(Observable observable, Object notification) { |
||
963 | if (observable.equals(this.featureStore)) { |
||
964 | if (notification instanceof FeatureStoreNotification) { |
||
965 | 42289 | jjdelcerro | FeatureStoreNotification event |
966 | = (FeatureStoreNotification) notification; |
||
967 | 40435 | jjdelcerro | if (event.getType() == FeatureStoreNotification.AFTER_DELETE
|
968 | 42289 | jjdelcerro | || event.getType() == FeatureStoreNotification.AFTER_UNDO |
969 | || event.getType() == FeatureStoreNotification.AFTER_REDO |
||
970 | || event.getType() == FeatureStoreNotification.AFTER_REFRESH |
||
971 | || event.getType() == FeatureStoreNotification.AFTER_UPDATE |
||
972 | || event.getType() == FeatureStoreNotification.AFTER_UPDATE_TYPE |
||
973 | || event.getType() == FeatureStoreNotification.SELECTION_CHANGE |
||
974 | || event.getType() == FeatureStoreNotification.AFTER_INSERT) { |
||
975 | 40435 | jjdelcerro | this.updateDrawVersion();
|
976 | 42289 | jjdelcerro | |
977 | 40435 | jjdelcerro | } else if (event.getType() == FeatureStoreNotification.AFTER_CANCELEDITING) { |
978 | 42289 | jjdelcerro | |
979 | 40435 | jjdelcerro | setSpatialCacheEnabled(false);
|
980 | callEditionChanged(LayerEvent.createEditionChangedEvent(this, "edition")); |
||
981 | this.updateDrawVersion();
|
||
982 | 42289 | jjdelcerro | |
983 | 40435 | jjdelcerro | } else if (event.getType() == FeatureStoreNotification.AFTER_STARTEDITING) { |
984 | 42289 | jjdelcerro | |
985 | 40435 | jjdelcerro | setSpatialCacheEnabled(true);
|
986 | callEditionChanged(LayerEvent.createEditionChangedEvent(this, "edition")); |
||
987 | |||
988 | 42289 | jjdelcerro | } else if (event.getType() == FeatureStoreNotification.TRANSFORM_CHANGE) { |
989 | 40435 | jjdelcerro | //If a transform has to be applied, try to reload the layer.
|
990 | try {
|
||
991 | reload(); |
||
992 | } catch (ReloadLayerException e) {
|
||
993 | 41132 | jldominguez | logger.info("While reloading layer.", e);
|
994 | 40435 | jjdelcerro | this.setAvailable(false); |
995 | } |
||
996 | } else if (event.getType() == FeatureStoreNotification.RESOURCE_CHANGED) { |
||
997 | this.setAvailable(false); |
||
998 | 42289 | jjdelcerro | } else if (event.getType() == FeatureStoreNotification.AFTER_FINISHEDITING) { |
999 | 40435 | jjdelcerro | this.setAvailable(true); |
1000 | setSpatialCacheEnabled(false);
|
||
1001 | callEditionChanged(LayerEvent.createEditionChangedEvent(this, "edition")); |
||
1002 | this.updateDrawVersion();
|
||
1003 | } |
||
1004 | } |
||
1005 | 42289 | jjdelcerro | } else if (notification instanceof FeatureDrawnNotification |
1006 | && (isEditing() || isLayerToSnap())) { |
||
1007 | 40614 | jldominguez | // This code is needed in editing mode
|
1008 | 42289 | jjdelcerro | // for all layers involved in snapping
|
1009 | // (including the layer being edited)
|
||
1010 | Geometry geometry |
||
1011 | = ((FeatureDrawnNotification) notification).getDrawnGeometry(); |
||
1012 | 40435 | jjdelcerro | spatialCache.insert(geometry.getEnvelope(), geometry); |
1013 | } |
||
1014 | } |
||
1015 | |||
1016 | 40614 | jldominguez | private boolean isLayerToSnap() { |
1017 | 41223 | jldominguez | |
1018 | if (this.getMapContext() == null) { |
||
1019 | /*
|
||
1020 | * This happens with the graphics layer because it has no parent
|
||
1021 | */
|
||
1022 | return false; |
||
1023 | } else {
|
||
1024 | return this.getMapContext().getLayersToSnap().contains(this); |
||
1025 | } |
||
1026 | 40614 | jldominguez | |
1027 | 42289 | jjdelcerro | /*
|
1028 | Iterator itersnap = this.getMapContext().getLayersToSnap().iterator();
|
||
1029 | Object item = null;
|
||
1030 | while (itersnap.hasNext()) {
|
||
1031 | item = itersnap.next();
|
||
1032 | if (item == this) {
|
||
1033 | return true;
|
||
1034 | }
|
||
1035 | }
|
||
1036 | return false;
|
||
1037 | */
|
||
1038 | } |
||
1039 | |||
1040 | /*
|
||
1041 | 40435 | jjdelcerro | * (non-Javadoc)
|
1042 | *
|
||
1043 | * @see org.gvsig.metadata.Metadata#getMetadataChildren()
|
||
1044 | */
|
||
1045 | public Set getMetadataChildren() { |
||
1046 | Set ret = new TreeSet(); |
||
1047 | ret.add(this.featureStore);
|
||
1048 | return ret;
|
||
1049 | } |
||
1050 | |||
1051 | /*
|
||
1052 | * (non-Javadoc)
|
||
1053 | *
|
||
1054 | * @see org.gvsig.metadata.Metadata#getMetadataID()
|
||
1055 | */
|
||
1056 | public Object getMetadataID() throws MetadataException { |
||
1057 | return "Layer(" + this.getName() + "):" |
||
1058 | 42289 | jjdelcerro | + this.featureStore.getMetadataID();
|
1059 | 40435 | jjdelcerro | } |
1060 | |||
1061 | public GeometryType getTypeVectorLayer() throws DataException, |
||
1062 | 42289 | jjdelcerro | LocatorException, |
1063 | GeometryTypeNotSupportedException, |
||
1064 | GeometryTypeNotValidException { |
||
1065 | 40435 | jjdelcerro | // FIXME Esto deberia de pedirse a FType!!!!
|
1066 | FeatureStore fs = this.getFeatureStore();
|
||
1067 | FeatureType fType = fs.getDefaultFeatureType(); |
||
1068 | 42289 | jjdelcerro | FeatureAttributeDescriptor attr |
1069 | = fType.getAttributeDescriptor(fType.getDefaultGeometryAttributeIndex()); |
||
1070 | GeometryType geomType |
||
1071 | = GeometryLocator.getGeometryManager() |
||
1072 | 40435 | jjdelcerro | .getGeometryType(attr.getGeometryType(), |
1073 | 42289 | jjdelcerro | attr.getGeometrySubType()); |
1074 | 40435 | jjdelcerro | return geomType;
|
1075 | } |
||
1076 | |||
1077 | 41840 | jjdelcerro | public static class RegisterPersistence implements Callable { |
1078 | 40435 | jjdelcerro | |
1079 | 41840 | jjdelcerro | public Object call() { |
1080 | PersistenceManager manager = ToolsLocator.getPersistenceManager(); |
||
1081 | 40435 | jjdelcerro | |
1082 | 41840 | jjdelcerro | DynStruct definition |
1083 | = manager.addDefinition(FLyrVect.class, |
||
1084 | "FLyrVect",
|
||
1085 | "FLyrVect Persistence definition",
|
||
1086 | null,
|
||
1087 | null);
|
||
1088 | definition.extend(PersistenceManager.PERSISTENCE_NAMESPACE, |
||
1089 | "FLyrDefault");
|
||
1090 | |||
1091 | definition.addDynFieldObject("legend")
|
||
1092 | .setClassOfValue(IVectorLegend.class) |
||
1093 | .setMandatory(true);
|
||
1094 | definition.addDynFieldObject("featureStore")
|
||
1095 | .setClassOfValue(FeatureStore.class) |
||
1096 | .setMandatory(true);
|
||
1097 | definition.addDynFieldBoolean("isLabeled").setMandatory(true); |
||
1098 | definition.addDynFieldInt("typeShape").setMandatory(true); |
||
1099 | definition.addDynFieldObject("labelingStrategy")
|
||
1100 | .setClassOfValue(ILabelingStrategy.class) |
||
1101 | .setMandatory(false);
|
||
1102 | |||
1103 | return Boolean.TRUE; |
||
1104 | } |
||
1105 | 40435 | jjdelcerro | } |
1106 | |||
1107 | protected void doDispose() throws BaseException { |
||
1108 | dispose(featureStore); |
||
1109 | spatialCache.clearAll(); |
||
1110 | } |
||
1111 | 42289 | jjdelcerro | |
1112 | 40435 | jjdelcerro | /**
|
1113 | 42289 | jjdelcerro | * Returns envelope in layer's data source CRS from envelope provided in
|
1114 | * viewport CRS
|
||
1115 | *
|
||
1116 | 40435 | jjdelcerro | * @param lyr
|
1117 | * @param env
|
||
1118 | * @return
|
||
1119 | */
|
||
1120 | public static Envelope fromViewPortCRSToSourceCRS(FLayer lyr, Envelope env) { |
||
1121 | |||
1122 | if (lyr == null || env == null) { |
||
1123 | return null; |
||
1124 | } |
||
1125 | |||
1126 | ICoordTrans ct = lyr.getCoordTrans(); |
||
1127 | if (ct == null) { |
||
1128 | return env;
|
||
1129 | } else {
|
||
1130 | return env.convert(ct.getInverted());
|
||
1131 | } |
||
1132 | } |
||
1133 | |||
1134 | 41813 | jjdelcerro | public Geometry transformToSourceCRS(Geometry geom, boolean clone) { |
1135 | 42289 | jjdelcerro | return fromViewPortCRSToSourceCRS(this, geom, clone); |
1136 | 41813 | jjdelcerro | } |
1137 | 42289 | jjdelcerro | |
1138 | 40435 | jjdelcerro | /**
|
1139 | 42289 | jjdelcerro | * Returns geometry in layer's data source CRS from geometry provided in
|
1140 | * viewport CRS
|
||
1141 | *
|
||
1142 | 40435 | jjdelcerro | * @param lyr
|
1143 | * @param geo
|
||
1144 | * @param clone
|
||
1145 | * @return
|
||
1146 | 41813 | jjdelcerro | * @deprecated use the transformToSourceCRS method of layer.
|
1147 | 40435 | jjdelcerro | */
|
1148 | public static Geometry fromViewPortCRSToSourceCRS( |
||
1149 | 42289 | jjdelcerro | FLayer lyr, |
1150 | Geometry geo, |
||
1151 | boolean clone) {
|
||
1152 | |||
1153 | 40435 | jjdelcerro | if (lyr == null || geo == null) { |
1154 | return null; |
||
1155 | } |
||
1156 | ICoordTrans ct = lyr.getCoordTrans(); |
||
1157 | Geometry resp = geo; |
||
1158 | if (clone) {
|
||
1159 | resp = resp.cloneGeometry(); |
||
1160 | } |
||
1161 | if (ct != null) { |
||
1162 | resp.reProject(ct.getInverted()); |
||
1163 | } |
||
1164 | return resp;
|
||
1165 | } |
||
1166 | |||
1167 | 42293 | jjdelcerro | public Iterator iterator() { |
1168 | return this.getFeatureStore().iterator(); |
||
1169 | } |
||
1170 | 40435 | jjdelcerro | } |