Revision 245
trunk/org.gvsig.app.document.layout2.app/org.gvsig.app.document.layout2.app.mainplugin/src/main/java/org/gvsig/app/project/documents/layout/fframes/FFrameView.java | ||
---|---|---|
76 | 76 |
import org.gvsig.gui.beans.Messages; |
77 | 77 |
import org.gvsig.tools.ToolsLocator; |
78 | 78 |
import org.gvsig.tools.dynobject.DynStruct; |
79 |
import org.gvsig.tools.locator.LocatorException; |
|
79 | 80 |
import org.gvsig.tools.persistence.PersistenceManager; |
80 | 81 |
import org.gvsig.tools.persistence.PersistentState; |
81 | 82 |
import org.gvsig.tools.persistence.exception.PersistenceException; |
... | ... | |
154 | 155 |
protected OwnMapContextListener ownMapContextListener; |
155 | 156 |
private boolean b_hasToc = true; |
156 | 157 |
protected static final GeometryManager geomManager = GeometryLocator.getGeometryManager(); |
158 |
protected Envelope oldViewEnvelope = null; |
|
157 | 159 |
|
158 | 160 |
/** |
159 | 161 |
* When we load a FFrameview from project, it will receive a wrong |
... | ... | |
210 | 212 |
* @param r Envelope to be set |
211 | 213 |
*/ |
212 | 214 |
public void setNewEnvelope(Envelope r) { |
215 |
if (getView()!=null) { |
|
216 |
oldViewEnvelope = getView().getMapContext().getViewPort().getAdjustedEnvelope(); |
|
217 |
} |
|
213 | 218 |
getMapContext().getViewPort().setEnvelope(r); |
214 | 219 |
updateScaleCtrl(); |
215 | 220 |
} |
... | ... | |
1090 | 1095 |
syncExtents = synced; |
1091 | 1096 |
resetListeners(); |
1092 | 1097 |
} |
1098 |
|
|
1099 |
/** |
|
1100 |
* Returns true if the newEnvelope represents a pan operation on oldEnvelope, |
|
1101 |
* (both extents have the same height and width) |
|
1102 |
*/ |
|
1103 |
public static boolean isPan(Envelope oldEnvelope, Envelope newEnvelope) { |
|
1104 |
if (oldEnvelope!=null && newEnvelope!=null) { |
|
1105 |
double toleranceX = 0.00000001*Math.min(oldEnvelope.getLength(0), newEnvelope.getLength(0)); |
|
1106 |
double toleranceY = 0.00000001*Math.min(oldEnvelope.getLength(1), newEnvelope.getLength(1)); |
|
1107 |
|
|
1108 |
// we consider it to be a pan if both lengths are equal |
|
1109 |
// (we use tolerance to avoid direct comparison of double values) |
|
1110 |
if ( ((oldEnvelope.getLength(0)-newEnvelope.getLength(0))<toleranceX) |
|
1111 |
&& ((oldEnvelope.getLength(1)-newEnvelope.getLength(1))<toleranceY) ) { |
|
1112 |
return true; |
|
1113 |
} |
|
1114 |
} |
|
1115 |
return false; |
|
1116 |
} |
|
1117 |
|
|
1118 |
/** |
|
1119 |
* Calculates the new extent for the FFrame. It is necessary to avoid |
|
1120 |
* scale changes when a pan is triggered from the view, as the different |
|
1121 |
* size factors from View/FFrameView introduces scale changes even for |
|
1122 |
* pans |
|
1123 |
* |
|
1124 |
* @param newEnvelope |
|
1125 |
* @return |
|
1126 |
*/ |
|
1127 |
protected Envelope calculateNewExtent(Envelope newEnvelope) { |
|
1128 |
if (isPan(oldViewEnvelope, newEnvelope)) { |
|
1129 |
Envelope envelope = getMapContext().getViewPort().getAdjustedEnvelope(); |
|
1130 |
double shiftX = newEnvelope.getMinimum(0) - oldViewEnvelope.getMinimum(0); |
|
1131 |
double shiftY = newEnvelope.getMinimum(1) - oldViewEnvelope.getMinimum(1); |
|
1093 | 1132 |
|
1133 |
double minX = envelope.getMinimum(0) + shiftX; |
|
1134 |
double minY = envelope.getMinimum(1) + shiftY; |
|
1135 |
double maxX = envelope.getMaximum(0) + shiftX; |
|
1136 |
double maxY = envelope.getMaximum(1) + shiftY; |
|
1137 |
try { |
|
1138 |
return GeometryLocator.getGeometryManager().createEnvelope(minX, minY, maxX, maxY, SUBTYPES.GEOM2D); |
|
1139 |
} |
|
1140 |
catch (LocatorException e) {} |
|
1141 |
catch (CreateEnvelopeException e) {} |
|
1142 |
|
|
1143 |
} |
|
1144 |
return newEnvelope; |
|
1145 |
} |
|
1146 |
|
|
1094 | 1147 |
private class ViewDocListener |
1095 | 1148 |
implements ViewPortListener, LegendListener, LayerCollectionListener, AtomicEventListener { |
1096 | 1149 |
|
... | ... | |
1102 | 1155 |
} |
1103 | 1156 |
if (getMapContext()!=null) { |
1104 | 1157 |
b_updating = true; |
1105 |
getMapContext().getViewPort().setEnvelope(e.getNewExtent()); |
|
1158 |
getMapContext().getViewPort().setEnvelope(calculateNewExtent(e.getNewExtent())); |
|
1159 |
oldViewEnvelope = getView().getMapContext().getViewPort().getAdjustedEnvelope(); |
|
1106 | 1160 |
updateScaleCtrl(); |
1107 | 1161 |
invalidateLayout(); |
1108 | 1162 |
b_updating = false; |
... | ... | |
1214 | 1268 |
b_updating = true; |
1215 | 1269 |
if (getExtentSynced()){ |
1216 | 1270 |
getView().getMapContext().getViewPort().setEnvelope(e.getNewExtent()); |
1271 |
oldViewEnvelope = getView().getMapContext().getViewPort().getAdjustedEnvelope(); |
|
1217 | 1272 |
} |
1218 | 1273 |
updateScaleCtrl(); |
1219 | 1274 |
invalidateLayout(); |
Also available in: Unified diff