65 |
import org.geotools.renderer.label.LabelCacheImpl; |
import org.geotools.renderer.label.LabelCacheImpl; |
66 |
import org.geotools.renderer.lite.LabelCache; |
import org.geotools.renderer.lite.LabelCache; |
67 |
import org.geotools.renderer.lite.StreamingRenderer; |
import org.geotools.renderer.lite.StreamingRenderer; |
|
import org.geotools.renderer.shape.ShapefileRenderer; |
|
68 |
import org.opengis.filter.FilterFactory2; |
import org.opengis.filter.FilterFactory2; |
69 |
import org.opengis.referencing.crs.CoordinateReferenceSystem; |
import org.opengis.referencing.crs.CoordinateReferenceSystem; |
70 |
|
|
230 |
Map<Object, Object> hints = new HashMap<Object, Object>(); |
Map<Object, Object> hints = new HashMap<Object, Object>(); |
231 |
|
|
232 |
this.renderer = renderer; |
this.renderer = renderer; |
233 |
|
//MS: Apply hint also for ShapeFileRenderer |
234 |
if (renderer instanceof StreamingRenderer |
// if (renderer instanceof StreamingRenderer) { |
|
|| renderer instanceof ShapefileRenderer) { |
|
235 |
hints = renderer.getRendererHints(); |
hints = renderer.getRendererHints(); |
236 |
if (hints == null) { |
if (hints == null) { |
237 |
hints = new HashMap<Object, Object>(); |
hints = new HashMap<Object, Object>(); |
246 |
hints.put("memoryPreloadingEnabled", Boolean.TRUE); |
hints.put("memoryPreloadingEnabled", Boolean.TRUE); |
247 |
|
|
248 |
renderer.setRendererHints(hints); |
renderer.setRendererHints(hints); |
249 |
} |
// } |
250 |
|
|
251 |
if (this.context != null) { |
if (this.context != null) { |
252 |
this.renderer.setContext(this.context); |
this.renderer.setContext(this.context); |
324 |
reset = false; /* forget about the reset */ |
reset = false; /* forget about the reset */ |
325 |
oldRect = r; /* store what the current size is */ |
oldRect = r; /* store what the current size is */ |
326 |
|
|
327 |
mapArea = fixAspectRatio(r, mapArea, false); |
mapArea = JTSUtil.fixAspectRatio(r, mapArea, false); |
328 |
} |
} |
329 |
} |
} |
330 |
|
|
360 |
((Graphics2D) g).drawImage(baseImage, 0, 0, this); |
((Graphics2D) g).drawImage(baseImage, 0, 0, this); |
361 |
} |
} |
362 |
|
|
|
/** |
|
|
* Returns an {@link Envelope} that has the same aspect ratio as the given rectangle |
|
|
* @param grow |
|
|
* If <code>true</code>, than the area will be enlarged to match |
|
|
* the aspect ratio. If <code>false</code>, it will only shrink. |
|
|
*/ |
|
|
private Envelope fixAspectRatio(final Rectangle r, final Envelope mapArea, |
|
|
boolean grow) { |
|
|
|
|
|
if (mapArea == null) { |
|
|
LOGGER.warn("mapArea has been null in method fixAspectRatio, returning an unmodified "); |
|
|
} |
|
|
|
|
|
final double mapWidth = mapArea.getWidth(); /* get the extent of the map */ |
|
|
final double mapHeight = mapArea.getHeight(); |
|
|
final double scaleX = r.getWidth() / mapArea.getWidth(); /* |
|
|
* calculate the |
|
|
* new scale |
|
|
*/ |
|
|
|
|
|
final double scaleY = r.getHeight() / mapArea.getHeight(); |
|
|
double scale = 1.0; // stupid compiler! |
|
|
|
|
|
if ((grow && scaleX < scaleY) || (!grow && scaleX > scaleY)) { |
|
|
scale = scaleX; |
|
|
} else { |
|
|
scale = scaleY; |
|
|
} |
|
|
|
|
|
/* calculate the difference in width and height of the new extent */ |
|
|
final double deltaX = /* Math.abs */((r.getWidth() / scale) - mapWidth); |
|
|
final double deltaY = /* Math.abs */((r.getHeight() / scale) - mapHeight); |
|
|
|
|
|
/* |
|
|
* System.out.println("delta x " + deltaX); |
|
|
* System.out.println("delta y " + deltaY); |
|
|
*/ |
|
|
|
|
|
/* create the new extent */ |
|
|
final Coordinate ll = new Coordinate( |
|
|
mapArea.getMinX() - (deltaX / 2.0), mapArea.getMinY() |
|
|
- (deltaY / 2.0)); |
|
|
final Coordinate ur = new Coordinate( |
|
|
mapArea.getMaxX() + (deltaX / 2.0), mapArea.getMaxY() |
|
|
+ (deltaY / 2.0)); |
|
|
|
|
|
return new Envelope(ll, ur); |
|
|
} |
|
|
|
|
363 |
public void mouseClicked(final MouseEvent e) { |
public void mouseClicked(final MouseEvent e) { |
364 |
if (mapArea == null) |
if (mapArea == null) |
365 |
return; |
return; |
868 |
* Correct the aspect Ratio before we check the rest. Otherwise we might |
* Correct the aspect Ratio before we check the rest. Otherwise we might |
869 |
* easily fail. |
* easily fail. |
870 |
*/ |
*/ |
871 |
env = fixAspectRatio(this.getBounds(), env, false); |
env = JTSUtil.fixAspectRatio(this.getBounds(), env, false); |
872 |
|
|
873 |
final double scale = env.getWidth() / getWidth(); |
final double scale = env.getWidth() / getWidth(); |
874 |
final double centerX = env.getMinX() + env.getWidth() / 2.; |
final double centerX = env.getMinX() + env.getWidth() / 2.; |
928 |
|
|
929 |
// LOGGER.debug("and fix aspect ratio"); |
// LOGGER.debug("and fix aspect ratio"); |
930 |
|
|
931 |
newArea = fixAspectRatio(this.getBounds(), newArea, false); |
newArea = JTSUtil.fixAspectRatio(this.getBounds(), newArea, false); |
932 |
} |
} |
933 |
} |
} |
934 |
|
|
950 |
|
|
951 |
// LOGGER.debug("and fix aspect ratio"); |
// LOGGER.debug("and fix aspect ratio"); |
952 |
|
|
953 |
newArea = fixAspectRatio(this.getBounds(), newArea, false); |
newArea = JTSUtil.fixAspectRatio(this.getBounds(), newArea, false); |
954 |
} |
} |
955 |
} |
} |
956 |
|
|
974 |
|
|
975 |
// LOGGER.debug("and fix aspect ratio"); |
// LOGGER.debug("and fix aspect ratio"); |
976 |
|
|
977 |
newArea = fixAspectRatio(this.getBounds(), newArea, false); |
newArea = JTSUtil.fixAspectRatio(this.getBounds(), newArea, false); |
978 |
} |
} |
979 |
} |
} |
980 |
|
|
998 |
|
|
999 |
// LOGGER.debug("and fix aspect ratio"); |
// LOGGER.debug("and fix aspect ratio"); |
1000 |
|
|
1001 |
newArea = fixAspectRatio(this.getBounds(), newArea, false); |
newArea = JTSUtil.fixAspectRatio(this.getBounds(), newArea, false); |
1002 |
} |
} |
1003 |
} |
} |
1004 |
|
|
1076 |
public Envelope getMaxExtend() { |
public Envelope getMaxExtend() { |
1077 |
if (maxExtend == null) { |
if (maxExtend == null) { |
1078 |
try { |
try { |
1079 |
return fixAspectRatio( |
return JTSUtil.fixAspectRatio( |
1080 |
this.getBounds(), |
this.getBounds(), |
1081 |
// Kartenbereich um 10% vergroessern |
// Kartenbereich um 10% vergroessern |
1082 |
JTSUtil.expandEnvelope(context.getLayerBounds(), 0.1), |
JTSUtil.expandEnvelope(context.getLayerBounds(), 0.1), |
1084 |
); |
); |
1085 |
} catch (IOException e) { |
} catch (IOException e) { |
1086 |
LOGGER.warn( |
LOGGER.warn( |
1087 |
"maxExtend == null; faild to getLayerBounds of context", |
"maxExtend == null; failed to getLayerBounds of context", |
1088 |
e); |
e); |
1089 |
} |
} |
1090 |
} |
} |