gvsig-webmap / org.gvsig.googlemaps / trunk / org.gvsig.googlemaps / org.gvsig.googlemaps.app / org.gvsig.googlemaps.app.mainplugin / src / main / java / org / gvsig / googlemaps / app / mainplugin / GoogleMapsService.java @ 135
History | View | Annotate | Download (5.7 KB)
1 |
/* gvSIG. Desktop Geographic Information System.
|
---|---|
2 |
*
|
3 |
* Copyright ? 2007-2016 gvSIG Association
|
4 |
*
|
5 |
* This program is free software; you can redistribute it and/or
|
6 |
* modify it under the terms of the GNU General Public License
|
7 |
* as published by the Free Software Foundation; either version 2
|
8 |
* of the License, or (at your option) any later version.
|
9 |
*
|
10 |
* This program is distributed in the hope that it will be useful,
|
11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
13 |
* GNU General Public License for more details.
|
14 |
*
|
15 |
* You should have received a copy of the GNU General Public License
|
16 |
* along with this program; if not, write to the Free Software
|
17 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
18 |
* MA 02110-1301, USA.
|
19 |
*
|
20 |
* For any additional information, do not hesitate to contact us
|
21 |
* at info AT gvsig.com, or visit our website www.gvsig.com.
|
22 |
*/
|
23 |
package org.gvsig.googlemaps.app.mainplugin; |
24 |
|
25 |
import java.awt.event.ActionEvent; |
26 |
import java.awt.event.ActionListener; |
27 |
import java.net.URI; |
28 |
import java.net.URISyntaxException; |
29 |
|
30 |
import org.cresques.cts.IProjection; |
31 |
import org.gvsig.andami.PluginServices; |
32 |
import org.gvsig.andami.PluginsLocator; |
33 |
import org.gvsig.andami.PluginsManager; |
34 |
import org.gvsig.fmap.crs.CRSFactory; |
35 |
import org.gvsig.fmap.dal.DataStoreParameters; |
36 |
import org.gvsig.fmap.dal.exception.InitializeException; |
37 |
import org.gvsig.fmap.dal.exception.ProviderNotRegisteredException; |
38 |
import org.gvsig.fmap.mapcontext.layers.FLayer; |
39 |
import org.gvsig.fmap.mapcontrol.MapControl; |
40 |
import org.gvsig.googlemaps.swing.api.GoogleMapsConfigDataParameters; |
41 |
import org.gvsig.googlemaps.swing.api.GoogleMapsParametersPanel; |
42 |
import org.gvsig.googlemaps.swing.api.GoogleMapsSwingLocator; |
43 |
import org.gvsig.googlemaps.swing.api.GoogleMapsSwingManager; |
44 |
import org.gvsig.tools.ToolsLocator; |
45 |
import org.gvsig.tools.dynobject.DynObject; |
46 |
import org.gvsig.tools.i18n.I18nManager; |
47 |
import org.gvsig.tools.swing.api.Component; |
48 |
import org.gvsig.webmap.lib.api.WebMapService; |
49 |
import org.gvsig.webmap.lib.api.exceptions.WebMapInvalidParamsException; |
50 |
import org.slf4j.Logger; |
51 |
import org.slf4j.LoggerFactory; |
52 |
|
53 |
|
54 |
/**
|
55 |
* Google Maps Services
|
56 |
* @author daniel
|
57 |
*
|
58 |
*/
|
59 |
public class GoogleMapsService implements WebMapService{ |
60 |
private static final String PANELNAME = "_google_maps"; |
61 |
private Logger log = LoggerFactory.getLogger(GoogleMapsService.class); |
62 |
private GoogleMapsParametersPanel parametersPanel;
|
63 |
private MapControl mapCtrl;
|
64 |
|
65 |
/**
|
66 |
* Default constructor
|
67 |
*/
|
68 |
public GoogleMapsService(){
|
69 |
parametersPanel=null;
|
70 |
} |
71 |
|
72 |
@Override
|
73 |
public String getLabel() { |
74 |
I18nManager i18nManager = ToolsLocator.getI18nManager(); |
75 |
return i18nManager.getTranslation(PANELNAME);
|
76 |
} |
77 |
|
78 |
@Override
|
79 |
public Component getParametersPanel() { |
80 |
if (parametersPanel==null){ |
81 |
GoogleMapsConfigDataParameters configParams= getGoogleMapsConfigDataParameters(); |
82 |
parametersPanel=GoogleMapsSwingLocator.getManager().createGoogleMapsParametersPanel(configParams); |
83 |
parametersPanel.addActionListener(new ActionListener() { |
84 |
|
85 |
@Override
|
86 |
public void actionPerformed(ActionEvent event) { |
87 |
GoogleMapsParametersPanel panel = (GoogleMapsParametersPanel) event.getSource(); |
88 |
if (panel.isSelectedAction(GoogleMapsParametersPanel.PanelAction.SHOW_DISCLAIMER)) {
|
89 |
PluginsManager pluginManager = PluginsLocator.getManager(); |
90 |
try {
|
91 |
pluginManager.desktopBrowse(configParams.getDisclaimerURL().toURI()); |
92 |
} catch (URISyntaxException e) { |
93 |
log.warn("Couldn't browse to: "+configParams.getDisclaimerURL().toString());
|
94 |
} |
95 |
} |
96 |
} |
97 |
}); |
98 |
IProjection googleMapsProjection = CRSFactory.getCRS("EPSG:3857");
|
99 |
if(mapCtrl!=null && !(mapCtrl.getProjection().equals(googleMapsProjection))){ |
100 |
parametersPanel.showCrsWarning(true);
|
101 |
} |
102 |
|
103 |
} |
104 |
return parametersPanel;
|
105 |
} |
106 |
|
107 |
@Override
|
108 |
public FLayer createLayer(DataStoreParameters params) {
|
109 |
FLyrGoogleMaps flyrGoogleMaps=new FLyrGoogleMaps(params);
|
110 |
return flyrGoogleMaps;
|
111 |
} |
112 |
|
113 |
@Override
|
114 |
public DataStoreParameters getParameters()
|
115 |
throws InitializeException, ProviderNotRegisteredException {
|
116 |
return parametersPanel.getParameters();
|
117 |
} |
118 |
|
119 |
@Override
|
120 |
public boolean isValid() |
121 |
throws WebMapInvalidParamsException {
|
122 |
return parametersPanel.areSettingsValid();
|
123 |
} |
124 |
|
125 |
/**
|
126 |
* Creates GoogleMapsPanelParams from plugin config
|
127 |
* @return
|
128 |
*/
|
129 |
private GoogleMapsConfigDataParameters getGoogleMapsConfigDataParameters(){
|
130 |
PluginsManager pluginsManager = PluginsLocator.getManager(); |
131 |
PluginServices plugin=pluginsManager.getPlugin(GoogleMapsExtension.class); |
132 |
|
133 |
DynObject config = plugin.getPluginProperties(); |
134 |
|
135 |
GoogleMapsSwingManager googleMapsSwingManager=GoogleMapsSwingLocator.getManager(); |
136 |
GoogleMapsConfigDataParameters panelParams=googleMapsSwingManager.createGoogleMapsPanelParams(config); |
137 |
return panelParams;
|
138 |
} |
139 |
|
140 |
/* (non-Javadoc)
|
141 |
* @see org.gvsig.webmap.lib.api.WebMapService#setMapCtrl(org.gvsig.fmap.mapcontrol.MapControl)
|
142 |
*/
|
143 |
@Override
|
144 |
public void setMapCtrl(MapControl mapControl) { |
145 |
this.mapCtrl = mapControl;
|
146 |
IProjection googleMapsProjection = CRSFactory.getCRS("EPSG:3857");
|
147 |
if(mapCtrl!=null && !(mapCtrl.getProjection().equals(googleMapsProjection))){ |
148 |
((GoogleMapsParametersPanel)getParametersPanel()).showCrsWarning(true);
|
149 |
} |
150 |
} |
151 |
|
152 |
} |