View Javadoc
1   package fr.ifremer.dali.ui.swing.util.map;
2   
3   /*-
4    * #%L
5    * Dali :: UI
6    * $Id:$
7    * $HeadURL:$
8    * %%
9    * Copyright (C) 2014 - 2017 Ifremer
10   * %%
11   * This program is free software: you can redistribute it and/or modify
12   * it under the terms of the GNU Affero General Public License as published by
13   * the Free Software Foundation, either version 3 of the License, or
14   * (at your option) any later version.
15   * 
16   * This program is distributed in the hope that it will be useful,
17   * but WITHOUT ANY WARRANTY; without even the implied warranty of
18   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19   * GNU General Public License for more details.
20   * 
21   * You should have received a copy of the GNU Affero General Public License
22   * along with this program.  If not, see <http://www.gnu.org/licenses/>.
23   * #L%
24   */
25  
26  import com.google.common.collect.Lists;
27  import org.geotools.data.ows.Layer;
28  import org.geotools.data.wms.WebMapServer;
29  import org.geotools.map.MapContent;
30  import org.geotools.map.WMSLayer;
31  import org.geotools.swing.JMapFrame;
32  import org.geotools.swing.wms.WMSChooser;
33  import org.geotools.swing.wms.WMSLayerChooser;
34  
35  import javax.swing.*;
36  import java.net.URL;
37  import java.util.List;
38  /**
39   * This is a Web Map Server "quickstart" doing the minimum required to display
40   * something on screen.
41   */
42  public class WMSLab extends JFrame {
43      /**
44       * Prompts the user for a wms service, connects, and asks for a layer and then
45       * and displays its contents on the screen in a map frame.
46       */
47      public static void main(String[] args) throws Exception {
48  
49          List<String> sextantServers = Lists.newArrayList(
50                  "http://www.ifremer.fr/services/wms1?Service=WMS&Request=GetCapabilities" //&Version=1.1.1
51          );
52  
53          // display a data store file chooser dialog for shapefiles
54          URL capabilitiesURL = WMSChooser.showChooseWMS(sextantServers);
55          if( capabilitiesURL == null ){
56              System.exit(0); // canceled
57          }
58          WebMapServer wms = new WebMapServer( capabilitiesURL );
59  
60          List<Layer> wmsLayers = WMSLayerChooser.showSelectLayer( wms );
61          if( wmsLayers == null ){
62              JOptionPane.showMessageDialog(null, "Could not connect - check url");
63              System.exit(0);
64          }
65          MapContent mapcontent = new MapContent();
66          mapcontent.setTitle( wms.getCapabilities().getService().getTitle() );
67  
68          for( Layer wmsLayer : wmsLayers ){
69              WMSLayer displayLayer = new WMSLayer(wms, wmsLayer );
70              mapcontent.addLayer(displayLayer);
71          }
72          // Now display the map
73          JMapFrame.showMap(mapcontent);
74      }
75  }