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 @ 58
History | View | Annotate | Download (4.77 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 org.cresques.cts.IProjection; |
26 |
import org.slf4j.Logger; |
27 |
import org.slf4j.LoggerFactory; |
28 |
|
29 |
import org.gvsig.andami.PluginServices; |
30 |
import org.gvsig.andami.PluginsLocator; |
31 |
import org.gvsig.andami.PluginsManager; |
32 |
import org.gvsig.fmap.crs.CRSFactory; |
33 |
import org.gvsig.fmap.dal.DataStoreParameters; |
34 |
import org.gvsig.fmap.dal.exception.InitializeException; |
35 |
import org.gvsig.fmap.dal.exception.ProviderNotRegisteredException; |
36 |
import org.gvsig.fmap.mapcontext.layers.FLayer; |
37 |
import org.gvsig.fmap.mapcontrol.MapControl; |
38 |
import org.gvsig.googlemaps.swing.api.GoogleMapsConfigDataParameters; |
39 |
import org.gvsig.googlemaps.swing.api.GoogleMapsParametersPanel; |
40 |
import org.gvsig.googlemaps.swing.api.GoogleMapsSwingLocator; |
41 |
import org.gvsig.googlemaps.swing.api.GoogleMapsSwingManager; |
42 |
import org.gvsig.tools.ToolsLocator; |
43 |
import org.gvsig.tools.dynobject.DynObject; |
44 |
import org.gvsig.tools.i18n.I18nManager; |
45 |
import org.gvsig.tools.swing.api.Component; |
46 |
import org.gvsig.webmap.lib.api.WebMapService; |
47 |
import org.gvsig.webmap.lib.api.exceptions.WebMapInvalidParamsException; |
48 |
|
49 |
|
50 |
/**
|
51 |
* Google Maps Services
|
52 |
* @author daniel
|
53 |
*
|
54 |
*/
|
55 |
public class GoogleMapsService implements WebMapService{ |
56 |
private static final String PANELNAME = "_google_maps"; |
57 |
private Logger log = LoggerFactory.getLogger(GoogleMapsService.class); |
58 |
private GoogleMapsParametersPanel parametersPanel;
|
59 |
private MapControl mapCtrl;
|
60 |
|
61 |
/**
|
62 |
* Default constructor
|
63 |
*/
|
64 |
public GoogleMapsService(){
|
65 |
parametersPanel=null;
|
66 |
} |
67 |
|
68 |
@Override
|
69 |
public String getLabel() { |
70 |
I18nManager i18nManager = ToolsLocator.getI18nManager(); |
71 |
return i18nManager.getTranslation(PANELNAME);
|
72 |
} |
73 |
|
74 |
@Override
|
75 |
public Component getParametersPanel() { |
76 |
if (parametersPanel==null){ |
77 |
GoogleMapsConfigDataParameters configParams= getGoogleMapsConfigDataParameters(); |
78 |
parametersPanel=GoogleMapsSwingLocator.getManager().createGoogleMapsParametersPanel(configParams); |
79 |
IProjection googleMapsProjection = CRSFactory.getCRS("EPSG:3857");
|
80 |
if(mapCtrl!=null && !(mapCtrl.getProjection().equals(googleMapsProjection))){ |
81 |
parametersPanel.showCrsWarning(true);
|
82 |
} |
83 |
} |
84 |
return parametersPanel;
|
85 |
} |
86 |
|
87 |
@Override
|
88 |
public FLayer createLayer(DataStoreParameters params) {
|
89 |
FLyrGoogleMaps flyrGoogleMaps=new FLyrGoogleMaps(params);
|
90 |
return flyrGoogleMaps;
|
91 |
} |
92 |
|
93 |
@Override
|
94 |
public DataStoreParameters getParameters()
|
95 |
throws InitializeException, ProviderNotRegisteredException {
|
96 |
return parametersPanel.getParameters();
|
97 |
} |
98 |
|
99 |
@Override
|
100 |
public boolean isValid() |
101 |
throws WebMapInvalidParamsException {
|
102 |
return parametersPanel.areSettingsValid();
|
103 |
} |
104 |
|
105 |
/**
|
106 |
* Creates GoogleMapsPanelParams from plugin config
|
107 |
* @return
|
108 |
*/
|
109 |
private GoogleMapsConfigDataParameters getGoogleMapsConfigDataParameters(){
|
110 |
PluginsManager pluginsManager = PluginsLocator.getManager(); |
111 |
PluginServices plugin=pluginsManager.getPlugin(GoogleMapsExtension.class); |
112 |
|
113 |
DynObject config = plugin.getPluginProperties(); |
114 |
|
115 |
GoogleMapsSwingManager googleMapsSwingManager=GoogleMapsSwingLocator.getManager(); |
116 |
GoogleMapsConfigDataParameters panelParams=googleMapsSwingManager.createGoogleMapsPanelParams(config); |
117 |
return panelParams;
|
118 |
} |
119 |
|
120 |
/* (non-Javadoc)
|
121 |
* @see org.gvsig.webmap.lib.api.WebMapService#setMapCtrl(org.gvsig.fmap.mapcontrol.MapControl)
|
122 |
*/
|
123 |
@Override
|
124 |
public void setMapCtrl(MapControl mapControl) { |
125 |
this.mapCtrl = mapControl;
|
126 |
IProjection googleMapsProjection = CRSFactory.getCRS("EPSG:3857");
|
127 |
if(mapCtrl!=null && !(mapCtrl.getProjection().equals(googleMapsProjection))){ |
128 |
((GoogleMapsParametersPanel)getParametersPanel()).showCrsWarning(true);
|
129 |
} |
130 |
} |
131 |
|
132 |
} |