Revision 198

View differences:

org.gvsig.raster.osm/tags/org.gvsig.raster.osm-2.2.16/pom.xml
1
<?xml version="1.0" encoding="UTF-8"?>
2
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
3
    <modelVersion>4.0.0</modelVersion>
4
    <groupId>org.gvsig</groupId>
5
    <artifactId>org.gvsig.raster.osm</artifactId>
6
    <packaging>pom</packaging>
7
    <version>2.2.16</version>
8
    <name>org.gvsig.raster.osm</name>
9
    <description>OSM adapter</description>
10
    <inceptionYear>2011</inceptionYear>
11
    <parent>
12
        <groupId>org.gvsig</groupId>
13
        <artifactId>org.gvsig.desktop</artifactId>
14
        <version>2.0.111</version>
15
    </parent>
16
    
17
    <repositories>
18
        <repository>
19
            <id>gvsig-public-http-repository</id>
20
            <name>gvSIG maven public HTTP repository</name>
21
            <url>http://devel.gvsig.org/m2repo/j2se</url>
22
            <releases>
23
                <enabled>true</enabled>
24
                <updatePolicy>daily</updatePolicy>
25
                <checksumPolicy>warn</checksumPolicy>
26
            </releases>
27
            <snapshots>
28
                <enabled>true</enabled>
29
                <updatePolicy>daily</updatePolicy>
30
                <checksumPolicy>warn</checksumPolicy>
31
            </snapshots>
32
        </repository>
33
    </repositories>
34
    
35
    <scm>
36
        <connection>scm:svn:https://devel.gvsig.org/svn/gvsig-osm/org.gvsig.raster.osm/tags/org.gvsig.raster.osm-2.2.16</connection>
37
        <developerConnection>scm:svn:https://devel.gvsig.org/svn/gvsig-osm/org.gvsig.raster.osm/tags/org.gvsig.raster.osm-2.2.16</developerConnection>
38
        <url>https://devel.gvsig.org/redmine/projects/gvsig-osm/repository/show/org.gvsig.raster.osm/tags/org.gvsig.raster.osm-2.2.16</url>
39
    </scm>	
40
    <properties>
41
        <org.gvsig.raster.version>2.2.21</org.gvsig.raster.version>
42
    </properties>
43
    
44
    <dependencyManagement>
45
        <dependencies>
46
            <dependency>
47
                <groupId>org.gvsig</groupId>
48
                <artifactId>org.gvsig.raster</artifactId>
49
                <version>${org.gvsig.raster.version}</version>
50
                <type>pom</type>
51
                <scope>import</scope>
52
            </dependency>
53
                        
54
            <dependency>
55
                <groupId>org.gvsig</groupId>
56
                <artifactId>org.gvsig.raster.osm.swing.api</artifactId>
57
                <version>2.2.16</version>
58
            </dependency>
59
            <dependency>
60
                <groupId>org.gvsig</groupId>
61
                <artifactId>org.gvsig.raster.osm.swing.impl</artifactId>
62
                <version>2.2.16</version>
63
            </dependency>
64
            <dependency>
65
                <groupId>org.gvsig</groupId>
66
                <artifactId>org.gvsig.raster.osm.io</artifactId>
67
                <version>2.2.16</version>
68
            </dependency>
69

  
70

  
71
        </dependencies>
72
    </dependencyManagement>
73

  
74
    <build>
75
        <plugins>
76
            <plugin>
77
                <groupId>org.apache.maven.plugins</groupId>
78
                <artifactId>maven-release-plugin</artifactId>
79
                <configuration>
80
                    <tagBase>https://devel.gvsig.org/svn/gvsig-osm/org.gvsig.raster.osm/tags/</tagBase>
81
                    <goals>deploy</goals>
82
                </configuration>
83
            </plugin>
84
        </plugins>
85
    </build>
86
    <modules>
87
        <module>org.gvsig.raster.osm.io</module>
88
        <module>org.gvsig.raster.osm.swing</module>
89
        <module>org.gvsig.raster.osm.app.osmclient</module>
90
    </modules> 
91
</project>
92

  
0 93

  
org.gvsig.raster.osm/tags/org.gvsig.raster.osm-2.2.16/org.gvsig.raster.osm.app.osmclient/pom.xml
1
<?xml version="1.0" encoding="ISO-8859-1"?>
2

  
3
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
4
	<modelVersion>4.0.0</modelVersion>
5
	<artifactId>org.gvsig.raster.osm.app.osmclient</artifactId>
6
	<packaging>jar</packaging>
7
        <name>${artifactId}</name>
8
	<description>Access for OpenStreetMap raster tiles in gvSIG 2.1</description>
9
	<parent>
10
		<groupId>org.gvsig</groupId>
11
		<artifactId>org.gvsig.raster.osm</artifactId>
12
		<version>2.2.16</version>
13
	</parent>
14

  
15
	<dependencies>
16
    <dependency>
17
			<groupId>org.gvsig</groupId>
18
			<artifactId>org.gvsig.raster.app.common</artifactId>
19
			<scope>compile</scope>
20
		</dependency>
21
    <dependency>
22
      <groupId>org.gvsig</groupId>
23
      <artifactId>org.gvsig.raster.lib.api</artifactId>
24
      <scope>compile</scope>
25
    </dependency>
26
		 <dependency>
27
        <groupId>org.gvsig</groupId>
28
        <artifactId>org.gvsig.ui</artifactId>
29
        <scope>compile</scope>
30
    </dependency>
31
    <dependency>
32
        <groupId>org.gvsig</groupId>
33
        <artifactId>org.gvsig.raster.osm.swing.api</artifactId>
34
        <scope>compile</scope>
35
    </dependency>
36
    <dependency>
37
        <groupId>org.gvsig</groupId>
38
        <artifactId>org.gvsig.raster.osm.swing.impl</artifactId>
39
        <scope>runtime</scope>
40
    </dependency>
41
		<dependency>
42
        <groupId>org.gvsig</groupId>
43
        <artifactId>org.gvsig.raster.osm.io</artifactId>
44
        <scope>compile</scope>
45
    </dependency>
46
    <dependency>
47
			<groupId>org.gvsig</groupId>
48
			<artifactId>org.gvsig.raster.fmap</artifactId>
49
      <scope>compile</scope>
50
		</dependency>
51
		<dependency>
52
			<groupId>org.gvsig</groupId>
53
			<artifactId>org.gvsig.app.mainplugin</artifactId>
54
      <scope>compile</scope>
55
		</dependency>
56
		<dependency>
57
        <groupId>org.gvsig</groupId>
58
        <artifactId>org.gvsig.fmap.dal.api</artifactId>
59
        <scope>compile</scope>
60
    </dependency>
61
    <dependency>
62
        <groupId>org.gvsig</groupId>
63
        <artifactId>org.gvsig.fmap.dal.impl</artifactId>
64
        <scope>compile</scope>
65
    </dependency>
66
		<dependency>
67
          <groupId>org.gvsig</groupId>
68
          <artifactId>org.gvsig.fmap.geometry.api</artifactId>
69
          <scope>compile</scope>
70
      </dependency>
71
    <!--
72
      <dependency>
73
          <groupId>org.gvsig</groupId>
74
          <artifactId>org.gvsig.fmap.geometry.generalpath</artifactId>
75
          <scope>runtime</scope>
76
      </dependency>
77
    -->
78
      <dependency>
79
          <groupId>org.gvsig</groupId>
80
          <artifactId>org.gvsig.fmap.dal.spi</artifactId>
81
          <scope>compile</scope>
82
      </dependency>
83
      <dependency>
84
          <groupId>org.gvsig</groupId>
85
          <artifactId>org.gvsig.fmap.mapcontext.api</artifactId>
86
          <scope>compile</scope>
87
      </dependency>
88
      <dependency>
89
          <groupId>org.gvsig</groupId>
90
          <artifactId>org.gvsig.fmap.mapcontext.impl</artifactId>
91
          <scope>runtime</scope>
92
      </dependency>
93
      <dependency>
94
          <groupId>org.gvsig</groupId>
95
          <artifactId>org.gvsig.fmap.mapcontext.operation</artifactId>
96
          <scope>runtime</scope>
97
      </dependency>
98
       <dependency>
99
          <groupId>org.gvsig</groupId>
100
          <artifactId>org.gvsig.fmap.control</artifactId>
101
          <scope>compile</scope>
102
      </dependency>
103
		  <dependency>
104
          <groupId>org.gvsig</groupId>
105
          <artifactId>org.gvsig.compat.api</artifactId>
106
          <scope>compile</scope>
107
      </dependency>
108
      <dependency>
109
          <groupId>org.gvsig</groupId>
110
          <artifactId>org.gvsig.compat.se</artifactId>
111
          <scope>compile</scope>
112
      </dependency>
113
  		<dependency>
114
          <groupId>org.gvsig</groupId>
115
          <artifactId>org.gvsig.projection.api</artifactId>
116
          <scope>compile</scope>
117
      </dependency>
118
      <dependency>
119
          <groupId>org.gvsig</groupId>
120
          <artifactId>org.gvsig.projection.cresques.impl</artifactId>
121
          <scope>runtime</scope>
122
      </dependency>
123
       <dependency>
124
          <groupId>org.gvsig</groupId>
125
          <artifactId>org.gvsig.metadata.lib.basic.api</artifactId>
126
          <scope>compile</scope>
127
      </dependency>
128
      <dependency>
129
           <groupId>org.gvsig</groupId>
130
           <artifactId>org.gvsig.about.api</artifactId>
131
           <scope>compile</scope>
132
      </dependency>
133
      <!--
134
      <dependency>
135
       		<groupId>org.gvsig</groupId>
136
        		<artifactId>org.gvsig.projection.jcrs.lib</artifactId>
137
         		<scope>compile</scope>
138
     	</dependency>
139
     	-->
140
	</dependencies>
141

  
142
	<properties>
143
                <gvsig.package.info.name>Formats: OpenStreetMap raster tiles support</gvsig.package.info.name>
144
		<gvsig.package.info.dependencies>required: org.gvsig.raster.tilecache.app -ge 2, required: org.gvsig.raster.mainplugin -ge 2, required: org.gvsig.crs.extension -ge 1</gvsig.package.info.dependencies>
145
		<gvsig.package.info.poolURL>https://devel.gvsig.org/download/projects/Raster/pool</gvsig.package.info.poolURL>
146
		<gvsig.package.info.categories>Remote Services,Raster,Formats</gvsig.package.info.categories>
147
  	<gvsig.package.info.state>testing</gvsig.package.info.state>
148
  	<gvsig.package.info.official>true</gvsig.package.info.official>
149
  </properties>
150
</project>
0 151

  
org.gvsig.raster.osm/tags/org.gvsig.raster.osm-2.2.16/org.gvsig.raster.osm.app.osmclient/buildNumber.properties
1
#Tue Nov 03 20:26:12 CET 2015
2
buildNumber=68
0 3

  
org.gvsig.raster.osm/tags/org.gvsig.raster.osm-2.2.16/org.gvsig.raster.osm.app.osmclient/src/main/java/org/gvsig/raster/osm/app/osmclient/AddOSMLayerWizard.java
1
/* 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
package org.gvsig.raster.osm.app.osmclient;
23

  
24
import java.awt.Component;
25
import java.awt.GridBagConstraints;
26
import java.awt.GridBagLayout;
27
import java.awt.Insets;
28
import java.awt.event.MouseEvent;
29
import java.awt.event.MouseListener;
30
import java.beans.PropertyVetoException;
31
import java.io.File;
32
import java.io.FileNotFoundException;
33
import java.io.IOException;
34

  
35
import javax.swing.JOptionPane;
36
import javax.swing.JPanel;
37

  
38
import org.cresques.cts.IProjection;
39
import org.gvsig.andami.Launcher;
40
import org.gvsig.andami.PluginServices;
41
import org.gvsig.andami.PluginsLocator;
42
import org.gvsig.andami.ui.mdiManager.IWindow;
43
import org.gvsig.app.ApplicationLocator;
44
import org.gvsig.app.ApplicationManager;
45
import org.gvsig.app.gui.WizardPanel;
46
import org.gvsig.app.gui.wizards.WizardListener;
47
import org.gvsig.app.gui.wizards.WizardListenerSupport;
48
import org.gvsig.app.project.ProjectManager;
49
import org.gvsig.app.project.documents.view.ViewDocument;
50
import org.gvsig.app.project.documents.view.ViewManager;
51
import org.gvsig.app.project.documents.view.gui.AbstractViewPanel;
52
import org.gvsig.app.project.documents.view.gui.IView;
53
import org.gvsig.fmap.crs.CRSFactory;
54
import org.gvsig.fmap.dal.DALLocator;
55
import org.gvsig.fmap.dal.DataParameters;
56
import org.gvsig.fmap.dal.DataStoreParameters;
57
import org.gvsig.fmap.dal.coverage.RasterLocator;
58
import org.gvsig.fmap.dal.coverage.store.parameter.TileDataParameters;
59
import org.gvsig.fmap.dal.coverage.util.FileUtils;
60
import org.gvsig.fmap.dal.exception.InitializeException;
61
import org.gvsig.fmap.dal.exception.ProviderNotRegisteredException;
62
import org.gvsig.fmap.dal.spi.DataManagerProviderServices;
63
import org.gvsig.fmap.mapcontext.MapContext;
64
import org.gvsig.fmap.mapcontext.exceptions.LoadLayerException;
65
import org.gvsig.raster.osm.app.osmclient.layer.FLyrOSM;
66
import org.gvsig.raster.osm.io.OSMDataParameters;
67
import org.gvsig.raster.osm.io.OSMProvider;
68
import org.gvsig.raster.osm.swing.AddOSMLayerPanel;
69
import org.gvsig.raster.osm.swing.OSMSwingLocator;
70
import org.slf4j.Logger;
71
import org.slf4j.LoggerFactory;
72

  
73
/**
74
 * Wizard panel to add a new OSM raster layer
75
 * @author Nacho Brodin (nachobrodin@gmail.com)
76
 */
77
public class AddOSMLayerWizard extends WizardPanel implements MouseListener {
78
	private static final long           serialVersionUID      = 1L;
79
	private static final String         TAB_NAME              = "OSM";
80
	private static Logger               logger                = LoggerFactory.getLogger(AddOSMLayerWizard.class.getName());
81
	private AddOSMLayerPanel            apiUI                 = null;
82
	private WizardListenerSupport       listenerSupport       = null;
83
	
84
	public AddOSMLayerWizard() {
85
		super();
86
		initialize();
87
	}
88

  
89
	/**
90
	 * This method initializes this
91
	 *
92
	 * @return void
93
	 */
94
	private void initialize() {
95
		setTabName(PluginServices.getText(this, TAB_NAME));
96
		setLayout(new GridBagLayout());
97
		GridBagConstraints gridBagConstraints = new GridBagConstraints();
98
		gridBagConstraints.fill = GridBagConstraints.BOTH;
99
		gridBagConstraints.weightx = 1.0;
100
		gridBagConstraints.weighty = 1.0;
101
		gridBagConstraints.insets = new Insets(6, 6, 6, 6);
102
		
103
		apiUI = OSMSwingLocator.getSwingManager().createAddOSMLayerPanel(new File(Launcher.getAppHomeDir()));
104
		
105
		//Copying osmservers.properties
106
		if(!new File(apiUI.getPropertiesFilePath()).exists()) {
107
			File pluginFolder = PluginsLocator.getManager().getPluginsFolder();
108
			File f = new File(pluginFolder.getAbsolutePath() + 
109
							File.separator + 
110
							"org.gvsig.raster.osm.app.osmclient" + 
111
							File.separator + 
112
							apiUI.getPropertiesFileName());
113
			FileUtils utils = RasterLocator.getManager().getFileUtils();
114
			try {
115
				utils.copyFile(f.getAbsolutePath(), Launcher.getAppHomeDir() + File.separator);
116
				apiUI = OSMSwingLocator.getSwingManager().createAddOSMLayerPanel(new File(Launcher.getAppHomeDir()));
117
			} catch (FileNotFoundException e) {
118
				logger.info("File not found copying osmservers.properties", e);
119
			} catch (IOException e) {
120
				logger.info("Error copying osmservers.properties", e);
121
			}
122
		}
123
		
124
		apiUI.addMouseListener(this);
125
		
126
		JPanel mainPanel = (JPanel)apiUI.getComponent();
127
		add(mainPanel, gridBagConstraints);
128
	}
129
	
130
	private WizardListenerSupport getWizardListenerSupport() {
131
		if(listenerSupport == null)
132
			listenerSupport = new WizardListenerSupport();
133
		return listenerSupport;
134
	}
135
	
136
	/**
137
	 * This method checks for the options selected within the configuration
138
	 * dialog are correct.
139
	 *
140
	 * @return true if you're done, false if not.
141
	 */
142
	public boolean areSettingsValid() {
143
		return apiUI.areSettingsValid(); 
144
	}
145
	
146
	public void addWizardListener(WizardListener listener) {
147
		getWizardListenerSupport().addWizardListener(listener);
148
		getWizardListenerSupport().callStateChanged(false);
149
	}
150

  
151
	public void removeWizardListener(WizardListener listener) {
152
		getWizardListenerSupport().removeWizardListener(listener);
153
	}
154
	
155
	@Override
156
	public void close() {
157
		
158
	}
159

  
160
	@Override
161
	public void execute() {
162
		if(!apiUI.areSettingsValid()) {
163
			messageBoxInfo("server_not_selected", PluginServices.getMDIManager().getActiveWindow(), null);
164
			return;
165
		}
166
			
167
		try {
168
			TileDataParameters tileParams = createDataParameters();
169
			
170
			//Getting the MapContext
171
			MapContext mapContext = getMapContext();
172
			
173
			if(mapContext == null) {
174
				mapContext = createViewWindow();
175
			}
176
			
177
			//Adding the layer
178
			FLyrOSM layer = buildLayer(tileParams);
179
			addLayerToMapContext(mapContext, layer);
180
		} catch (InitializeException e) {
181
			messageBoxInfo("error_creating_parameters", PluginServices.getMDIManager().getActiveWindow(), e);
182
		} catch (ProviderNotRegisteredException e) {
183
			messageBoxInfo("error_creating_parameters", PluginServices.getMDIManager().getActiveWindow(), e);
184
		} catch (LoadLayerException e) {
185
			messageBoxInfo("error_creating_the_view", PluginServices.getMDIManager().getActiveWindow(), e);
186
		}
187
	}
188
	
189
	/**
190
	 * Create the parameters to the provider
191
	 * @return
192
	 * @throws InitializeException
193
	 * @throws ProviderNotRegisteredException
194
	 */
195
	private TileDataParameters createDataParameters() throws InitializeException, ProviderNotRegisteredException {
196
		DataManagerProviderServices dataman = (DataManagerProviderServices) DALLocator.getDataManager();
197
		OSMDataParameters parameters = (OSMDataParameters)dataman.createStoreParameters(OSMProvider.NAME);
198
		parameters.setURI(apiUI.getSelectedURL());
199
		parameters.setTileSuffix(apiUI.getSelectedFormat());
200
		parameters.setOSMLayerName(apiUI.getSelectedName());
201
		try {
202
			parameters.setNumberOfLevels(new Integer(apiUI.getSelectedLevel()));
203
		} catch (NumberFormatException e) {
204
			
205
		}
206
		
207
		TileDataParameters tileParams = (TileDataParameters) dataman.createStoreParameters("Tile Store");
208
		tileParams.setDataParameters((DataParameters)parameters);
209
		return tileParams;
210
	}
211
	
212
	/**
213
	 * Adds the layer to the MapContext selected
214
	 * @param mapContext
215
	 * @param layer
216
	 */
217
	private void addLayerToMapContext(MapContext mapContext, FLyrOSM layer) {
218
		mapContext.beginAtomicEvent();
219
		layer.setVisible(true);
220
		mapContext.getLayers().addLayer(layer);
221
		mapContext.callLegendChanged();
222
		mapContext.endAtomicEvent();
223
	}
224
	
225
	/**
226
	 * Builds the OSM layer
227
	 * @param tileParams
228
	 * @return
229
	 */
230
	private FLyrOSM buildLayer(TileDataParameters tileParams) {
231
		FLyrOSM layer = new FLyrOSM();
232
		layer.deleteCache(false);  //Esto es parametrizable
233
		try {
234
			layer.setParameters(tileParams);
235
			layer.setName(apiUI.getSelectedName());
236
		} catch (InitializeException e) {
237
			messageBoxInfo("error_initializing_layer", PluginServices.getMDIManager().getActiveWindow(), e);
238
		}
239
		return layer;
240
	}
241
	
242
	/**
243
	 * Gets the active view or the first view opened if there is not 
244
	 * any with the focus
245
	 * @return
246
	 */
247
	public MapContext getMapContext() {
248
		IWindow window = PluginServices.getMDIManager().getFocusWindow();
249
		if(window instanceof AbstractViewPanel) {
250
			return ((AbstractViewPanel)window).getMapControl().getMapContext();
251
		}
252
		
253
		IWindow[] w = PluginServices.getMDIManager().getAllWindows();
254
		for (int i = 0; i < w.length; i++) {
255
			if (w[i] instanceof org.gvsig.app.project.documents.view.gui.AbstractViewPanel) {
256
				return ((AbstractViewPanel)w[i]).getMapControl().getMapContext();
257
			}
258
		}
259
		return null;
260
	}
261
	
262
	private void messageBoxInfo(String msg, Object parentWindow, Exception exception) {
263
		LoggerFactory.getLogger(getClass()).debug(msg, exception);
264
		String string = PluginServices.getText(parentWindow, "accept");
265
		Object[] options = {string};
266
		JOptionPane.showOptionDialog((Component)/*PluginServices.getMainFrame()*/parentWindow,
267
					"<html>" + PluginServices.getText(parentWindow, msg).replaceAll("\n", "<br>") + "</html>",
268
					PluginServices.getText(parentWindow, "confirmacion"),
269
					JOptionPane.OK_OPTION,
270
					JOptionPane.INFORMATION_MESSAGE,
271
					null,
272
					options,
273
					string);
274
	}
275
	
276
	/**
277
     * Create the view in the project. Add the blocks layer
278
     * to the view, and register the tool for get info of the
279
     * blocks.
280
     */
281
    @SuppressWarnings("deprecation")
282
	private MapContext createViewWindow() throws LoadLayerException {
283
    	ApplicationManager application = ApplicationLocator.getManager();
284

  
285
    	ProjectManager projectManager = application.getProjectManager();
286

  
287
    	// 1. Create a new view and set the name.
288
    	ViewManager viewManager = (ViewManager) projectManager.getDocumentManagers(ViewManager.TYPENAME);
289
    	ViewDocument view = (ViewDocument) viewManager.createDocument();
290
    	view.setName("OpenStreetMap View");
291

  
292
    	// 4. Add the view to the current project.
293
    	projectManager.getCurrentProject().add(view);
294

  
295
    	// 5. Force to show the view's window.
296
    	IView viewWindow = (IView) viewManager.getMainWindow(view);
297

  
298
    	application.getUIManager().addWindow(viewWindow, GridBagConstraints.CENTER);
299
    	try {
300
			application.getUIManager().setMaximum((IWindow) viewWindow, true);
301
		} catch (PropertyVetoException e) {
302
		}
303
    	
304
		if(viewWindow != null) {
305
			IProjection proj = CRSFactory.getCRS("EPSG:3857");
306
			if(proj != null)
307
				viewWindow.getMapControl().setProjection(proj);
308
			return viewWindow.getMapControl().getMapContext();
309
		}
310
		return null;
311
    }
312

  
313
	@Override
314
	public DataStoreParameters[] getParameters() {
315
		return null;
316
	}
317

  
318
	@Override
319
	public void initWizard() {
320
		
321
	}
322

  
323
	public void mouseClicked(MouseEvent e) {
324
		
325
	}
326

  
327
	public void mouseEntered(MouseEvent e) {
328
		
329
	}
330

  
331
	public void mouseExited(MouseEvent e) {
332
		
333
	}
334

  
335
	public void mousePressed(MouseEvent e) {
336
		getWizardListenerSupport().callStateChanged(true);
337
	}
338

  
339
	public void mouseReleased(MouseEvent e) {
340
		
341
	}
342
}
0 343

  
org.gvsig.raster.osm/tags/org.gvsig.raster.osm-2.2.16/org.gvsig.raster.osm.app.osmclient/src/main/java/org/gvsig/raster/osm/app/osmclient/OSMServer.java
1
/* OSM layers for gvSIG. 
2
 * Geographic Information System of the Valencian Government
3
*
4
* Copyright (C) 2012 Nacho Brodin
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
package org.gvsig.raster.osm.app.osmclient;
23

  
24
/**
25
 * Fixed parameters for a Open Street Map server. These parameters 
26
 * are known for each server added.
27
 * 
28
 * @author Nacho Brodin (nachobrodin@gmail.com)
29
 */
30
public class OSMServer {
31
	private String serverURL  = null;
32
	private int    levels     = 0;
33
	private String name       = null;
34
	private String suffix     = null;
35
	
36
	/**
37
	 * Constructor
38
	 * @param server
39
	 * 			The server URL
40
	 * @param levels
41
	 * 			The number of resolution levels
42
	 * @param name
43
	 * 			Layer's name
44
	 * @param suffix
45
	 * 			The suffix of the image file.
46
	 * 			
47
	 */
48
	public OSMServer(String server, int levels, String name, String suffix) {
49
		this.serverURL = server;
50
		this.levels = levels;
51
		this.name = name;
52
		this.suffix = suffix;
53
	}
54

  
55
	/**
56
	 * Gets the server URL
57
	 * @return
58
	 */
59
	public String getServerURL() {
60
		return serverURL;
61
	}
62

  
63
	/**
64
	 * Gets the number of resolution levels
65
	 * @return
66
	 */
67
	public int getLevels() {
68
		return levels;
69
	}
70

  
71
	/**
72
	 * Gets the layer's name
73
	 * @return
74
	 */
75
	public String getName() {
76
		return name;
77
	}
78

  
79
	/**
80
	 * Gets the suffix of the image file. 
81
	 * This suffix depends on the kind of the image (tif, png, jpg,...)
82
	 * @return
83
	 */
84
	public String getSuffix() {
85
		return suffix;
86
	}
87
	
88
	public String toString() {
89
		return name;
90
	}
91
}
0 92

  
org.gvsig.raster.osm/tags/org.gvsig.raster.osm-2.2.16/org.gvsig.raster.osm.app.osmclient/src/main/java/org/gvsig/raster/osm/app/osmclient/OSMClientExtension.java
1
/* OSM layers for gvSIG. 
2
 * Geographic Information System of the Valencian Government
3
*
4
* Copyright (C) 2012 Nacho Brodin
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
package org.gvsig.raster.osm.app.osmclient;
23

  
24
import java.io.File;
25
import java.io.IOException;
26
import java.sql.ResultSet;
27

  
28
import javax.swing.JOptionPane;
29

  
30
import org.cresques.cts.IProjection;
31
import org.gvsig.about.AboutManager;
32
import org.gvsig.about.AboutParticipant;
33
import org.gvsig.andami.IconThemeHelper;
34
import org.gvsig.andami.plugins.Extension;
35
import org.gvsig.app.ApplicationLocator;
36
import org.gvsig.app.ApplicationManager;
37
import org.gvsig.app.extension.AddLayer;
38
import org.gvsig.fmap.crs.CRSFactory;
39
import org.gvsig.i18n.Messages;
40
import org.gvsig.raster.osm.app.osmclient.layer.FLyrOSM;
41
import org.slf4j.Logger;
42
import org.slf4j.LoggerFactory;
43

  
44
/**
45
 * Extension for adding open street map support to gvSIG.
46
 * @author Nacho Brodin (nachobrodin@gmail.com)
47
 */
48
public class OSMClientExtension extends Extension {
49
	private Logger              log           = LoggerFactory.getLogger(OSMClientExtension.class);
50
	private String              fileCheck     = System.getProperty("user.home") + File.separator + "gvSIG" + File.separator + "osm_epsg_error";
51
	private String              epsgCode      = "3857";
52
	
53
	public void initialize() {
54
		/*
55
		 	#Thu May 23 15:49:23 CEST 2013
56
			Map_Quest=Map Quest*http\://oatile1.mqcdn.com/tiles/1.0.0/map*20*png
57
			Stamen=Stamen*http\://a.tile.stamen.com/terrain*17*jpg
58
			Open_Cycle_Map=Open Cycle Map*http\://tile.opencyclemap.org/cycle/*16*png
59
			Stamen_Toner=Stamen Toner*http\://tile.stamen.com/toner*17*jpg
60
			Map_Quest_Open_Aerial=Map Quest Open Aerial*http\://otile1.mqcdn.com/tiles/1.0.0/sat*20*jpg
61
			Mapnik=Mapnik*http\://tile.openstreetmap.org/*18*png
62
			Stamen_Water_Color=Stamen Water Color*http\://tile.stamen.com/watercolor*17*jpg
63
		 */
64
		
65
		IconThemeHelper.registerIcon(null, "icon-layer-osm", this);
66
	}
67

  
68
	public void postInitialize() {
69
		FLyrOSM.registerPersistent();
70
		addAboutInfo();
71
		AddLayer.addWizard(AddOSMLayerWizard.class);
72
		// loadEpsgCodeInJCRSUserDatabase();
73
	}
74
	
75
	/*
76
	private void loadEpsgCodeInJCRSUserDatabase() {
77
		IProjection proj = null;
78
		try {
79
			proj = CRSFactory.getCRS("EPSG:" + epsgCode);
80
		} catch(Exception e) {
81
		}
82
		
83
		if(proj != null)
84
			return;
85
		
86
		String wkt = "'PROJCS[\"WGS 84 / Pseudo-Mercator\",GEOGCS[\"Popular Visualisation CRS\",DATUM[\"D_Popular_Visualisation_Datum\",SPHEROID[\"Popular_Visualisation_Sphere\",6378137,0]],PRIMEM[\"Greenwich\",0],UNIT[\"Degree\",0.017453292519943295]],PROJECTION[\"Mercator\"],PARAMETER[\"central_meridian\",0],PARAMETER[\"scale_factor\",1],PARAMETER[\"false_easting\",0],PARAMETER[\"false_northing\",0],UNIT[\"Meter\",1]]'";
87
		try {
88
			es.idr.teledeteccion.connection.EpsgConnection conn = new es.idr.teledeteccion.connection.EpsgConnection();
89
			conn.setConnectionUsr();
90

  
91
			String query = "SELECT usr_code FROM USR WHERE usr_code='" + epsgCode + "'";
92
			ResultSet result = es.idr.teledeteccion.connection.Query.select(query, conn.getConnection());
93

  
94
			//Si no existe en c?digo se inserta para que la proyecci?n est? disponible
95

  
96
			if(result == null || !result.next()) { 
97
				String sentence = "INSERT INTO USR VALUES(" + epsgCode + ", " + wkt + ",'WGS 84 / Pseudo-Mercator','Usuario2','Popular_Visualisation_Datum')";
98
				conn.update(sentence);
99
				conn.shutdown();
100
			}
101
		} catch (Throwable e) {
102
			File f = new File(fileCheck);
103
			if(!f.exists())
104
				messageErrorEpsg("error_loading_epsg", f);
105
			log.info("Error accediendo a JCRS", e);
106
			return;
107
		} 
108
	}
109
	*/
110
	
111
	public void messageErrorEpsg(String msg, File f) {
112
		String string1 = Messages.getText("dont_remind_me_anymore");
113
		String string2 = Messages.getText("ok");
114
		Object[] options = {string1, string2};
115
		int n = JOptionPane.showOptionDialog(null,
116
					"<html>" + Messages.getText(msg).replaceAll("\n", "<br>") + "</html>",
117
					Messages.getText("confirmacion"),
118
					JOptionPane.YES_NO_OPTION,
119
					JOptionPane.QUESTION_MESSAGE,
120
					null,
121
					options,
122
					string1);
123
		if (n == 0) {
124
			try {
125
				f.createNewFile();
126
			} catch (IOException e) {
127
			}
128
		}
129
	}
130

  
131
	public void execute(String actionCommand) {
132

  
133
	}
134

  
135
	public boolean isEnabled() {
136
		return true;
137
	}
138

  
139
	public boolean isVisible() {
140
		return true;
141
	}
142
	
143
	private void addAboutInfo() {
144
        ApplicationManager application = ApplicationLocator.getManager();
145
        
146
        AboutManager about = application.getAbout();
147
        about.addDeveloper("Nacho Brodin", getClass().getClassLoader()
148
            .getResource("about/osm-about.html"), 2);
149

  
150
        AboutParticipant participant = about.getDeveloper("Nacho Brodin");
151
        participant.addContribution(
152
            "OSM",
153
            "Open Street Map client for gvSIG", 
154
            2012,1,1, 
155
            2012,1,15
156
        );      
157
    }
158
}
0 159

  
org.gvsig.raster.osm/tags/org.gvsig.raster.osm-2.2.16/org.gvsig.raster.osm.app.osmclient/src/main/java/org/gvsig/raster/osm/app/osmclient/layer/FLyrOSM.java
1
/* OSM layers for gvSIG. 
2
 * Geographic Information System of the Valencian Government
3
*
4
* Copyright (C) 2012 Nacho Brodin
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.osm.app.osmclient.layer;
24

  
25
import java.awt.Dimension;
26
import java.awt.Graphics2D;
27
import java.awt.Image;
28
import java.awt.Point;
29
import java.awt.geom.Point2D;
30
import java.awt.image.BufferedImage;
31
import java.lang.ref.WeakReference;
32
import java.util.ArrayList;
33
import java.util.HashMap;
34
import java.util.Iterator;
35
import java.util.List;
36

  
37
import javax.print.attribute.PrintRequestAttributeSet;
38

  
39
import org.cresques.cts.ICoordTrans;
40
import org.gvsig.andami.PluginServices;
41
import org.gvsig.fmap.dal.DALLocator;
42
import org.gvsig.fmap.dal.DataParameters;
43
import org.gvsig.fmap.dal.DataStore;
44
import org.gvsig.fmap.dal.DataStoreParameters;
45
import org.gvsig.fmap.dal.coverage.RasterLocator;
46
import org.gvsig.fmap.dal.coverage.RasterManager;
47
import org.gvsig.fmap.dal.coverage.datastruct.Extent;
48
import org.gvsig.fmap.dal.coverage.datastruct.NoData;
49
import org.gvsig.fmap.dal.coverage.datastruct.ViewPortData;
50
import org.gvsig.fmap.dal.coverage.exception.FilePaletteException;
51
import org.gvsig.fmap.dal.coverage.exception.InfoByPointException;
52
import org.gvsig.fmap.dal.coverage.exception.ProcessInterruptedException;
53
import org.gvsig.fmap.dal.coverage.exception.QueryException;
54
import org.gvsig.fmap.dal.coverage.grid.RasterFilter;
55
import org.gvsig.fmap.dal.coverage.store.RasterDataStore;
56
import org.gvsig.fmap.dal.coverage.store.parameter.RasterDataParameters;
57
import org.gvsig.fmap.dal.coverage.store.parameter.TileDataParameters;
58
import org.gvsig.fmap.dal.coverage.store.props.ColorInterpretation;
59
import org.gvsig.fmap.dal.exception.DataException;
60
import org.gvsig.fmap.dal.exception.InitializeException;
61
import org.gvsig.fmap.dal.exception.ProviderNotRegisteredException;
62
import org.gvsig.fmap.dal.exception.ReadException;
63
import org.gvsig.fmap.dal.exception.ValidateDataParametersException;
64
import org.gvsig.fmap.dal.spi.DataManagerProviderServices;
65
import org.gvsig.fmap.geom.Geometry.SUBTYPES;
66
import org.gvsig.fmap.geom.GeometryLocator;
67
import org.gvsig.fmap.geom.GeometryManager;
68
import org.gvsig.fmap.geom.exception.CreateEnvelopeException;
69
import org.gvsig.fmap.geom.primitive.Envelope;
70
import org.gvsig.fmap.mapcontext.ViewPort;
71
import org.gvsig.fmap.mapcontext.exceptions.LoadLayerException;
72
import org.gvsig.fmap.mapcontext.layers.FLayer;
73
import org.gvsig.fmap.mapcontext.layers.operations.IHasImageLegend;
74
import org.gvsig.fmap.mapcontext.rendering.legend.ILegend;
75
import org.gvsig.raster.fmap.layers.DefaultFLyrRaster;
76
import org.gvsig.raster.fmap.layers.IRasterLayerActions;
77
import org.gvsig.raster.fmap.layers.NotAvailableStateException;
78
import org.gvsig.raster.osm.io.OSMDataParameters;
79
import org.gvsig.raster.swing.RasterSwingLibrary;
80
import org.gvsig.raster.util.CancelTaskImpl;
81
import org.gvsig.tools.ToolsLocator;
82
import org.gvsig.tools.dynobject.DynObjectSet;
83
import org.gvsig.tools.dynobject.DynStruct;
84
import org.gvsig.tools.persistence.PersistenceManager;
85
import org.gvsig.tools.task.SimpleTaskStatus;
86
import org.gvsig.tools.task.TaskStatusManager;
87
import org.slf4j.Logger;
88
import org.slf4j.LoggerFactory;
89

  
90

  
91
/**
92
 * Open Street Map layer class.
93
 * @author Nacho Brodin (nachobrodin@gmail.com)
94
 */
95
public class FLyrOSM extends DefaultFLyrRaster implements IHasImageLegend {
96
	private static final GeometryManager geomManager               = GeometryLocator.getGeometryManager();
97
	private static final Logger          logger                    = LoggerFactory.getLogger(FLyrOSM.class);
98
	private List<WeakReference<Thread>>	 disableUpdateDrawVersion;
99
	private boolean						 firstLoad                 = false;
100
	private RasterManager                rManager                  = RasterLocator.getManager();
101
	private boolean                      deleteCache               = false;
102
	
103
	public static void registerPersistent() {
104
		PersistenceManager manager = ToolsLocator.getPersistenceManager();
105
		DynStruct definition = manager.getDefinition("FLyrOSM_Persistent");
106
		if( definition == null ) {
107
			if (manager.getDefinition(DefaultFLyrRaster.class) == null) {
108
				DefaultFLyrRaster.registerPersistence();
109
			}
110

  
111
			definition = manager.addDefinition(
112
					FLyrOSM.class,
113
					"FLyrOSM_Persistent",
114
					"FLyrOSM Persistent Definition",
115
					null, 
116
					null
117
			);
118
			
119
			definition.extend(PersistenceManager.PERSISTENCE_NAMESPACE, DefaultFLyrRaster.PERSISTENT_NAME);
120
		}
121
	}
122

  
123
	public FLyrOSM() {
124
		super();
125
		this.updateDrawVersion();
126
		try {
127
			enableAwake();
128
		} catch (NotAvailableStateException e) {
129
			logger.error("Fallo el estado de open. Closed=" + isClosed() + " Awake=" + isAwake(), this, e);
130
		}
131
	}
132
	
133
	public static DataStore createDataStore(String host) throws InitializeException {
134
		DataManagerProviderServices dataman = (DataManagerProviderServices) DALLocator.getDataManager();
135
		RasterDataParameters params = null;
136
		try {
137
			params = (RasterDataParameters)dataman.createStoreParameters("OSM Raster");
138
		} catch (InitializeException e) {
139
			RasterSwingLibrary.messageBoxInfo("error_creating_parameters", PluginServices.getMDIManager().getActiveWindow(), e);
140
		} catch (ProviderNotRegisteredException e) {
141
			RasterSwingLibrary.messageBoxInfo("error_creating_parameters", PluginServices.getMDIManager().getActiveWindow(), e);
142
		}
143
		params.setURI(host);
144
		
145
		try {
146
			return dataman.openStore(params.getDataStoreName(), params);
147
		} catch (ValidateDataParametersException e) {
148
			throw new InitializeException(e);
149
		} catch (ProviderNotRegisteredException e) {
150
			throw new InitializeException(e);
151
		}
152
	}
153

  
154
	public void setDataStore(DataStore dataStore) throws LoadLayerException {
155
		this.dataStore = (RasterDataStore) dataStore;
156
		try {
157
			enableOpen();
158
		} catch (NotAvailableStateException e) {
159
			logger.error("Fallo el estado de open. Closed=" + isClosed() + " Awake=" + isAwake(), this, e);
160
		}
161
		setProjection(this.dataStore.getProjection());
162
		//setFullExtent(this.dataStore.getExtent().toRectangle2D());
163
	}
164
	
165
	@SuppressWarnings("deprecation")
166
	public void draw(BufferedImage image, Graphics2D g, ViewPort viewPort,
167
			 org.gvsig.tools.task.Cancellable cancel, double scale) throws ReadException {
168
		TaskStatusManager manager = ToolsLocator.getTaskStatusManager();
169
		SimpleTaskStatus taskStatus = new RasterTaskStatus("Drawing " + getName() + "...", cancel);
170
		manager.add(taskStatus);
171
		taskStatus.setAutoremove(true);
172

  
173
		//Solo el zoom normal recalcula el nivel dependiendo de la escala. El zoom por niveles asigna
174
		//?l el nivel de zoom por lo que no habr? que recalcularlo.
175
		if(recalcLevel) {
176
			double pixelSize = viewPort.getExtent().getWidth() / (double)viewPort.getImageWidth();
177
			zoomLevel = dataStore.getNearestLevel(pixelSize);
178
		}
179
		recalcLevel = true;
180
		
181
		if(!firstLoad) {
182
			try {
183
				initFilters();
184
				try {
185
					if(!isOpen())
186
						enableOpen();
187
				} catch (NotAvailableStateException e) {
188
					throw new ReadException("Fallo el estado de open. Closed=" + isClosed() + " Awake=" + isAwake(), e);
189
				}
190
			} catch (FilePaletteException e) {
191
				throw new ReadException(e.getMessage(), e);
192
			}
193
			firstLoad = true;
194
		}
195
		
196
		enableStopped();
197

  
198
		if (isWithinScale(scale)) {
199
			if (!viewPort.getAdjustedExtent().intersects(getFullEnvelope()))
200
				return;
201
			Envelope adjustedExtent = viewPort.getAdjustedEnvelope();
202
			Extent ext = rManager.getDataStructFactory().createExtent(
203
					adjustedExtent.getLowerCorner().getX(),
204
					adjustedExtent.getUpperCorner().getY(), 
205
					adjustedExtent.getUpperCorner().getX(),
206
					adjustedExtent.getLowerCorner().getY());
207
			Dimension imgSz = viewPort.getImageSize();
208
			ViewPortData vp2 = rManager.getDataStructFactory().createViewPortData(viewPort.getProjection(), ext, imgSz );
209
			vp2.setMat(viewPort.getAffineTransform());
210
			vp2.setDPI((int)viewPort.getDPI());
211
			
212
			try {
213
				OSMDataParameters par = getOSMParameters(getDataStore().getParameters());
214
				par.setWidth((int)viewPort.getImageSize().getWidth());
215
				par.setHeight((int)viewPort.getImageSize().getHeight());
216
				
217
				getRender().drawTiledService(g, vp2, viewPort.getImageSize(), taskStatus);
218
			} catch (ProcessInterruptedException e) {
219
				throw new ReadException("Problems drawing this layer: " + e.getMessage(), e);
220
			} catch (QueryException e) {
221
				throw new ReadException("Problems drawing this layer: " + e.getMessage(), e);
222
			} finally {
223
				taskStatus.terminate();
224
			}
225
		}
226
		disableStopped();
227
	}
228
	
229

  
230
	/**
231
	 * @see com.iver.cit.gvsig.fmap.layers.FLayer#print(java.awt.Graphics2D,
232
	 * 		com.iver.cit.gvsig.fmap.ViewPort,
233
	 * 		com.iver.cit.gvsig.fmap.operations.Cancellable)
234
	 */
235
	@SuppressWarnings("deprecation")
236
	public void print(Graphics2D g, ViewPort viewPort,  org.gvsig.tools.task.Cancellable cancel, 
237
			double scale, PrintRequestAttributeSet properties) throws ReadException {
238
		
239
	}
240

  
241
	@SuppressWarnings("deprecation")
242
	public void _print(Graphics2D g, ViewPort viewPort,  org.gvsig.tools.task.Cancellable cancel,
243
			double scale) throws ReadException {
244
		draw(null, g, viewPort, cancel,scale);
245
	}
246

  
247
	public HashMap<String, Object> getProperties() {
248
		HashMap<String, Object> info = new HashMap<String, Object>();
249
		OSMDataParameters par = getOSMParameters(getDataStore().getParameters());
250
		String layerName = getName();
251
		try {
252
			info.put("selectedLayer", layerName);
253
			info.put("host", par.getURI());
254
			info.put("srs", dataStore.getProjection().getAbrev());
255
			return info;
256
		} catch (Exception e) {
257
			e.printStackTrace();
258
		}
259
		return null;
260
	}
261

  
262

  
263
	public String getTocImageIcon() {
264
		return "icon-layer-osm";
265
	}
266

  
267
	public boolean isActionEnabled(int action) {
268
		switch (action) {
269
		case IRasterLayerActions.ZOOM_PIXEL_RESOLUTION:
270
		case IRasterLayerActions.FLYRASTER_BAR_TOOLS:
271
		case IRasterLayerActions.BANDS_FILE_LIST:
272
		case IRasterLayerActions.GEOLOCATION:
273
		case IRasterLayerActions.PANSHARPENING:
274
		case IRasterLayerActions.SAVE_COLORINTERP:
275
		case IRasterLayerActions.SAVEAS:
276
		case IRasterLayerActions.BANDS_RGB:
277
		case IRasterLayerActions.CLIPPING:
278
		case IRasterLayerActions.ENHANCED:
279
		case IRasterLayerActions.STATS:
280
		case IRasterLayerActions.NODATA:
281
		case IRasterLayerActions.HISTOGRAM:
282
			return false;
283
		case IRasterLayerActions.COLOR_TABLE:
284
		case IRasterLayerActions.REMOTE_ACTIONS:
285
			return true;
286
		}
287

  
288
		return super.isActionEnabled(action);
289
	}
290

  
291
	public ILegend getLegend() {
292
		return null;
293
	}
294
	
295
	public boolean isRemote() {
296
		return true;
297
	}
298

  
299
	public boolean overviewsSupport() {
300
		return false;
301
	}
302

  
303
	protected void updateDrawVersion() {
304
		if (this.disableUpdateDrawVersion != null){
305

  
306
			Thread curThread = Thread.currentThread();
307

  
308
			Thread aThread;
309

  
310
			Iterator<WeakReference<Thread>> iter = this.disableUpdateDrawVersion.iterator();
311
			while (iter.hasNext()){
312
				aThread = (Thread) ((WeakReference<?>)iter.next()).get();
313
				if (aThread == null){
314
					iter.remove();
315
				} else if(aThread.equals(curThread)){
316
					return;
317
				}
318
			}
319
		}
320
		super.updateDrawVersion();
321
	}
322

  
323
	protected void disableUpdateDrawVersion() {
324
		if (this.disableUpdateDrawVersion == null) {
325
			this.disableUpdateDrawVersion = new ArrayList<WeakReference<Thread>>();
326
		}
327
		this.disableUpdateDrawVersion.add(new WeakReference<Thread>(Thread.currentThread()));
328
	}
329

  
330
	protected void enableUpdateDrawVersion() {
331
		if (this.disableUpdateDrawVersion == null) {
332
			return;
333
		}
334
		Thread curThread = Thread.currentThread();
335
		Thread aThread;
336

  
337
		Iterator<WeakReference<Thread>> iter = this.disableUpdateDrawVersion.iterator();
338
		while (iter.hasNext()) {
339
			aThread = (Thread) ((WeakReference<?>)iter.next()).get();
340
			if (aThread == null) {
341
				iter.remove();
342
			} else if(aThread.equals(curThread)) {
343
				iter.remove();
344
				break;
345
			}
346
		}
347

  
348
	}
349

  
350
	/*private Rectangle2D.Double getRectable2DFromEnvelope(Envelope env) {
351
		return new Rectangle2D.Double(env.getMinimum(0), env.getMinimum(1), env
352
				.getLength(0), env.getLength(1));
353
	}
354

  
355
	private Envelope getEnvelopeFromRectable2D(Rectangle2D rect) {
356
		try {
357
			return geomManager.createEnvelope(rect.getMinX(), rect.getMinY(),
358
					rect.getMaxX(), rect.getMaxY(),
359
					SUBTYPES.GEOM2D);
360
		} catch (CreateEnvelopeException e) {
361
			logger.error("Error creating the envelope", e);
362
		}
363
		return null;
364
	}*/
365
	
366
	@Override
367
	public String getFileFormat() {
368
		return "OSM";
369
	}
370
	
371

  
372
	/**
373
	 * Devuelve el envelope en la proyeccion de la vista
374
	 */
375
	public Envelope getFullEnvelope() {
376
		Extent e1 = getDataStore().getExtent();
377
		Envelope rAux = null;
378
		try {
379
			rAux = geomManager.createEnvelope(e1.getMin().getX(), e1.getMin().getY(), e1.getMax().getX(), e1.getMax().getY(), SUBTYPES.GEOM2D);
380
		} catch (CreateEnvelopeException exc) {
381
			logger.error("Error creating the envelope", exc);
382
		}
383

  
384
		// Esto es para cuando se crea una capa nueva con el fullExtent de ancho
385
		// y alto 0.
386
		if (rAux == null || rAux.getMaximum(0) - rAux.getMinimum(0) == 0
387
				&& rAux.getMaximum(1) - rAux.getMinimum(1) == 0) {
388
			try {
389
				rAux = geomManager.createEnvelope(0, 0, 100, 100, SUBTYPES.GEOM2D);
390
			} catch (CreateEnvelopeException e) {
391
				logger.error("Error creating the envelope", e);
392
			}
393
		}
394
		// Si existe reproyecci?n, reproyectar el extent
395
		ICoordTrans ct = getCoordTrans();
396
		if (ct != null) {
397
			Point2D pt1 = new Point2D.Double(rAux.getMinimum(0), rAux
398
					.getMinimum(1));
399
			Point2D pt2 = new Point2D.Double(rAux.getMaximum(0), rAux
400
					.getMaximum(1));
401
			pt1 = ct.convert(pt1, null);
402
			pt2 = ct.convert(pt2, null);
403
			try {
404
				rAux = geomManager.createEnvelope(pt1.getX(), pt1.getY(), pt2
405
						.getX(), pt2.getY(), SUBTYPES.GEOM2D);
406
			} catch (CreateEnvelopeException e) {
407
				logger.error("Error creating the envelope", e);
408
			}// new
409
			// Rectangle2D.Double();
410
		}
411
		return rAux;
412

  
413
	}
414
	
415
	public Extent getFullRasterExtent() {
416
		Envelope env = getFullEnvelope();
417
		double minx = env.getMinimum(0);
418
		double miny = env.getMinimum(1);
419
		double maxx = env.getMaximum(0);
420
		double maxy = env.getMaximum(1);
421
		Point2D ul = new Point2D.Double(minx, maxy);
422
		Point2D ur = new Point2D.Double(maxx, maxy);
423
		Point2D ll = new Point2D.Double(minx, miny);
424
		Point2D lr = new Point2D.Double(maxx, miny);
425
		return rManager.getDataStructFactory().createExtent(ul, lr, ur, ll);
426
	}
427

  
428
    @SuppressWarnings("deprecation")
429
	public DynObjectSet getInfo(Point p, double tolerance, org.gvsig.tools.task.Cancellable cancel)
430
		throws LoadLayerException, DataException {
431
		
432
		return null;
433
	}
434
    
435
    @SuppressWarnings("deprecation")
436
	public DynObjectSet getInfo(Point p, double tolerance, org.gvsig.tools.task.Cancellable cancel, boolean fast)
437
    throws LoadLayerException, DataException {
438

  
439
    	Point2D pReal = getMapContext().getViewPort().toMapPoint(p);
440
    	@SuppressWarnings("unused")
441
		String fInfo = null;
442
    	try {
443
    		fInfo = getDataStore().getInfoByPoint(pReal.getX(), pReal.getY(), new CancelTaskImpl(cancel));
444
    	} catch (InfoByPointException e) {
445
    		throw new LoadLayerException("Error in getInfoByPoint", e);
446
    	}
447
    	return null;
448
    	//return new DynObjectSetWMTSInfo(fInfo, type);
449
    }
450
    
451
    /**
452
     * Sets the data store parameters
453
     * @param params
454
     * @throws InitializeException
455
     */
456
    public void setParameters(DataStoreParameters params) throws InitializeException {
457
		if(params instanceof TileDataParameters) {
458
			((TileDataParameters)params).deleteCache(deleteCache);
459
		}
460
		
461
    	DataManagerProviderServices dataman = (DataManagerProviderServices) DALLocator.getDataManager();
462
		try {
463
			DataStore dStore = dataman.openStore(params.getDataStoreName(), params);
464
			this.setDataStore(dStore);
465
			
466
			if(params instanceof OSMDataParameters) {
467
				this.setName(((OSMDataParameters) params).getURI());
468
			}
469
			
470
			if(params instanceof TileDataParameters) {
471
				DataParameters p = ((TileDataParameters) params).getDataParameters();
472
				if(p instanceof OSMDataParameters) {
473
					this.setName(((OSMDataParameters) p).getURI());
474
				}
475
			}
476
			
477
		} catch (ValidateDataParametersException e) {
478
			throw new InitializeException(e);
479
		} catch (ProviderNotRegisteredException e) {
480
			throw new InitializeException(e);
481
		} catch (InitializeException e) {
482
			throw new InitializeException(e);
483
		} catch (LoadLayerException e) {
484
			throw new InitializeException(e);
485
		}
486
    }
487
    
488
    /**
489
     * Gets <code>WMTSDataParameters</code>
490
     * @param parameters
491
     * @return
492
     */
493
    private OSMDataParameters getOSMParameters(DataStoreParameters parameters) {
494
    	OSMDataParameters params = null;
495
    	if(parameters instanceof OSMDataParameters) {
496
			params = (OSMDataParameters) parameters;
497
		}
498
		
499
		if(parameters instanceof TileDataParameters) {
500
			DataParameters p = ((TileDataParameters) parameters).getDataParameters();
501
			if(p instanceof OSMDataParameters) {
502
				params = (OSMDataParameters) p;
503
			}
504
		}
505
		return params;
506
    }
507

  
508
	public Image getImageLegend() {
509
		return null;
510
	}
511

  
512
	public String getPathImage() {
513
		return null;
514
	}
515
	
516
	public FLayer cloneLayer() throws Exception {
517
		RasterDataStore  ds = dataStore.cloneDataStore();
518
		FLyrOSM newLayer = new FLyrOSM();
519
		newLayer.setName(getName());
520
		newLayer.setOpenRasterStore(ds);
521
		newLayer.firstLoad = firstLoad;
522
		
523
		List<RasterFilter> filters = getRender().getFilterList().getStatusCloned();
524

  
525
		//Hacemos una copia de las bandas a renderizar
526
		ColorInterpretation ci = getRender().getRenderColorInterpretation();
527
		if(ci != null) {
528
			newLayer.getRender().setRenderColorInterpretation(ci.cloneColorInterpretation());
529
		}
530

  
531
		//Asignamos el entorno
532
		if(newLayer.getRender().getFilterList() == null)
533
			newLayer.getRender().setFilterList(RasterLocator.getManager().createEmptyFilterList(getRender().getFilterList().getInitDataType()));
534
		newLayer.getRender().getFilterList().setEnv(getRender().getFilterList().getEnv());
535
		newLayer.getRender().getFilterList().setStatus(filters);
536

  
537
		// Asignamos los valores noData del original
538
		NoData nd = (NoData)getNoDataValue().clone();
539
		newLayer.setNoDataValue(nd);
540
		newLayer.enableOpen();
541
		
542
		return newLayer;
543
	}
544

  
545
	/**
546
	 * Assigns the flag to delete this layer from the cache
547
	 * @param selected
548
	 */
549
	public void deleteCache(boolean deleteCache) {
550
		this.deleteCache = deleteCache;
551
	}
552
}
0 553

  
org.gvsig.raster.osm/tags/org.gvsig.raster.osm-2.2.16/org.gvsig.raster.osm.app.osmclient/src/main/resources-plugin/text.properties
1
error_creating_the_view=Error creando una vista nueva. Pruebe creando una manualmente.
2
error_creating_parameters=Error creando los par?metros
3
server_not_selected=No hay un servidor seleccionado
4
error_loading_epsg=Error cargando el EPSG:3785 desde el plugin de OSM.\n Comprueba que la extensi?n JCRS est? instalada y funcionando. \n Esta proyecci?n no estar? disponible aunque la \n carga de tiles deber?a funcionar correctamente.
5
dont_remind_me_anymore=No me lo recuerdes m?s
6
ok=OK
0 7

  
org.gvsig.raster.osm/tags/org.gvsig.raster.osm-2.2.16/org.gvsig.raster.osm.app.osmclient/src/main/resources-plugin/text_en.properties
1
error_creating_the_view=Error creating a new view
2
error_creating_parameters=Error creating the parameters
3
server_not_selected=There is not a server selected
4
error_loading_epsg=Error loading EPSG:3785 in database from OSM plug-in.\n Checks if JCRS plug-in is installed and running. \nThis projection is not available.
5
dont_remind_me_anymore=Don't remind me anymore
6
ok=OK
0 7

  
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff