gvsig-3d / 2.1 / trunk / org.gvsig.view3d / org.gvsig.view3d.vector / org.gvsig.view3d.vector.lib / org.gvsig.view3d.vector.lib.impl / src / main / java / org / gvsig / view3d / vector / lib / impl / AbstractPointRenderableLayer.java @ 761
History | View | Annotate | Download (5.29 KB)
1 | 761 | llmarques | package org.gvsig.view3d.vector.lib.impl; |
---|---|---|---|
2 | |||
3 | import java.awt.Color; |
||
4 | import java.util.List; |
||
5 | import java.util.concurrent.ExecutorService; |
||
6 | import java.util.concurrent.Executors; |
||
7 | |||
8 | import org.slf4j.Logger; |
||
9 | import org.slf4j.LoggerFactory; |
||
10 | |||
11 | import org.gvsig.fmap.dal.exception.DataException; |
||
12 | import org.gvsig.fmap.dal.feature.Feature; |
||
13 | import org.gvsig.fmap.dal.feature.FeatureQuery; |
||
14 | import org.gvsig.fmap.dal.feature.FeatureSet; |
||
15 | import org.gvsig.fmap.dal.feature.FeatureStore; |
||
16 | import org.gvsig.fmap.mapcontext.rendering.legend.IVectorLegend; |
||
17 | import org.gvsig.fmap.mapcontext.rendering.symbols.ISymbol; |
||
18 | import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.marker.ISimpleMarkerSymbol; |
||
19 | import org.gvsig.tools.dispose.DisposableIterator; |
||
20 | import org.gvsig.view3d.vector.lib.api.VectorElevationMode; |
||
21 | import org.gvsig.view3d.vector.lib.api.VectorLoaderParameters; |
||
22 | |||
23 | import gov.nasa.worldwind.WorldWind; |
||
24 | import gov.nasa.worldwind.layers.RenderableLayer; |
||
25 | import gov.nasa.worldwind.render.Material; |
||
26 | import gov.nasa.worldwind.render.PointPlacemarkAttributes; |
||
27 | import gov.nasa.worldwind.render.Renderable; |
||
28 | |||
29 | public abstract class AbstractPointRenderableLayer extends RenderableLayer { |
||
30 | |||
31 | private static final Logger LOG = LoggerFactory.getLogger(AbstractPointRenderableLayer.class); |
||
32 | |||
33 | protected FeatureStore featureStore;
|
||
34 | |||
35 | protected PointPlacemarkAttributes markAttributes;
|
||
36 | |||
37 | protected VectorLoaderParameters parameters;
|
||
38 | |||
39 | public AbstractPointRenderableLayer(VectorLoaderParameters parameters, FeatureStore featureStore,
|
||
40 | IVectorLegend legend) { |
||
41 | this.featureStore = featureStore;
|
||
42 | this.parameters = parameters;
|
||
43 | this.markAttributes = getBasicMarkerAttributes(legend);
|
||
44 | ExecutorService executor = Executors.newSingleThreadExecutor(); |
||
45 | executor.execute(addRenderableObjects()); |
||
46 | } |
||
47 | |||
48 | protected Runnable addRenderableObjects() { |
||
49 | |||
50 | return new Runnable() { |
||
51 | |||
52 | @Override
|
||
53 | public void run() { |
||
54 | FeatureQuery featureQuery; |
||
55 | try {
|
||
56 | featureQuery = getFeatureQuery(); |
||
57 | } catch (DataException e) {
|
||
58 | LOG.error(String.format("Can not access to feature type of %1s", featureStore.getFullName()), e); |
||
59 | removeAllRenderables(); |
||
60 | return;
|
||
61 | } |
||
62 | |||
63 | FeatureSet featureSet = null;
|
||
64 | DisposableIterator it = null;
|
||
65 | try {
|
||
66 | featureSet = featureStore.getFeatureSet(featureQuery); |
||
67 | it = featureSet.fastIterator(); |
||
68 | while (it.hasNext()) {
|
||
69 | Feature feature = (Feature) it.next(); |
||
70 | List<Renderable> renderables = getRenderable(feature);
|
||
71 | for (Renderable renderable : renderables) {
|
||
72 | addRenderable(renderable); |
||
73 | } |
||
74 | } |
||
75 | } catch (DataException e) {
|
||
76 | LOG.error(String.format("Can not access to %1s data", featureStore.getFullName()), e); |
||
77 | removeAllRenderables(); |
||
78 | return;
|
||
79 | } finally {
|
||
80 | if (it != null) { |
||
81 | it.dispose(); |
||
82 | } |
||
83 | if (featureSet != null) { |
||
84 | featureSet.dispose(); |
||
85 | } |
||
86 | } |
||
87 | } |
||
88 | }; |
||
89 | } |
||
90 | |||
91 | protected PointPlacemarkAttributes getBasicMarkerAttributes(IVectorLegend legend) {
|
||
92 | |||
93 | if (this.markAttributes != null) { |
||
94 | return this.markAttributes; |
||
95 | } |
||
96 | |||
97 | double markerSize = 0; |
||
98 | Material fillMaterial = null;
|
||
99 | |||
100 | if (legend == null) { |
||
101 | fillMaterial = new Material(parameters.getDefaultColor());
|
||
102 | markerSize = 0.3;
|
||
103 | } else {
|
||
104 | ISymbol symbol = legend.getDefaultSymbol(); |
||
105 | if (symbol instanceof ISimpleMarkerSymbol) { |
||
106 | ISimpleMarkerSymbol markerSymbol = (ISimpleMarkerSymbol) symbol; |
||
107 | Color fillColor = markerSymbol.getColor();
|
||
108 | markerSize = markerSymbol.getSize(); |
||
109 | fillMaterial = new Material(fillColor);
|
||
110 | } else {
|
||
111 | fillMaterial = new Material(parameters.getDefaultColor());
|
||
112 | markerSize = 4;
|
||
113 | } |
||
114 | } |
||
115 | markAttributes = new PointPlacemarkAttributes();
|
||
116 | Color color = fillMaterial.getDiffuse();
|
||
117 | markAttributes.setImageColor(color); |
||
118 | markAttributes.setLineMaterial(fillMaterial); |
||
119 | markAttributes.setLineWidth(1d);
|
||
120 | markAttributes.setUsePointAsDefaultImage(true);
|
||
121 | markAttributes.setScale(markerSize); |
||
122 | return markAttributes;
|
||
123 | } |
||
124 | |||
125 | protected int getAltitudeMode(VectorElevationMode mode) { |
||
126 | switch (mode) {
|
||
127 | case CLAMP_TO_GROUND:
|
||
128 | return WorldWind.CLAMP_TO_GROUND;
|
||
129 | case ABSOLUTE:
|
||
130 | return WorldWind.ABSOLUTE;
|
||
131 | case RELATIVE_TO_GROUND:
|
||
132 | return WorldWind.RELATIVE_TO_GROUND;
|
||
133 | default:
|
||
134 | throw new IllegalArgumentException( |
||
135 | "Vector elevation mode not reconized. Only CLAMP_TO_GROUND, ABSOLUTE and RELATIVE_TO_GROUND are valid");
|
||
136 | } |
||
137 | } |
||
138 | |||
139 | protected abstract List<Renderable> getRenderable(Feature feature); |
||
140 | |||
141 | protected abstract FeatureQuery getFeatureQuery() throws DataException; |
||
142 | } |