gvsig-raster / org.gvsig.raster.wmts / trunk / org.gvsig.raster.wmts / org.gvsig.raster.wmts.app.wmtsclient / src / main / java / org / gvsig / raster / wmts / app / wmtsclient / WMTSClientExtension.java @ 9533
History | View | Annotate | Download (5.74 KB)
1 | 2485 | nbrodin | /* gvSIG. Geographic Information System of the Valencian Government
|
---|---|---|---|
2 | *
|
||
3 | * Copyright (C) 2007-2008 Infrastructures and Transports Department
|
||
4 | * of the Valencian Government (CIT)
|
||
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 2
|
||
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 | */
|
||
22 | |||
23 | package org.gvsig.raster.wmts.app.wmtsclient; |
||
24 | |||
25 | import java.awt.Component; |
||
26 | import java.awt.geom.Point2D; |
||
27 | |||
28 | import javax.swing.JOptionPane; |
||
29 | |||
30 | import org.gvsig.about.AboutManager; |
||
31 | import org.gvsig.about.AboutParticipant; |
||
32 | import org.gvsig.andami.IconThemeHelper; |
||
33 | import org.gvsig.andami.PluginServices; |
||
34 | import org.gvsig.andami.plugins.Extension; |
||
35 | import org.gvsig.andami.ui.mdiManager.IWindow; |
||
36 | import org.gvsig.app.ApplicationLocator; |
||
37 | import org.gvsig.app.ApplicationManager; |
||
38 | import org.gvsig.app.extension.AddLayer; |
||
39 | import org.gvsig.app.project.documents.view.gui.AbstractViewPanel; |
||
40 | import org.gvsig.fmap.geom.exception.CreateEnvelopeException; |
||
41 | import org.gvsig.fmap.geom.primitive.Envelope; |
||
42 | import org.gvsig.fmap.mapcontext.ViewPort; |
||
43 | import org.gvsig.fmap.mapcontext.layers.FLayer; |
||
44 | import org.gvsig.fmap.mapcontext.layers.FLayers; |
||
45 | import org.gvsig.fmap.mapcontrol.MapControl; |
||
46 | import org.gvsig.raster.fmap.layers.Multiresolution; |
||
47 | import org.gvsig.raster.wmts.app.wmtsclient.gui.wizard.WMTSWizard; |
||
48 | import org.gvsig.raster.wmts.app.wmtsclient.layer.DynObjectSetWMTSInfo; |
||
49 | import org.gvsig.raster.wmts.app.wmtsclient.layer.FLyrWMTS; |
||
50 | import org.gvsig.tools.ToolsLocator; |
||
51 | import org.gvsig.tools.extensionpoint.ExtensionPoint; |
||
52 | |||
53 | |||
54 | /**
|
||
55 | * Extension for adding WMTS support to gvSIG.
|
||
56 | *
|
||
57 | * @author Nacho Brodin (nachobrodin@gmail.com)
|
||
58 | */
|
||
59 | public class WMTSClientExtension extends Extension { |
||
60 | |||
61 | public void initialize() { |
||
62 | // Adds an entry to the TOC's floating menu to those layers defined in this extension
|
||
63 | ExtensionPoint exPoint = ToolsLocator.getExtensionPointManager().add("View_TocActions");
|
||
64 | exPoint.append("WMTSPropsTocMenuEntry", "", new WMTSPropsTocMenuEntry()); |
||
65 | |||
66 | // Adds a new tab to the "add layer" wizard for WMTS layer creation
|
||
67 | AddLayer.addWizard(WMTSWizard.class); |
||
68 | |||
69 | //ToolsLocator.getExtensionPointManager().add("CatalogLayers").append("OGC:WMTS", "", FLyrWMTS.class);
|
||
70 | initilizeIcons(); |
||
71 | DynObjectSetWMTSInfo.registerDynClass(); |
||
72 | } |
||
73 | |||
74 | public void postInitialize() { |
||
75 | FLyrWMTS.registerPersistent(); |
||
76 | 9533 | jjdelcerro | // addAboutInfo();
|
77 | 2485 | nbrodin | } |
78 | |||
79 | 9533 | jjdelcerro | // private void addAboutInfo() {
|
80 | // ApplicationManager application = ApplicationLocator.getManager();
|
||
81 | //
|
||
82 | // AboutManager about = application.getAbout();
|
||
83 | // about.addDeveloper("PRODEVELOP", getClass().getClassLoader()
|
||
84 | // .getResource("about/wmts-about.html"), 2);
|
||
85 | //
|
||
86 | // AboutParticipant participant = about.getDeveloper("PRODEVELOP");
|
||
87 | // participant.addContribution(
|
||
88 | // "WMTS",
|
||
89 | // "Cliente para Web Map Tile Service",
|
||
90 | // 2011,3,1,
|
||
91 | // 2011,3,30
|
||
92 | // );
|
||
93 | // }
|
||
94 | 2485 | nbrodin | |
95 | @SuppressWarnings("deprecation") |
||
96 | public void execute(String actionCommand) { |
||
97 | AbstractViewPanel theView = (AbstractViewPanel) PluginServices.getMDIManager().getActiveWindow(); |
||
98 | MapControl mapCtrl = theView.getMapControl(); |
||
99 | ViewPort viewPort = mapCtrl.getViewPort(); |
||
100 | |||
101 | Multiresolution lyrMultires = null;
|
||
102 | |||
103 | FLayers lyrs = mapCtrl.getMapContext().getLayers(); |
||
104 | for (int i = 0; i < lyrs.getLayersCount(); i++) { |
||
105 | FLayer lyr = lyrs.getLayer(i); |
||
106 | if(lyr instanceof FLyrWMTS) { |
||
107 | lyrMultires = ((Multiresolution)lyr); |
||
108 | } |
||
109 | } |
||
110 | |||
111 | if(actionCommand.compareTo("NEXT_LEVEL") == 0) { |
||
112 | if(!lyrMultires.increaseZoomLevel()) {
|
||
113 | JOptionPane.showMessageDialog((Component)PluginServices.getMainFrame(), "max_zoom_reached"); |
||
114 | return;
|
||
115 | } |
||
116 | } |
||
117 | |||
118 | if(actionCommand.compareTo("PREV_LEVEL") == 0) { |
||
119 | if(!lyrMultires.decreaseZoomLevel()) {
|
||
120 | JOptionPane.showMessageDialog((Component)PluginServices.getMainFrame(), "min_zoom_reached"); |
||
121 | return;
|
||
122 | } |
||
123 | } |
||
124 | |||
125 | Point2D center = new Point2D.Double(viewPort.getExtent().getCenterX(), viewPort.getExtent().getCenterY()); |
||
126 | Envelope r; |
||
127 | try {
|
||
128 | r = lyrMultires.getCoordsInLevel(center, lyrMultires.getZoomLevel(), |
||
129 | viewPort.getImageWidth(), viewPort.getImageHeight()); |
||
130 | } catch (CreateEnvelopeException e) {
|
||
131 | return;
|
||
132 | } |
||
133 | |||
134 | mapCtrl.getViewPort().setEnvelope(r); |
||
135 | mapCtrl.invalidate(); |
||
136 | } |
||
137 | |||
138 | public boolean isEnabled() { |
||
139 | return true; |
||
140 | } |
||
141 | |||
142 | public boolean isVisible() { |
||
143 | IWindow window = PluginServices.getMDIManager().getActiveWindow(); |
||
144 | if(window instanceof AbstractViewPanel) { |
||
145 | AbstractViewPanel theView = (AbstractViewPanel) window; |
||
146 | MapControl mapCtrl = theView.getMapControl(); |
||
147 | FLayers lyrs = mapCtrl.getMapContext().getLayers(); |
||
148 | for (int i = 0; i < lyrs.getLayersCount(); i++) { |
||
149 | if(lyrs.getLayer(i) instanceof FLyrWMTS) |
||
150 | return true; |
||
151 | } |
||
152 | } |
||
153 | return false; |
||
154 | } |
||
155 | |||
156 | |||
157 | void initilizeIcons(){
|
||
158 | IconThemeHelper.registerIcon(null, "level-plus", this); |
||
159 | IconThemeHelper.registerIcon(null, "level-less", this); |
||
160 | IconThemeHelper.registerIcon(null, "icon-layer-wmts", this); |
||
161 | IconThemeHelper.registerIcon(null, "aplication-preferences-downarrow", this); |
||
162 | IconThemeHelper.registerIcon(null, "aplication-preferences-uparrow", this); |
||
163 | } |
||
164 | } |