7 |
7 |
import java.awt.image.BufferedImage;
|
8 |
8 |
import org.gvsig.fmap.dal.feature.Feature;
|
9 |
9 |
import org.gvsig.fmap.geom.Geometry;
|
|
10 |
import org.gvsig.fmap.geom.GeometryLocator;
|
|
11 |
import org.gvsig.fmap.geom.GeometryManager;
|
10 |
12 |
import org.gvsig.fmap.geom.aggregate.Aggregate;
|
|
13 |
import org.gvsig.fmap.geom.exception.CreateGeometryException;
|
11 |
14 |
import org.gvsig.fmap.geom.primitive.Point;
|
12 |
15 |
import org.gvsig.fmap.mapcontext.MapContext;
|
13 |
|
import org.gvsig.fmap.mapcontext.ViewPort;
|
|
16 |
import org.gvsig.fmap.mapcontext.rendering.symbols.CartographicSupport;
|
14 |
17 |
import org.gvsig.fmap.mapcontext.rendering.symbols.IMultiLayerSymbol;
|
15 |
18 |
import org.gvsig.fmap.mapcontext.rendering.symbols.ISymbol;
|
|
19 |
import org.gvsig.fmap.mapcontext.rendering.symbols.ISymbol_v2;
|
16 |
20 |
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.line.ILineSymbol;
|
17 |
21 |
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.line.impl.AbstractLineSymbol;
|
18 |
22 |
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.marker.IMarkerSymbol;
|
... | ... | |
51 |
55 |
}
|
52 |
56 |
|
53 |
57 |
@Override
|
54 |
|
public void draw(Graphics2D g, AffineTransform affineTransform, Geometry geom, Feature f, Cancellable cnclbl) {
|
|
58 |
public void draw(Graphics2D g, AffineTransform affineTransform, Geometry geom, Feature f, Cancellable cnclbl, Rectangle r) {
|
55 |
59 |
Point p;
|
56 |
|
try {
|
57 |
|
p = geom.centroid();
|
58 |
|
} catch (Exception ex) {
|
59 |
|
return;
|
|
60 |
if(r != null){
|
|
61 |
GeometryManager geometryManager = GeometryLocator.getGeometryManager();
|
|
62 |
try {
|
|
63 |
p = (Point) geometryManager.createPoint(r.getCenterX(), r.getCenterY(), Geometry.SUBTYPES.GEOM2D);
|
|
64 |
} catch (CreateGeometryException ex) {
|
|
65 |
return;
|
|
66 |
}
|
|
67 |
} else {
|
|
68 |
try {
|
|
69 |
p = geom.centroid();
|
|
70 |
} catch (Exception ex) {
|
|
71 |
return;
|
|
72 |
}
|
|
73 |
try {
|
|
74 |
if( geom.getType()==Geometry.TYPES.LINE ) {
|
|
75 |
// Si es una linea, intenta coger un punto aproximadamente
|
|
76 |
// sobre el centro de la linea.
|
|
77 |
p = (Point) geom.closestPoints(p)[0];
|
|
78 |
} else if( geom.getType()==Geometry.TYPES.MULTILINE && ((Aggregate)geom).getPrimitivesNumber()==1 ) {
|
|
79 |
// Si es una multilinea compuesta por solo una linea, intenta
|
|
80 |
// coger un punto aproximadamene sobre el centro de esa linea
|
|
81 |
p = (Point) ((Aggregate)geom).getPrimitiveAt(0).closestPoints(p)[0];
|
|
82 |
}
|
|
83 |
} catch(Throwable th) {
|
|
84 |
// Do nothing, ignore error and use centroid
|
|
85 |
LOGGER.debug("Problems calculating the center of geometry",th);
|
|
86 |
}
|
|
87 |
|
|
88 |
if (affineTransform != null) {
|
|
89 |
p.transform(affineTransform);
|
|
90 |
}
|
60 |
91 |
}
|
61 |
|
if (affineTransform != null) {
|
62 |
|
p.transform(affineTransform);
|
63 |
|
}
|
64 |
92 |
double x, y;
|
65 |
93 |
int size = (int) Math.round(this.parent.getEfectiveSize(f));
|
66 |
94 |
double halfSize = this.parent.getEfectiveSize(f) / 2;
|
... | ... | |
85 |
113 |
}
|
86 |
114 |
|
87 |
115 |
@Override
|
88 |
|
public double toCartographicSize(ViewPort viewPort, double dpi, Geometry geom) {
|
89 |
|
return this.parent.toCartographicSize(viewPort, dpi, geom); //To change body of generated methods, choose Tools | Templates.
|
|
116 |
public void setCartographicContext(CartographicContext ctx) {
|
|
117 |
super.setCartographicContext(ctx);
|
|
118 |
this.parent.setCartographicContext(ctx);
|
90 |
119 |
}
|
91 |
|
|
|
120 |
|
92 |
121 |
@Override
|
93 |
|
public void setCartographicSize(double cartographicSize, Geometry geom) {
|
94 |
|
this.parent.setCartographicSize(cartographicSize, geom); //To change body of generated methods, choose Tools | Templates.
|
95 |
|
}
|
96 |
|
|
97 |
|
@Override
|
98 |
122 |
public int getUnit() {
|
99 |
123 |
return this.parent.getUnit();
|
100 |
124 |
}
|
... | ... | |
115 |
139 |
}
|
116 |
140 |
|
117 |
141 |
@Override
|
118 |
|
public void draw(Graphics2D g, AffineTransform affineTransform, Geometry geom, Feature f, Cancellable cnclbl) {
|
|
142 |
public void draw(Graphics2D g, AffineTransform affineTransform, Geometry geom, Feature f, Cancellable cnclbl, Rectangle rect) {
|
119 |
143 |
Point p;
|
120 |
144 |
try {
|
121 |
145 |
p = geom.centroid();
|
... | ... | |
148 |
172 |
}
|
149 |
173 |
|
150 |
174 |
@Override
|
151 |
|
public double toCartographicSize(ViewPort viewPort, double dpi, Geometry geom) {
|
152 |
|
return this.parent.toCartographicSize(viewPort, dpi, geom); //To change body of generated methods, choose Tools | Templates.
|
|
175 |
public void setCartographicContext(CartographicContext ctx) {
|
|
176 |
super.setCartographicContext(ctx);
|
|
177 |
this.parent.setCartographicContext(ctx);
|
153 |
178 |
}
|
154 |
|
|
|
179 |
|
155 |
180 |
@Override
|
156 |
|
public void setCartographicSize(double cartographicSize, Geometry geom) {
|
157 |
|
this.parent.setCartographicSize(cartographicSize, geom); //To change body of generated methods, choose Tools | Templates.
|
158 |
|
}
|
159 |
|
|
160 |
|
@Override
|
161 |
181 |
public int getUnit() {
|
162 |
182 |
return this.parent.getUnit();
|
163 |
183 |
}
|
... | ... | |
177 |
197 |
}
|
178 |
198 |
|
179 |
199 |
@Override
|
180 |
|
public void draw(Graphics2D g, AffineTransform affineTransform, Geometry geom, Feature f, Cancellable cancel) {
|
181 |
|
Point p;
|
182 |
|
try {
|
183 |
|
p = geom.centroid();
|
184 |
|
} catch (Exception ex) {
|
185 |
|
return;
|
186 |
|
}
|
187 |
|
try {
|
188 |
|
if( geom.getType()==Geometry.TYPES.LINE ) {
|
189 |
|
// Si es una linea, intenta coger un punto aproximadamene
|
190 |
|
// sobre el centro de la linea.
|
191 |
|
p = (Point) geom.closestPoints(p)[0];
|
192 |
|
} else if( geom.getType()==Geometry.TYPES.MULTILINE && ((Aggregate)geom).getPrimitivesNumber()==1 ) {
|
193 |
|
// Si es una multilinea compuesta por solo una linea, intenta
|
194 |
|
// coger un punto aproximadamene sobre el centro de esa linea
|
195 |
|
p = (Point) ((Aggregate)geom).getPrimitiveAt(0).closestPoints(p)[0];
|
|
200 |
public void draw(Graphics2D g, AffineTransform affineTransform, Geometry geom, Feature f, Cancellable cancel, Rectangle r) {
|
|
201 |
for (int i = 0; (cancel == null || !cancel.isCanceled())
|
|
202 |
&& layers != null && i < layers.length; i++) {
|
|
203 |
ISymbol layer = layers[i];
|
|
204 |
if (layer == null) {
|
|
205 |
continue;
|
196 |
206 |
}
|
197 |
|
} catch(Throwable th) {
|
198 |
|
// Do nothing, ignore error and use centroid
|
199 |
|
LOGGER.debug("Problems calculating the center of geometry",th);
|
200 |
|
}
|
201 |
|
|
202 |
|
if (affineTransform != null) {
|
203 |
|
p.transform(affineTransform);
|
204 |
|
}
|
205 |
|
double x, y;
|
206 |
|
int size = (int) Math.round(getEfectiveSize(f));
|
207 |
|
double halfSize = getEfectiveSize(f) / 2;
|
208 |
|
x = p.getX() - halfSize;
|
209 |
|
y = p.getY() - halfSize;
|
210 |
|
Point2D theOffset = this.getEfectiveOffset(f);
|
211 |
|
int xOffset = (int) theOffset.getX();
|
212 |
|
int yOffset = (int) theOffset.getY();
|
213 |
|
|
214 |
|
if (size > 0) {
|
215 |
|
if( isDrawLineToOffset() ) {
|
216 |
|
g.setColor(this.getEfectiveLineToOffsetColor(f));
|
217 |
|
g.drawLine((int)p.getX(), (int)p.getY(), (int)p.getX() + xOffset, (int)p.getY() + yOffset);
|
|
207 |
if(layer instanceof CartographicSupport){
|
|
208 |
((CartographicSupport)layer).setCartographicContext(this.getCartographicContext());
|
218 |
209 |
}
|
219 |
|
Rectangle rect = new Rectangle(size, size);
|
220 |
|
g.translate(x + xOffset, y + yOffset);
|
221 |
|
double auxRotation = getEfectiveRotationInRadians(f);
|
222 |
|
g.rotate(auxRotation, halfSize, halfSize);
|
223 |
|
|
224 |
|
this.drawInsideRectangle(g, rect, true);
|
225 |
|
|
226 |
|
g.rotate(-auxRotation, halfSize, halfSize);
|
227 |
|
g.translate(-(x + xOffset), -(y + yOffset));
|
228 |
|
|
|
210 |
if(layer instanceof ISymbol_v2){
|
|
211 |
((ISymbol_v2)layer).draw(g, affineTransform, geom, f, cancel, r);
|
|
212 |
} else {
|
|
213 |
layer.draw(g, affineTransform, geom, f, cancel);
|
|
214 |
}
|
229 |
215 |
}
|
230 |
216 |
}
|
231 |
217 |
|
... | ... | |
332 |
318 |
public ISymbol[] getLayers() {
|
333 |
319 |
return layers;
|
334 |
320 |
}
|
335 |
|
|
336 |
|
|
337 |
|
|
|
321 |
|
|
322 |
@Override
|
|
323 |
public void setCartographicContext(CartographicContext ctx) {
|
|
324 |
super.setCartographicContext(ctx);
|
|
325 |
// ((CartographicSupport)this.layers[0]).setCartographicContext(ctx);
|
|
326 |
// ((CartographicSupport)this.layers[1]).setCartographicContext(ctx);
|
|
327 |
}
|
338 |
328 |
}
|