gvsig-webmap / org.gvsig.bingmaps / trunk / org.gvsig.bingmaps / org.gvsig.bingmaps.app / org.gvsig.bingmaps.app.mainplugin / src / main / java / org / gvsig / bingmaps / app / mainplugin / BingMapsService.java @ 58
History | View | Annotate | Download (5.06 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.bingmaps.app.mainplugin; |
24 |
|
25 |
import java.io.File; |
26 |
import java.io.FileInputStream; |
27 |
import java.io.FileNotFoundException; |
28 |
import java.io.IOException; |
29 |
import java.util.Properties; |
30 |
|
31 |
import org.apache.commons.io.IOUtils; |
32 |
import org.cresques.cts.IProjection; |
33 |
|
34 |
import org.gvsig.andami.PluginServices; |
35 |
import org.gvsig.andami.PluginsLocator; |
36 |
import org.gvsig.andami.PluginsManager; |
37 |
import org.gvsig.bingmaps.swing.api.BingMapsConfigDataParameters; |
38 |
import org.gvsig.bingmaps.swing.api.BingMapsParametersPanel; |
39 |
import org.gvsig.bingmaps.swing.api.BingMapsSwingLocator; |
40 |
import org.gvsig.bingmaps.swing.api.BingMapsSwingManager; |
41 |
import org.gvsig.fmap.crs.CRSFactory; |
42 |
import org.gvsig.fmap.dal.DataStoreParameters; |
43 |
import org.gvsig.fmap.dal.exception.InitializeException; |
44 |
import org.gvsig.fmap.dal.exception.ProviderNotRegisteredException; |
45 |
import org.gvsig.fmap.mapcontext.layers.FLayer; |
46 |
import org.gvsig.fmap.mapcontrol.MapControl; |
47 |
import org.gvsig.tools.ToolsLocator; |
48 |
import org.gvsig.tools.dynobject.DynObject; |
49 |
import org.gvsig.tools.i18n.I18nManager; |
50 |
import org.gvsig.tools.swing.api.Component; |
51 |
import org.gvsig.webmap.lib.api.WebMapService; |
52 |
import org.gvsig.webmap.lib.api.exceptions.WebMapInvalidParamsException; |
53 |
|
54 |
import org.slf4j.Logger; |
55 |
import org.slf4j.LoggerFactory; |
56 |
|
57 |
|
58 |
/**
|
59 |
* Bing Maps Services
|
60 |
* @author daniel
|
61 |
*
|
62 |
*/
|
63 |
public class BingMapsService implements WebMapService{ |
64 |
private static final String PANELNAME="_bing_maps"; |
65 |
private static final String defaultPropertiesFilename = "defaultConfig.properties"; |
66 |
private Logger log = LoggerFactory.getLogger(BingMapsService.class); |
67 |
private BingMapsParametersPanel parametersPanel;
|
68 |
private MapControl mapCtrl;
|
69 |
|
70 |
/**
|
71 |
* Default Constructor
|
72 |
*/
|
73 |
public BingMapsService(){
|
74 |
this.parametersPanel=null; |
75 |
} |
76 |
|
77 |
@Override
|
78 |
public String getLabel() { |
79 |
I18nManager i18nManager = ToolsLocator.getI18nManager(); |
80 |
return i18nManager.getTranslation(PANELNAME);
|
81 |
} |
82 |
|
83 |
@Override
|
84 |
public Component getParametersPanel() { |
85 |
if (parametersPanel==null){ |
86 |
BingMapsConfigDataParameters configParams= getBingMapsConfigDataParameters(); |
87 |
parametersPanel=BingMapsSwingLocator.getManager().createBingMapsParametersPanel(configParams); |
88 |
IProjection bingMapsProjection = CRSFactory.getCRS("EPSG:3857");
|
89 |
if(mapCtrl!=null && !(mapCtrl.getProjection().equals(bingMapsProjection))){ |
90 |
parametersPanel.showCrsWarning(true);
|
91 |
} |
92 |
|
93 |
} |
94 |
return parametersPanel;
|
95 |
} |
96 |
|
97 |
@Override
|
98 |
public FLayer createLayer(DataStoreParameters params) {
|
99 |
FLyrBingMaps flyrBingMaps=new FLyrBingMaps(params);
|
100 |
return flyrBingMaps;
|
101 |
} |
102 |
|
103 |
@Override
|
104 |
public DataStoreParameters getParameters()
|
105 |
throws InitializeException, ProviderNotRegisteredException {
|
106 |
return parametersPanel.getParameters();
|
107 |
} |
108 |
|
109 |
@Override
|
110 |
public boolean isValid() |
111 |
throws WebMapInvalidParamsException {
|
112 |
return parametersPanel.areSettingsValid();
|
113 |
} |
114 |
|
115 |
/**
|
116 |
* Creates BingMapsPanelParams from plugin config a default properties file
|
117 |
* @return
|
118 |
*/
|
119 |
private BingMapsConfigDataParameters getBingMapsConfigDataParameters(){
|
120 |
PluginsManager pluginsManager = PluginsLocator.getManager(); |
121 |
PluginServices plugin=pluginsManager.getPlugin(BingMapsExtension.class); |
122 |
|
123 |
//Last used configuration
|
124 |
DynObject config = plugin.getPluginProperties(); |
125 |
|
126 |
BingMapsSwingManager bingMapsSwingManager=BingMapsSwingLocator.getManager(); |
127 |
BingMapsConfigDataParameters panelParams=bingMapsSwingManager.createBingMapsPanelParams(config); |
128 |
return panelParams;
|
129 |
} |
130 |
|
131 |
/* (non-Javadoc)
|
132 |
* @see org.gvsig.webmap.lib.api.WebMapService#setMapCtrl(org.gvsig.fmap.mapcontrol.MapControl)
|
133 |
*/
|
134 |
@Override
|
135 |
public void setMapCtrl(MapControl mapControl) { |
136 |
this.mapCtrl = mapControl;
|
137 |
IProjection googleMapsProjection = CRSFactory.getCRS("EPSG:3857");
|
138 |
if(mapCtrl!=null && !(mapCtrl.getProjection().equals(googleMapsProjection))){ |
139 |
((BingMapsParametersPanel)getParametersPanel()).showCrsWarning(true);
|
140 |
} |
141 |
} |
142 |
|
143 |
|
144 |
|
145 |
} |