svn-gvsig-desktop / branches / v2_0_0_prep / libraries / libFMap_mapcontext / src-test / org / gvsig / fmap / mapcontext / rendering / TestCartographicSupportForSymbol.java @ 29313
History | View | Annotate | Download (21.5 KB)
1 |
/* gvSIG. Sistema de Informaci�n Geogr�fica de la Generalitat Valenciana
|
---|---|
2 |
*
|
3 |
* Copyright (C) 2005 IVER T.I. and Generalitat Valenciana.
|
4 |
*
|
5 |
* This program is free software; you can redistribute it and/or
|
6 |
* modify it under the terms of the GNU General Public License
|
7 |
* as published by the Free Software Foundation; either version 2
|
8 |
* of the License, or (at your option) any later version.
|
9 |
*
|
10 |
* This program is distributed in the hope that it will be useful,
|
11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
13 |
* GNU General Public License for more details.
|
14 |
*
|
15 |
* You should have received a copy of the GNU General Public License
|
16 |
* along with this program; if not, write to the Free Software
|
17 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
18 |
*
|
19 |
* For more information, contact:
|
20 |
*
|
21 |
* Generalitat Valenciana
|
22 |
* Conselleria d'Infraestructures i Transport
|
23 |
* Av. Blasco Ib��ez, 50
|
24 |
* 46010 VALENCIA
|
25 |
* SPAIN
|
26 |
*
|
27 |
* +34 963862235
|
28 |
* gvsig@gva.es
|
29 |
* www.gvsig.gva.es
|
30 |
*
|
31 |
* or
|
32 |
*
|
33 |
* IVER T.I. S.A
|
34 |
* Salamanca 50
|
35 |
* 46005 Valencia
|
36 |
* Spain
|
37 |
*
|
38 |
* +34 963163400
|
39 |
* dac@iver.es
|
40 |
*/
|
41 |
package org.gvsig.fmap.mapcontext.rendering; |
42 |
|
43 |
import java.awt.Dimension; |
44 |
import java.awt.geom.Rectangle2D; |
45 |
import java.util.ArrayList; |
46 |
import java.util.Random; |
47 |
|
48 |
import junit.framework.TestCase; |
49 |
|
50 |
import org.gvsig.compat.CompatLocator; |
51 |
import org.gvsig.fmap.AllTests; |
52 |
import org.gvsig.fmap.geom.Geometry; |
53 |
import org.gvsig.fmap.geom.GeometryLocator; |
54 |
import org.gvsig.fmap.geom.GeometryManager; |
55 |
import org.gvsig.fmap.geom.Geometry.SUBTYPES; |
56 |
import org.gvsig.fmap.geom.exception.CreateEnvelopeException; |
57 |
import org.gvsig.fmap.geom.exception.CreateGeometryException; |
58 |
import org.gvsig.fmap.geom.primitive.Envelope; |
59 |
import org.gvsig.fmap.geom.primitive.Point; |
60 |
import org.gvsig.fmap.geom.util.UtilFunctions; |
61 |
import org.gvsig.fmap.mapcontext.MapContext; |
62 |
import org.gvsig.fmap.mapcontext.ViewPort; |
63 |
import org.gvsig.fmap.mapcontext.rendering.symbol.AbstractSymbolTestCase; |
64 |
import org.gvsig.fmap.mapcontext.rendering.symbol.SimpleFillSymbolTest; |
65 |
import org.gvsig.fmap.mapcontext.rendering.symbol.SimpleLineSymbolTest; |
66 |
import org.gvsig.fmap.mapcontext.rendering.symbol.SimpleMarkerSymbolTest; |
67 |
import org.gvsig.fmap.mapcontext.rendering.symbols.CartographicSupport; |
68 |
import org.gvsig.fmap.mapcontext.rendering.symbols.IFillSymbol; |
69 |
import org.gvsig.fmap.mapcontext.rendering.symbols.ILineSymbol; |
70 |
import org.gvsig.fmap.mapcontext.rendering.symbols.IMarkerSymbol; |
71 |
import org.gvsig.fmap.mapcontext.rendering.symbols.ISymbol; |
72 |
import org.gvsig.fmap.mapcontext.rendering.symbols.SymbologyFactory; |
73 |
import org.slf4j.Logger; |
74 |
import org.slf4j.LoggerFactory; |
75 |
|
76 |
import com.iver.utiles.IPersistence; |
77 |
import com.iver.utiles.NotExistInXMLEntity; |
78 |
import com.iver.utiles.XMLEntity; |
79 |
import com.iver.utiles.XMLException; |
80 |
|
81 |
/**
|
82 |
*
|
83 |
* @author jaume dominguez faus - jaume.dominguez@iver.es
|
84 |
*/
|
85 |
public class TestCartographicSupportForSymbol extends TestCase { |
86 |
private static final GeometryManager geomManager = GeometryLocator.getGeometryManager(); |
87 |
private static final Logger logger = LoggerFactory.getLogger(TestCartographicSupportForSymbol.class); |
88 |
|
89 |
/**
|
90 |
* Geodesic vertex of the Micalet in Valencia (Spain) in <b>EPSG:23030</b>
|
91 |
*/
|
92 |
public static Point valenciaUTM30 = null; |
93 |
|
94 |
/**
|
95 |
* Geodesic vertex of the Micalet in Valencia (Spain) in <b>EPSG:4326</b>
|
96 |
*/
|
97 |
public static Point valenciaGeo = null; |
98 |
/**
|
99 |
* Extent that covers the whole Comunitat Valenciana in <b>EPSG:23030</b>
|
100 |
*/
|
101 |
public static final Rectangle2D TEST_UTM30_EXTENT = new Rectangle2D.Double(); |
102 |
{ |
103 |
TEST_UTM30_EXTENT.setFrameFromDiagonal( |
104 |
4191037.369934333,
|
105 |
626674.7454557443,
|
106 |
|
107 |
4519266.460824658,
|
108 |
797903.2656794232
|
109 |
); |
110 |
} |
111 |
/**
|
112 |
* Extent that covers the whole Comunitat Valenciana in <b>EPSG:4326</b>
|
113 |
*/
|
114 |
|
115 |
public static final Rectangle2D TEST_GEO_EXTENT = new Rectangle2D.Double(); |
116 |
{ |
117 |
TEST_GEO_EXTENT.setFrameFromDiagonal( |
118 |
|
119 |
- (1 + (31/60) + (28.09/3600)), // Western egde |
120 |
37 + (50/60) + (48.05/3600), // Southern edge |
121 |
|
122 |
0 + (31/60) + (1.85/3600), // Eastern edge |
123 |
40 + (47/60) + (21.36/3600) // Northern edge |
124 |
|
125 |
); |
126 |
} |
127 |
|
128 |
public static final Rectangle2D TEST_EXTENT = new Rectangle2D.Double( |
129 |
4191037.369934333,
|
130 |
626674.7454557443,
|
131 |
|
132 |
4519266.460824658 - 4191037.369934333, |
133 |
797903.2656794232 - 626674.7454557443 |
134 |
); |
135 |
private static ArrayList symbolsToTest; //<AbstractSymbolTestCase> |
136 |
private ArrayList csSymbols; //<CartographicSupport> |
137 |
|
138 |
/**
|
139 |
* Acceptable pixel tolerance error. 1 pixel of error is accetable since it is probably due to
|
140 |
* the java.awt.Graphics
|
141 |
*/
|
142 |
private static final double TOL = 1; |
143 |
|
144 |
double zooms[] = new double[] { |
145 |
1,
|
146 |
2,
|
147 |
1.2,
|
148 |
10,
|
149 |
0.5
|
150 |
}; |
151 |
|
152 |
|
153 |
|
154 |
public void setUp() { |
155 |
try {
|
156 |
valenciaUTM30 = geomManager.createPoint(725846.080, 4373022.720, SUBTYPES.GEOM2D); |
157 |
valenciaGeo = geomManager.createPoint(- (0+ 22/60 + 27.919/3600), 39 + 28/60 + 35.4276/3600, SUBTYPES.GEOM2D); |
158 |
} catch (CreateGeometryException e) {
|
159 |
// TODO Auto-generated catch block
|
160 |
e.printStackTrace(); |
161 |
} |
162 |
|
163 |
addSymbolTest(new SimpleFillSymbolTest());
|
164 |
addSymbolTest(new SimpleLineSymbolTest());
|
165 |
addSymbolTest(new SimpleMarkerSymbolTest());
|
166 |
|
167 |
init(); |
168 |
} |
169 |
|
170 |
protected void init() { |
171 |
|
172 |
// take the symbols added to the TestISymbol test
|
173 |
ISymbol[] symbols = getNewSymbolInstances();
|
174 |
|
175 |
csSymbols = new ArrayList(); //<CartographicSupport> |
176 |
for (int i = 0; i < symbols.length; i++) { |
177 |
if (symbols[i] instanceof CartographicSupport) { |
178 |
csSymbols.add((CartographicSupport) symbols[i]); |
179 |
} |
180 |
} |
181 |
} |
182 |
|
183 |
public static void addSymbolTest(AbstractSymbolTestCase symbolTestClass) { |
184 |
if (symbolsToTest == null) symbolsToTest = new ArrayList(); //<AbstractSymbolTestCase> |
185 |
symbolsToTest.add(symbolTestClass); |
186 |
} |
187 |
|
188 |
public static ISymbol[] getNewSymbolInstances() { |
189 |
ISymbol[] symbols = new ISymbol[symbolsToTest.size()]; |
190 |
for (int i = 0; i < symbols.length; i++) { |
191 |
symbols[i] = (ISymbol)((AbstractSymbolTestCase)symbolsToTest.get(i)).newInstance(); |
192 |
} |
193 |
return symbols;
|
194 |
} |
195 |
|
196 |
|
197 |
public void testSymbolUnitDefinition() { |
198 |
for (int i = 0; i < csSymbols.size(); i++) { |
199 |
CartographicSupport symbol = (CartographicSupport)csSymbols.get(i); |
200 |
|
201 |
int aRandomUnit = new Random().nextInt(7); |
202 |
|
203 |
|
204 |
symbol.setUnit(aRandomUnit); |
205 |
XMLEntity xml=null;
|
206 |
try {
|
207 |
xml = ((IPersistence) symbol).getXMLEntity(); |
208 |
} catch (XMLException e) {
|
209 |
// TODO Auto-generated catch block
|
210 |
e.printStackTrace(); |
211 |
} |
212 |
String name = symbol.getClass().getName().substring(
|
213 |
symbol.getClass().getName().lastIndexOf('.')+1, |
214 |
symbol.getClass().getName().length()); |
215 |
|
216 |
try {
|
217 |
assertTrue( ((ISymbol) symbol).getClassName()+" does not declare units correctly",
|
218 |
symbol.getUnit() == xml.getIntProperty("unit"));
|
219 |
} catch (NotExistInXMLEntity neiXMLEx) {
|
220 |
fail(((ISymbol) symbol).getClassName()+ " does not declare field attribute in its XMLEntity");
|
221 |
} |
222 |
symbol.setUnit(5);
|
223 |
try {
|
224 |
assertTrue( ((ISymbol) symbol).getClassName()+" does not apply changes to symbol",symbol.getUnit()== 5); |
225 |
assertTrue( ((ISymbol) symbol).getClassName()+" does not declare units correctly",
|
226 |
5 == ((IPersistence) symbol).getXMLEntity().getIntProperty("unit")); |
227 |
} catch (NotExistInXMLEntity neiXMLEx) {
|
228 |
fail(((ISymbol) symbol).getClassName()+ " does not declare field attribute in its XMLEntity");
|
229 |
} catch (XMLException e) {
|
230 |
fail(((ISymbol) symbol).getClassName()+ " does not declare field attribute in its XMLEntity");
|
231 |
} |
232 |
|
233 |
xml.putProperty("unit", 3); |
234 |
ISymbol ts = SymbologyFactory.createSymbolFromXML(xml, xml.getStringProperty("desc"));
|
235 |
assertTrue("The application of the UNIT value to the XMLEntity didn't have any effect ("+name+")", ((CartographicSupport) ts).getUnit() == 3); |
236 |
} |
237 |
|
238 |
} |
239 |
|
240 |
|
241 |
public void testSymbolReferenceSystemDefinition() { |
242 |
for (int i = 0; i < csSymbols.size(); i++) { |
243 |
CartographicSupport symbol = (CartographicSupport)csSymbols.get(i); |
244 |
XMLEntity xml=null;
|
245 |
try {
|
246 |
xml = ((IPersistence) symbol).getXMLEntity(); |
247 |
} catch (XMLException e) {
|
248 |
// TODO Auto-generated catch block
|
249 |
e.printStackTrace(); |
250 |
} |
251 |
String name = symbol.getClass().getName().substring(
|
252 |
symbol.getClass().getName().lastIndexOf('.')+1, |
253 |
symbol.getClass().getName().length()); |
254 |
try {
|
255 |
assertTrue( ((ISymbol) symbol).getClassName()+" does not declare units correctly",
|
256 |
symbol.getReferenceSystem() == xml.getIntProperty("referenceSystem"));
|
257 |
} catch (NotExistInXMLEntity neiXMLEx) {
|
258 |
fail(((ISymbol) symbol).getClassName()+ " does not declare referenceSystem field attribute in its XMLEntity");
|
259 |
} |
260 |
symbol.setReferenceSystem(CartographicSupport.PAPER); |
261 |
try {
|
262 |
assertTrue( ((ISymbol) symbol).getClassName()+" does not apply changes to symbol",symbol.getReferenceSystem()== CartographicSupport.PAPER);
|
263 |
assertTrue( ((ISymbol) symbol).getClassName()+" does not declare referenceSystem correctly",
|
264 |
CartographicSupport.PAPER == ((IPersistence) symbol).getXMLEntity().getIntProperty("referenceSystem"));
|
265 |
} catch (NotExistInXMLEntity neiXMLEx) {
|
266 |
fail(((ISymbol) symbol).getClassName()+ " does not declare referenceSystem field attribute in its XMLEntity ("+name+")"); |
267 |
} catch (XMLException e) {
|
268 |
fail(((ISymbol) symbol).getClassName()+ " does not declare referenceSystem field attribute in its XMLEntity ("+name+")"); |
269 |
} |
270 |
|
271 |
symbol.setReferenceSystem(CartographicSupport.WORLD); |
272 |
try {
|
273 |
assertTrue( ((ISymbol) symbol).getClassName()+" does not apply changes to symbol",symbol.getReferenceSystem()== CartographicSupport.WORLD);
|
274 |
assertTrue( ((ISymbol) symbol).getClassName()+" does not declare referenceSystem correctly",
|
275 |
CartographicSupport.WORLD == ((IPersistence) symbol).getXMLEntity().getIntProperty("referenceSystem"));
|
276 |
} catch (NotExistInXMLEntity neiXMLEx) {
|
277 |
fail(((ISymbol) symbol).getClassName()+ " does not declare referenceSystem field attribute in its XMLEntity");
|
278 |
} catch (XMLException e) {
|
279 |
fail(((ISymbol) symbol).getClassName()+ " does not declare referenceSystem field attribute in its XMLEntity");
|
280 |
} |
281 |
|
282 |
xml.putProperty("referenceSystem", CartographicSupport.PAPER);
|
283 |
ISymbol ts = SymbologyFactory.createSymbolFromXML(xml, xml.getStringProperty("desc"));
|
284 |
assertTrue("The application of the REFERENCE SYSTEM value to the XMLEntity didn't have any effect ("+name+")", ((CartographicSupport) ts).getReferenceSystem() == CartographicSupport.PAPER); |
285 |
} |
286 |
} |
287 |
|
288 |
|
289 |
public void testDegreesUnits_MapReferenceSystem() throws CreateGeometryException, CreateEnvelopeException { |
290 |
for (int j = 0; j < csSymbols.size(); j++) { |
291 |
CartographicSupport symbol = (CartographicSupport)csSymbols.get(j); |
292 |
|
293 |
MapContext mc = AllTests.newMapContext(AllTests.TEST_DEFAULT_PROJECTION); |
294 |
ViewPort viewPort = mc.getViewPort(); |
295 |
|
296 |
int unit = 8; |
297 |
Dimension dim = new Dimension(600, 600); |
298 |
viewPort.setImageSize(dim); |
299 |
|
300 |
|
301 |
/*
|
302 |
* will test with several extents but in the same map image size, so
|
303 |
* the scale issue is exercised as well.
|
304 |
*/
|
305 |
for (int i = 0; i < zooms.length; i++) { |
306 |
Envelope extent = geomManager.createEnvelope(-30, -30,dim.getWidth()/zooms[i]-30, dim.getHeight()/zooms[i]-30, SUBTYPES.GEOM2D); |
307 |
|
308 |
viewPort.setMapUnits(unit); |
309 |
viewPort.setEnvelope(extent); |
310 |
|
311 |
|
312 |
String name = ((IPersistence) symbol).getClassName().substring(
|
313 |
((IPersistence) symbol).getClassName().lastIndexOf('.')+1, |
314 |
((IPersistence) symbol).getClassName().length()); |
315 |
|
316 |
CartographicSupport csSym = (CartographicSupport) symbol; |
317 |
csSym.setReferenceSystem(CartographicSupport.WORLD); |
318 |
double size = 30; |
319 |
|
320 |
csSym.setUnit(unit); |
321 |
|
322 |
|
323 |
|
324 |
if (symbol instanceof IMarkerSymbol) { |
325 |
|
326 |
IMarkerSymbol markerSym = (IMarkerSymbol) symbol; |
327 |
markerSym.setSize(size); |
328 |
csSym.toCartographicSize( |
329 |
viewPort, |
330 |
CompatLocator.getGraphicsUtils().getScreenDPI(), |
331 |
geomManager.createPoint( |
332 |
viewPort.getAdjustedExtent().getCenter(0),
|
333 |
viewPort.getAdjustedExtent().getCenter(1),
|
334 |
SUBTYPES.GEOM2D |
335 |
) |
336 |
); |
337 |
double mySize = markerSym.getSize();
|
338 |
assertTrue("The Symbol '"+name+"' failed computing cartographic size. " + |
339 |
"It returned "+markerSym.getSize()+" when expecting "+ |
340 |
size+"*"+zooms[i]+"="+size*zooms[i], Math.abs(mySize-size*zooms[i]) <= TOL ); |
341 |
} |
342 |
|
343 |
if (symbol instanceof ILineSymbol) { |
344 |
|
345 |
ILineSymbol lineSym = (ILineSymbol) symbol; |
346 |
lineSym.setLineWidth(size); |
347 |
csSym.toCartographicSize( |
348 |
viewPort, |
349 |
CompatLocator.getGraphicsUtils().getScreenDPI(), |
350 |
geomManager.createPoint( |
351 |
viewPort.getAdjustedExtent().getCenter(0),
|
352 |
viewPort.getAdjustedExtent().getCenter(1),
|
353 |
SUBTYPES.GEOM2D |
354 |
) |
355 |
); |
356 |
double mySize = lineSym.getLineStyle().getLineWidth();
|
357 |
assertTrue("The Symbol '"+name+"' failed computing cartographic size. " + |
358 |
"It returned "+mySize+" when expecting "+ |
359 |
size+"*"+zooms[i]+"="+size*zooms[i], Math.abs(mySize-size*zooms[i]) <= TOL ); |
360 |
} |
361 |
|
362 |
if (symbol instanceof IFillSymbol) { |
363 |
// this tests if symbol applies the cartographic support to its
|
364 |
// outline, since is the only thing that may be resized
|
365 |
IFillSymbol fillSym = (IFillSymbol) symbol; |
366 |
if (fillSym.getOutline() == null) { |
367 |
fillSym.setOutline(SymbologyFactory.createDefaultLineSymbol()); |
368 |
} |
369 |
|
370 |
fillSym.getOutline().setLineWidth(size); |
371 |
|
372 |
csSym.toCartographicSize( |
373 |
viewPort, |
374 |
CompatLocator.getGraphicsUtils().getScreenDPI(), |
375 |
geomManager.createPoint( |
376 |
viewPort.getAdjustedExtent().getCenter(0),
|
377 |
viewPort.getAdjustedExtent().getCenter(1),
|
378 |
SUBTYPES.GEOM2D |
379 |
) |
380 |
); |
381 |
double mySize = fillSym.getOutline().getLineStyle().getLineWidth();
|
382 |
assertTrue("The Symbol '"+name+"' failed computing cartographic size. " + |
383 |
"It returned "+fillSym.getOutline().getLineWidth()+" when expecting "+ |
384 |
size+"*"+zooms[i]+"="+size*zooms[i], Math.abs(mySize-size*zooms[i]) <= TOL ); |
385 |
} |
386 |
|
387 |
} |
388 |
} |
389 |
} |
390 |
|
391 |
|
392 |
public void testKilometersUnits_MapReferenceSystem() throws CreateGeometryException, CreateEnvelopeException { |
393 |
for (int j = 0; j < csSymbols.size(); j++) { |
394 |
CartographicSupport symbol = (CartographicSupport)csSymbols.get(j); |
395 |
MapContext mc = AllTests.newMapContext(AllTests.TEST_DEFAULT_MERCATOR_PROJECTION); |
396 |
ViewPort viewPort = mc.getViewPort(); |
397 |
|
398 |
int unit = 0; |
399 |
Dimension dim = new Dimension(60, 60); |
400 |
viewPort.setImageSize(dim); |
401 |
|
402 |
|
403 |
/*
|
404 |
* will test with several extents but in the same map image size, so
|
405 |
* the scale issue is exercised as well.
|
406 |
*/
|
407 |
for (int i = 0; i < zooms.length; i++) { |
408 |
Envelope extent = geomManager.createEnvelope(-30, -30, dim.getWidth()/zooms[i]-30, dim.getHeight()/zooms[i]-30, SUBTYPES.GEOM2D); |
409 |
|
410 |
viewPort.setMapUnits(unit); |
411 |
viewPort.setEnvelope(extent); |
412 |
|
413 |
|
414 |
String name = ((IPersistence) symbol).getClassName().substring(
|
415 |
((IPersistence) symbol).getClassName().lastIndexOf('.')+1, |
416 |
((IPersistence) symbol).getClassName().length()); |
417 |
|
418 |
CartographicSupport csSym = (CartographicSupport) symbol; |
419 |
csSym.setReferenceSystem(CartographicSupport.WORLD); |
420 |
double size = 30; |
421 |
|
422 |
csSym.setUnit(unit); |
423 |
|
424 |
|
425 |
|
426 |
|
427 |
if (symbol instanceof IMarkerSymbol) { |
428 |
|
429 |
IMarkerSymbol markerSym = (IMarkerSymbol) symbol; |
430 |
markerSym.setSize(size); |
431 |
csSym.toCartographicSize( |
432 |
viewPort, |
433 |
CompatLocator.getGraphicsUtils().getScreenDPI(), |
434 |
geomManager.createPoint( |
435 |
viewPort.getAdjustedExtent().getCenter(0),
|
436 |
viewPort.getAdjustedExtent().getCenter(1),
|
437 |
SUBTYPES.GEOM2D |
438 |
) |
439 |
); |
440 |
double mySize = markerSym.getSize();
|
441 |
assertTrue("The Symbol '"+name+"' failed computing cartographic size. " + |
442 |
"It returned "+markerSym.getSize()+" when expecting "+ |
443 |
size+"*"+zooms[i]+"="+size*zooms[i], Math.abs(mySize-size*zooms[i]) <= TOL ); |
444 |
} |
445 |
|
446 |
if (symbol instanceof ILineSymbol) { |
447 |
|
448 |
ILineSymbol lineSym = (ILineSymbol) symbol; |
449 |
lineSym.setLineWidth(size); |
450 |
csSym.toCartographicSize( |
451 |
viewPort, |
452 |
CompatLocator.getGraphicsUtils().getScreenDPI(), |
453 |
geomManager.createPoint( |
454 |
viewPort.getAdjustedExtent().getCenter(0),
|
455 |
viewPort.getAdjustedExtent().getCenter(1),
|
456 |
SUBTYPES.GEOM2D |
457 |
) |
458 |
); |
459 |
double mySize = lineSym.getLineStyle().getLineWidth();
|
460 |
assertTrue("The Symbol '"+name+"' failed computing cartographic size. " + |
461 |
"It returned "+lineSym.getLineWidth()+" when expecting "+ |
462 |
size+"*"+zooms[i]+"="+size*zooms[i], Math.abs(mySize-size*zooms[i]) <= TOL ); |
463 |
} |
464 |
|
465 |
if (symbol instanceof IFillSymbol) { |
466 |
// this tests if symbol applies the cartographic support to its
|
467 |
// outline, since is the only thing that may be resized
|
468 |
IFillSymbol fillSym = (IFillSymbol) symbol; |
469 |
if (fillSym.getOutline() == null) { |
470 |
fillSym.setOutline(SymbologyFactory.createDefaultLineSymbol()); |
471 |
} |
472 |
|
473 |
fillSym.getOutline().setLineWidth(size); |
474 |
|
475 |
csSym.toCartographicSize( |
476 |
viewPort, |
477 |
CompatLocator.getGraphicsUtils().getScreenDPI(), |
478 |
geomManager.createPoint( |
479 |
viewPort.getAdjustedExtent().getCenter(0),
|
480 |
viewPort.getAdjustedExtent().getCenter(1),
|
481 |
SUBTYPES.GEOM2D |
482 |
) |
483 |
); |
484 |
double mySize = fillSym.getOutline().getLineStyle().getLineWidth();
|
485 |
assertTrue("The Symbol '"+name+"' failed computing cartographic size. " + |
486 |
"It returned "+fillSym.getOutline().getLineWidth()+" when expecting "+ |
487 |
size+"*"+zooms[i]+"="+size*zooms[i], Math.abs(mySize-size*zooms[i]) <= TOL ); |
488 |
} |
489 |
|
490 |
} |
491 |
} |
492 |
|
493 |
} |
494 |
|
495 |
public void testMapInKilometersSymbolInMeters_MapReferenceSystem() throws CreateGeometryException, CreateEnvelopeException { |
496 |
for (int j = 0; j < csSymbols.size(); j++) { |
497 |
CartographicSupport symbol = (CartographicSupport)csSymbols.get(j); |
498 |
|
499 |
MapContext mc = AllTests.newMapContext(AllTests.TEST_DEFAULT_MERCATOR_PROJECTION); |
500 |
ViewPort viewPort = mc.getViewPort(); |
501 |
|
502 |
int mapUnit = 0; |
503 |
int symbolUnit = 1; |
504 |
Dimension dim = new Dimension(60, 60); |
505 |
viewPort.setImageSize(dim); |
506 |
|
507 |
|
508 |
/*
|
509 |
* will test with several extents but in the same map image size, so
|
510 |
* the scale issue is exercised as well.
|
511 |
*/
|
512 |
for (int i = 0; i < zooms.length; i++) { |
513 |
Envelope extent = geomManager.createEnvelope(-30, -30, dim.getWidth()/zooms[i]-30, dim.getHeight()/zooms[i]-30, SUBTYPES.GEOM2D); |
514 |
viewPort.setMapUnits(mapUnit); |
515 |
viewPort.setEnvelope(extent); |
516 |
double size = 30; |
517 |
|
518 |
|
519 |
String name = ((IPersistence) symbol).getClassName().substring(
|
520 |
((IPersistence) symbol).getClassName().lastIndexOf('.')+1, |
521 |
((IPersistence) symbol).getClassName().length()); |
522 |
|
523 |
|
524 |
CartographicSupport csSym = (CartographicSupport) symbol; |
525 |
csSym.setReferenceSystem(CartographicSupport.WORLD); |
526 |
|
527 |
csSym.setUnit(symbolUnit); |
528 |
|
529 |
if (symbol instanceof IMarkerSymbol) { |
530 |
|
531 |
IMarkerSymbol markerSym = (IMarkerSymbol) symbol; |
532 |
markerSym.setSize(size*MapContext.CHANGEM[mapUnit]); // 30m*1000 = 30 km
|
533 |
csSym.toCartographicSize( |
534 |
viewPort, |
535 |
CompatLocator.getGraphicsUtils().getScreenDPI(), |
536 |
geomManager.createPoint( |
537 |
viewPort.getAdjustedExtent().getCenter(0),
|
538 |
viewPort.getAdjustedExtent().getCenter(1),
|
539 |
SUBTYPES.GEOM2D |
540 |
) |
541 |
); |
542 |
double mySize = markerSym.getSize();
|
543 |
assertTrue("The Symbol '"+name+"' failed computing cartographic size. " + |
544 |
"It returned "+markerSym.getSize()+" when expecting "+ |
545 |
size+"*"+zooms[i]+"="+size*zooms[i], Math.abs(mySize-size*zooms[i]) <= TOL ); |
546 |
} |
547 |
|
548 |
if (symbol instanceof ILineSymbol) { |
549 |
|
550 |
ILineSymbol lineSym = (ILineSymbol) symbol; |
551 |
lineSym.setLineWidth(size*MapContext.CHANGEM[mapUnit]); // 30m*1000 = 30 km
|
552 |
csSym.toCartographicSize( |
553 |
viewPort, |
554 |
CompatLocator.getGraphicsUtils().getScreenDPI(), |
555 |
geomManager.createPoint( |
556 |
viewPort.getAdjustedExtent().getCenter(0),
|
557 |
viewPort.getAdjustedExtent().getCenter(1),
|
558 |
SUBTYPES.GEOM2D |
559 |
) |
560 |
); |
561 |
double mySize = lineSym.getLineStyle().getLineWidth();
|
562 |
assertTrue("The Symbol '"+name+"' failed computing cartographic size. " + |
563 |
"It returned "+lineSym.getLineWidth()+" when expecting "+ |
564 |
size+"*"+zooms[i]+"="+size*zooms[i], Math.abs(mySize-size*zooms[i]) <= TOL ); |
565 |
} |
566 |
|
567 |
if (symbol instanceof IFillSymbol) { |
568 |
// this tests if symbol applies the cartographic support to its
|
569 |
// outline, since is the only thing that may be resized
|
570 |
IFillSymbol fillSym = (IFillSymbol) symbol; |
571 |
if (fillSym.getOutline() == null) { |
572 |
fillSym.setOutline(SymbologyFactory.createDefaultLineSymbol()); |
573 |
} |
574 |
|
575 |
fillSym.getOutline().setLineWidth(size*MapContext.CHANGEM[mapUnit]); |
576 |
|
577 |
csSym.toCartographicSize( |
578 |
viewPort, |
579 |
CompatLocator.getGraphicsUtils().getScreenDPI(), |
580 |
geomManager.createPoint( |
581 |
viewPort.getAdjustedExtent().getCenter(0),
|
582 |
viewPort.getAdjustedExtent().getCenter(1),
|
583 |
SUBTYPES.GEOM2D |
584 |
) |
585 |
); |
586 |
double mySize = fillSym.getOutline().getLineStyle().getLineWidth();
|
587 |
assertTrue("The Symbol '"+name+"' failed computing cartographic size. " + |
588 |
"It returned "+fillSym.getOutline().getLineWidth()+" when expecting "+ |
589 |
size+"*"+zooms[i]+"="+size*zooms[i], Math.abs(mySize-size*zooms[i]) <= TOL ); |
590 |
} |
591 |
|
592 |
} |
593 |
} |
594 |
} |
595 |
|
596 |
} |