Revision 45941
trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.mapcontext/org.gvsig.fmap.mapcontext.api/src/main/java/org/gvsig/fmap/mapcontext/MapContext.java | ||
---|---|---|
46 | 46 |
import org.gvsig.fmap.dal.DataStore; |
47 | 47 |
import org.gvsig.fmap.dal.exception.ReadException; |
48 | 48 |
import org.gvsig.fmap.dal.feature.FeatureStoreNotification; |
49 |
import org.gvsig.fmap.geom.Geometry; |
|
49 | 50 |
import org.gvsig.fmap.geom.Geometry.SUBTYPES; |
50 | 51 |
import org.gvsig.fmap.geom.GeometryLocator; |
51 | 52 |
import org.gvsig.fmap.geom.GeometryManager; |
53 |
import org.gvsig.fmap.geom.GeometryUtils; |
|
52 | 54 |
import org.gvsig.fmap.geom.exception.CreateEnvelopeException; |
53 | 55 |
import org.gvsig.fmap.geom.primitive.Envelope; |
56 |
import org.gvsig.fmap.geom.primitive.Point; |
|
54 | 57 |
import org.gvsig.fmap.mapcontext.events.ErrorEvent; |
55 | 58 |
import org.gvsig.fmap.mapcontext.events.listeners.AtomicEventListener; |
56 | 59 |
import org.gvsig.fmap.mapcontext.events.listeners.ErrorListener; |
... | ... | |
165 | 168 |
|
166 | 169 |
private static final Logger LOGGER = LoggerFactory.getLogger(MapContext.class); |
167 | 170 |
|
171 |
private long scaleToUseWhenEnvelopeCollapse = 10000000; |
|
172 |
|
|
168 | 173 |
/** |
169 | 174 |
* <p> |
170 | 175 |
* Determines the number of frames.</p> |
... | ... | |
1183 | 1188 |
public ViewPort getViewPort() { |
1184 | 1189 |
return viewPort; |
1185 | 1190 |
} |
1186 |
|
|
1191 |
|
|
1187 | 1192 |
/** |
1188 | 1193 |
* <p> |
1189 | 1194 |
* Sets a {@link ViewPort ViewPort} with the drawing information of this |
... | ... | |
1218 | 1223 |
* |
1219 | 1224 |
* @param extent the extent of the new zoom |
1220 | 1225 |
*/ |
1221 |
public void zoomToEnvelope(Envelope extent) {
|
|
1222 |
if (extent != null && !extent.isEmpty()) {
|
|
1223 |
getViewPort().setEnvelope(extent);
|
|
1226 |
public void zoomToEnvelope(Envelope env) {
|
|
1227 |
if (env == null || env.isEmpty()) {
|
|
1228 |
return;
|
|
1224 | 1229 |
} |
1230 |
if( env.isCollapsed(Geometry.SUBTYPES.GEOM2D) ) { |
|
1231 |
// El envelop ha colapsado en X e Y. |
|
1232 |
// Fijamos la escala por defecto para cuando colapsa y centramos |
|
1233 |
// sobre el centro del envelop. |
|
1234 |
|
|
1235 |
this.setScaleView(this.getScaleToUseWhenEnvelopeCollapse()); |
|
1236 |
|
|
1237 |
Envelope curenv = viewPort.getEnvelope(); |
|
1238 |
double halfWidth = curenv.getLength(Geometry.DIMENSIONS.X) / 2; |
|
1239 |
double halfHeight = curenv.getLength(Geometry.DIMENSIONS.Y) / 2; |
|
1240 |
double centerx = env.getCenter(Geometry.DIMENSIONS.X); |
|
1241 |
double centery = env.getCenter(Geometry.DIMENSIONS.Y); |
|
1242 |
|
|
1243 |
Point lowerCorner = GeometryUtils.createPoint(halfWidth + centerx, halfHeight + centery); |
|
1244 |
Point upperCorner = GeometryUtils.createPoint(halfWidth - centerx, halfHeight - centery); |
|
1245 |
|
|
1246 |
env.setLowerCorner(lowerCorner); |
|
1247 |
env.setUpperCorner(upperCorner); |
|
1248 |
} |
|
1249 |
this.viewPort.setEnvelope(env); |
|
1225 | 1250 |
} |
1226 | 1251 |
|
1227 | 1252 |
/** |
... | ... | |
1843 | 1868 |
}; |
1844 | 1869 |
} |
1845 | 1870 |
|
1871 |
public long getScaleToUseWhenEnvelopeCollapse() { |
|
1872 |
return this.scaleToUseWhenEnvelopeCollapse; |
|
1873 |
} |
|
1874 |
|
|
1875 |
public void setScaleToUseWhenEnvelopeCollapse(long scale) { |
|
1876 |
this.scaleToUseWhenEnvelopeCollapse = scale; |
|
1877 |
} |
|
1878 |
|
|
1846 | 1879 |
} |
trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.geometry/org.gvsig.fmap.geometry.api/src/main/java/org/gvsig/fmap/geom/primitive/Envelope.java | ||
---|---|---|
211 | 211 |
public void setProjectionIffNull(IProjection projection); |
212 | 212 |
|
213 | 213 |
public IProjection getProjection(); |
214 |
|
|
215 |
public boolean isCollapsed(); |
|
216 |
|
|
217 |
public boolean isCollapsed(int subtype); |
|
214 | 218 |
} |
trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.geometry/org.gvsig.fmap.geometry.jts/src/main/java/org/gvsig/fmap/geom/jts/primitive/DefaultEnvelope.java | ||
---|---|---|
440 | 440 |
public void setProjection(IProjection projection) { |
441 | 441 |
this.projection = projection; |
442 | 442 |
} |
443 |
|
|
444 |
@Override |
|
445 |
public boolean isCollapsed() { |
|
446 |
switch(this.getDimension()) { |
|
447 |
case 3: |
|
448 |
return this.isCollapsed(Geometry.SUBTYPES.GEOM3D); |
|
449 |
default: |
|
450 |
case 2: |
|
451 |
return this.isCollapsed(Geometry.SUBTYPES.GEOM2D); |
|
452 |
} |
|
453 |
} |
|
443 | 454 |
|
455 |
@Override |
|
456 |
public boolean isCollapsed(int subtype) { |
|
457 |
if( this.isEmpty ) { |
|
458 |
return true; |
|
459 |
} |
|
460 |
switch(subtype) { |
|
461 |
case Geometry.SUBTYPES.GEOM3DM: |
|
462 |
int m = this.getDimension()-1; |
|
463 |
if( this.getLength(m)!=0 ) { |
|
464 |
return false; |
|
465 |
} |
|
466 |
case Geometry.SUBTYPES.GEOM2DM: |
|
467 |
case Geometry.SUBTYPES.GEOM3D: |
|
468 |
if( this.getLength(DIMENSIONS.Z)!=0 ) { |
|
469 |
return false; |
|
470 |
} |
|
471 |
default: |
|
472 |
case Geometry.SUBTYPES.GEOM2D: |
|
473 |
if( this.getLength(DIMENSIONS.X)!=0 ) { |
|
474 |
return false; |
|
475 |
} |
|
476 |
if( this.getLength(DIMENSIONS.Y)!=0 ) { |
|
477 |
return false; |
|
478 |
} |
|
479 |
return true; |
|
480 |
} |
|
481 |
} |
|
482 |
|
|
444 | 483 |
} |
trunk/org.gvsig.desktop/org.gvsig.desktop.plugin/org.gvsig.app/org.gvsig.app.mainplugin/src/main/java/org/gvsig/app/project/documents/view/DefaultViewDocument.java | ||
---|---|---|
94 | 94 |
// Si nadie le ha asignado un envelope mientras se |
95 | 95 |
// calculaba el inicial le asignamos el calculado. |
96 | 96 |
if (viewPort.getEnvelope() == null) { |
97 |
viewPort.setEnvelope(envelope); |
|
97 |
getMapContext().zoomToEnvelope(envelope); // viewPort.setEnvelope(envelope);
|
|
98 | 98 |
} |
99 | 99 |
application.message( |
100 | 100 |
"", |
trunk/org.gvsig.desktop/org.gvsig.desktop.plugin/org.gvsig.app/org.gvsig.app.mainplugin/src/main/java/org/gvsig/app/extension/ZoomToSelectExtension.java | ||
---|---|---|
31 | 31 |
import org.gvsig.app.project.documents.view.gui.IView; |
32 | 32 |
import org.gvsig.fmap.dal.feature.FeatureSelection; |
33 | 33 |
import org.gvsig.fmap.dal.feature.FeatureStore; |
34 |
import org.gvsig.fmap.dal.feature.FeatureType; |
|
35 | 34 |
import org.gvsig.fmap.geom.primitive.Envelope; |
36 | 35 |
import org.gvsig.fmap.mapcontext.MapContext; |
37 | 36 |
import org.gvsig.fmap.mapcontext.layers.FLayer; |
38 | 37 |
import org.gvsig.fmap.mapcontext.layers.vectorial.FLyrVect; |
39 | 38 |
import org.gvsig.tools.exception.BaseException; |
40 |
import org.slf4j.Logger; |
|
41 |
import org.slf4j.LoggerFactory; |
|
42 | 39 |
|
43 | 40 |
/** |
44 | 41 |
* Extensi?n de zoom a lo seleccionado teniendo como ventana activa una vista. |
45 | 42 |
* |
46 | 43 |
*/ |
44 |
@SuppressWarnings("UseSpecificCatch") |
|
47 | 45 |
public class ZoomToSelectExtension extends Extension { |
48 | 46 |
|
49 |
private static final Logger logger = LoggerFactory |
|
50 |
.getLogger(ZoomToSelectExtension.class); |
|
47 |
// private static final Logger logger = LoggerFactory.getLogger(ZoomToSelectExtension.class); |
|
51 | 48 |
|
49 |
@Override |
|
52 | 50 |
public void initialize() { |
53 | 51 |
IconThemeHelper.registerIcon("action", "view-navigation-zoom-to-selection", this); |
54 | 52 |
} |
55 | 53 |
|
54 |
@Override |
|
56 | 55 |
public void execute(String s) { |
57 | 56 |
ApplicationManager application = ApplicationLocator.getManager(); |
58 | 57 |
|
... | ... | |
62 | 61 |
} |
63 | 62 |
ViewDocument document = view.getViewDocument(); |
64 | 63 |
MapContext mapa = document.getMapContext(); |
65 |
Envelope selectedExtent = null;
|
|
64 |
Envelope selectedExtent; |
|
66 | 65 |
try { |
67 | 66 |
selectedExtent = mapa.getSelectionBounds(); |
68 |
mapa.getViewPort().setEnvelope(selectedExtent);
|
|
67 |
mapa.zoomToEnvelope(selectedExtent);
|
|
69 | 68 |
} catch (BaseException e) { |
70 | 69 |
String msg = "Can't zoom to the seleccion."; |
71 | 70 |
logger.warn(msg, e); |
... | ... | |
73 | 72 |
} |
74 | 73 |
} |
75 | 74 |
|
75 |
@Override |
|
76 | 76 |
public boolean isVisible() { |
77 | 77 |
ApplicationManager application = ApplicationLocator.getManager(); |
78 | 78 |
|
Also available in: Unified diff