* Update the rectangle, and perhaps the entire map if needed.
*/
private void updatePov() {
MapView mapView = getMapModel().getMapView();
WorldViewTransformer transformer = new WorldViewTransformer(mapView);
Bbox targetBox = targetMap.getMapModel().getMapView().getBounds();
Bbox overviewBox = mapView.getBounds();
// check if bounds are valid
if (Double.isNaN(overviewBox.getX())) {
return;
}
// zoom if current view is too small
if (dynamicOverview && !overviewBox.contains(targetBox)) {
// mapView.applyBounds(overviewBox.union(targetBox), MapView.ZoomOption.LEVEL_FIT);
// super.onMapViewChanged(null);
}
// calculate boxSize
Coordinate viewBegin = transformer.worldToView(targetBox.getOrigin());
Coordinate viewEnd = transformer.worldToView(targetBox.getEndPoint());
double width = Math.abs(viewEnd.getX() - viewBegin.getX());
double height = Math.abs(viewEnd.getY() - viewBegin.getY());
viewBegin.setY(viewBegin.getY() - height);
// show recticle or box
if (width < 20) {
if (null != targetRectangle) {
render(targetRectangle, RenderGroup.SCREEN, RenderStatus.DELETE);
targetRectangle = null;
}
if (null == targetReticle) {
targetReticle = new Image("targetReticle");
targetReticle.setHref(Geomajas.getIsomorphicDir() + TARGET_RETICLE_IMAGE);
targetReticle.setBounds(new Bbox(0, 0, 21, 21));
}
double x = viewBegin.getX() + (width / 2) - 10;
double y = viewBegin.getY() + (width / 2) - 10;
targetReticle.getBounds().setX(x);
targetReticle.getBounds().setY(y);
render(targetReticle, RenderGroup.SCREEN, RenderStatus.UPDATE);
} else {
if (null != targetReticle) {
render(targetReticle, RenderGroup.SCREEN, RenderStatus.DELETE);
targetReticle = null;
}
if (null == targetRectangle) {
targetRectangle = new Rectangle("targetRect");
targetRectangle.setStyle(rectangleStyle);
}
targetRectangle.setBounds(new Bbox(viewBegin.getX(), viewBegin.getY(), width, height));
render(targetRectangle, RenderGroup.SCREEN, RenderStatus.UPDATE);
}
}