svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.plugin / org.gvsig.app / org.gvsig.app.mainplugin / src / main / java / org / gvsig / app / project / documents / view / toc / actions / ZoomAlTemaTocMenuEntry.java @ 40596
History | View | Annotate | Download (4.21 KB)
1 |
/**
|
---|---|
2 |
* gvSIG. Desktop Geographic Information System.
|
3 |
*
|
4 |
* Copyright (C) 2007-2013 gvSIG Association.
|
5 |
*
|
6 |
* This program is free software; you can redistribute it and/or
|
7 |
* modify it under the terms of the GNU General Public License
|
8 |
* as published by the Free Software Foundation; either version 3
|
9 |
* of the License, or (at your option) any later version.
|
10 |
*
|
11 |
* This program is distributed in the hope that it will be useful,
|
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14 |
* GNU General Public License for more details.
|
15 |
*
|
16 |
* You should have received a copy of the GNU General Public License
|
17 |
* along with this program; if not, write to the Free Software
|
18 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
19 |
* MA 02110-1301, USA.
|
20 |
*
|
21 |
* For any additional information, do not hesitate to contact us
|
22 |
* at info AT gvsig.com, or visit our website www.gvsig.com.
|
23 |
*/
|
24 |
package org.gvsig.app.project.documents.view.toc.actions; |
25 |
|
26 |
import org.gvsig.andami.PluginServices; |
27 |
import org.gvsig.app.extension.ProjectExtension; |
28 |
import org.gvsig.app.project.Project; |
29 |
import org.gvsig.app.project.documents.view.toc.AbstractTocContextMenuAction; |
30 |
import org.gvsig.app.project.documents.view.toc.ITocItem; |
31 |
import org.gvsig.fmap.dal.exception.ReadException; |
32 |
import org.gvsig.fmap.geom.GeometryLocator; |
33 |
import org.gvsig.fmap.geom.GeometryManager; |
34 |
import org.gvsig.fmap.geom.Geometry.SUBTYPES; |
35 |
import org.gvsig.fmap.geom.exception.CreateEnvelopeException; |
36 |
import org.gvsig.fmap.geom.primitive.Envelope; |
37 |
import org.gvsig.fmap.mapcontext.layers.FLayer; |
38 |
import org.slf4j.Logger; |
39 |
import org.slf4j.LoggerFactory; |
40 |
|
41 |
|
42 |
public class ZoomAlTemaTocMenuEntry extends AbstractTocContextMenuAction { |
43 |
private static final GeometryManager geomManager = GeometryLocator.getGeometryManager(); |
44 |
private static final Logger logger = LoggerFactory.getLogger(ZoomAlTemaTocMenuEntry.class); |
45 |
|
46 |
public String getGroup() { |
47 |
return "group2"; //FIXME |
48 |
} |
49 |
|
50 |
public int getGroupOrder() { |
51 |
return 20; |
52 |
} |
53 |
|
54 |
public int getOrder() { |
55 |
return 1; |
56 |
} |
57 |
|
58 |
public String getText() { |
59 |
return PluginServices.getText(this, "Zoom_a_la_capa"); |
60 |
} |
61 |
|
62 |
public boolean isEnabled(ITocItem item, FLayer[] selectedItems) { |
63 |
return true; |
64 |
} |
65 |
|
66 |
public boolean isVisible(ITocItem item, FLayer[] selectedItems) { |
67 |
if (isTocItemBranch(item) && ! (selectedItems == null || selectedItems.length <= 0)) { |
68 |
return true; |
69 |
} |
70 |
return false; |
71 |
|
72 |
} |
73 |
|
74 |
|
75 |
public void execute(ITocItem item, FLayer[] selectedItems) { |
76 |
|
77 |
|
78 |
// 050209, jmorell: Para que haga un zoom a un grupo de capas seleccionadas.
|
79 |
|
80 |
if (selectedItems.length==1) { |
81 |
try {
|
82 |
if (!selectedItems[0].isAvailable()) { |
83 |
return;
|
84 |
} |
85 |
getMapContext().zoomToEnvelope(selectedItems[0].getFullEnvelope());
|
86 |
} catch (ReadException e1) {
|
87 |
e1.printStackTrace(); |
88 |
} |
89 |
} else {
|
90 |
try {
|
91 |
Envelope maxExtent = setMaxExtent(selectedItems); |
92 |
getMapContext().zoomToEnvelope(maxExtent); |
93 |
} catch (ReadException e1) {
|
94 |
e1.printStackTrace(); |
95 |
} |
96 |
} |
97 |
Project project=((ProjectExtension)PluginServices.getExtension(ProjectExtension.class)).getProject(); |
98 |
project.setModified(true);
|
99 |
} |
100 |
|
101 |
private Envelope setMaxExtent(FLayer[] actives) |
102 |
throws ReadException {
|
103 |
Envelope extRef = null;
|
104 |
extRef = actives[0].getFullEnvelope();
|
105 |
|
106 |
double minXRef = extRef.getMinimum(0); |
107 |
double maxYRef = extRef.getMaximum(1); |
108 |
double maxXRef = extRef.getMaximum(0); |
109 |
double minYRef = extRef.getMinimum(1); |
110 |
for (int i = 0; i < actives.length; i++) { |
111 |
if (actives[i].isAvailable()) {
|
112 |
Envelope extVar = actives[i].getFullEnvelope(); |
113 |
double minXVar = extVar.getMinimum(0); |
114 |
double maxYVar = extVar.getMaximum(1); |
115 |
double maxXVar = extVar.getMaximum(0); |
116 |
double minYVar = extVar.getMinimum(1); |
117 |
if (minXVar <= minXRef) {
|
118 |
minXRef = minXVar; |
119 |
} |
120 |
if (maxYVar >= maxYRef) {
|
121 |
maxYRef = maxYVar; |
122 |
} |
123 |
if (maxXVar >= maxXRef) {
|
124 |
maxXRef = maxXVar; |
125 |
} |
126 |
if (minYVar <= minYRef) {
|
127 |
minYRef = minYVar; |
128 |
} |
129 |
try {
|
130 |
extRef = geomManager.createEnvelope(minXRef, minYRef, maxXRef, maxYRef, SUBTYPES.GEOM2D); |
131 |
} catch (CreateEnvelopeException e) {
|
132 |
logger.error("Error creating the envelope", e);
|
133 |
} |
134 |
} |
135 |
} |
136 |
return extRef;
|
137 |
} |
138 |
} |