Statistics
| Revision:

svn-gvsig-desktop / branches / v10 / extensions / extPublish / src / com / iver / cit / gvsig / publish / layers / LayerLoader.java @ 10874

History | View | Annotate | Download (4.64 KB)

1
package com.iver.cit.gvsig.publish.layers;
2

    
3
import java.util.HashMap;
4
import java.util.Map;
5

    
6
import org.gvsig.remoteservices.conf.mapserver.MapServerConfiguration.ConfigFile;
7
import org.gvsig.remoteservices.conf.mapserver.MapServerConfiguration.MapLayer;
8

    
9
import com.iver.andami.PluginServices;
10
import com.iver.cit.gvsig.fmap.layers.FLayer;
11
import com.iver.cit.gvsig.project.documents.view.gui.View;
12
import com.iver.cit.gvsig.publish.Servers;
13
import com.iver.utiles.extensionPoints.ExtensionPoint;
14
import com.iver.utiles.extensionPoints.ExtensionPointsSingleton;
15
import com.iver.utiles.swing.jcomboServer.ServerData;
16

    
17
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
18
 *
19
 * Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
20
 *
21
 * This program is free software; you can redistribute it and/or
22
 * modify it under the terms of the GNU General Public License
23
 * as published by the Free Software Foundation; either version 2
24
 * of the License, or (at your option) any later version.
25
 *
26
 * This program is distributed in the hope that it will be useful,
27
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
28
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
29
 * GNU General Public License for more details.
30
 *
31
 * You should have received a copy of the GNU General Public License
32
 * along with this program; if not, write to the Free Software
33
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
34
 *
35
 * For more information, contact:
36
 *
37
 *  Generalitat Valenciana
38
 *   Conselleria d'Infraestructures i Transport
39
 *   Av. Blasco Ib??ez, 50
40
 *   46010 VALENCIA
41
 *   SPAIN
42
 *
43
 *      +34 963862235
44
 *   gvsig@gva.es
45
 *      www.gvsig.gva.es
46
 *
47
 *    or
48
 *
49
 *   IVER T.I. S.A
50
 *   Salamanca 50
51
 *   46005 Valencia
52
 *   Spain
53
 *
54
 *   +34 963163400
55
 *   dac@iver.es
56
 */
57
/* CVS MESSAGES:
58
 *
59
 * $Id: LayerLoader.java 10874 2007-03-23 08:52:35Z dagilgon $
60
 * $Log$
61
 * Revision 1.6.2.2  2007-03-23 08:52:34  dagilgon
62
 * *** empty log message ***
63
 *
64
 * Revision 1.6.2.1  2006/11/15 04:11:02  jjdelcerro
65
 * *** empty log message ***
66
 *
67
 * Revision 1.6  2006/10/05 13:20:05  jvhigon
68
 * Debido a los cambios de nombre MapserverConfigFile y GeoserverConfig
69
 *
70
 * Revision 1.5  2006/10/03 10:30:14  dagilgon
71
 * adaptation to branch v10
72
 *
73
 * Revision 1.4  2006/09/28 15:04:02  fjp
74
 * Usar siempre que se pueda ISymbol en lugar de FSymbol
75
 *
76
 * Revision 1.3  2006/09/19 00:30:31  luisw2
77
 * Soporte para WCS en mapserver. Pendiente de verificar que va
78
 *
79
 * Revision 1.2  2006/09/08 12:50:20  jorpiell
80
 * Se tiene en cuanta el par?metro TIME
81
 *
82
 * Revision 1.1  2006/09/07 19:13:39  jorpiell
83
 * Ya se pueden cargar im?genes
84
 *
85
 *
86
 */
87
/**
88
 * @author Jorge Piera Llodr? (piera_jor@gva.es)
89
 */
90
public class LayerLoader {
91
        public static final String GROUP_LAYER_TIME = "TIME";
92
        public static final String GROUP_LAYER_MOSAIC = "MOSAIC";
93
        
94
        public static void loadLayers(ServerData serverData,ConfigFile map){
95
                for (int i=0 ; i<map.layersCnt() ; i++){
96
                        try{
97
                                loadLayer(serverData,(MapLayer)map.getLayer(i));
98
                        }catch(Exception e){
99
                                e.printStackTrace();
100
                        }
101
                }
102
        }
103
        
104
        public static void loadLayer(ServerData serverData,MapLayer mapLayer)throws Exception{
105
                FLayer layer = null;
106
                if (serverData.getServiceType().compareTo(Servers.SERVER_TYPE_WMS) == 0){
107
                        layer = createWMSLayer(serverData.getServerAddress(),mapLayer.name,mapLayer.crs.getCrs());
108
                }else if(serverData.getServiceType().compareTo(Servers.SERVER_TYPE_WFS) == 0){
109
                        layer = createWFSLayer(serverData.getServerAddress(),mapLayer.name);
110
                }        
111
                if (layer != null){
112
                        loadLayer(layer);
113
                }
114
        }
115
        
116
        private static void loadLayer(FLayer layer){
117
                View theView = 
118
                        (View) PluginServices.getMDIManager().getActiveWindow();
119
                        
120
                theView.getMapControl().getMapContext().beginAtomicEvent();
121
                theView.getMapControl().getMapContext().getLayers().addLayer(layer);
122
                theView.getMapControl().getMapContext().endAtomicEvent();
123
                layer.setActive(true);
124
                PluginServices.getMainFrame().enableControls();        
125
        }
126
        
127
        private static FLayer createWMSLayer(String host,String layerName,String srs) throws Exception{
128
                ExtensionPoint extensionPoint = (ExtensionPoint)ExtensionPointsSingleton.getInstance().get("CatalogLayers");
129
                Map args = new HashMap();
130
                args.put("host",host + "&service=WMS");
131
                args.put("layer",layerName);
132
                args.put("SRS",srs);
133
                return (FLayer)extensionPoint.create("OGC:WMS",args);                
134
        }
135
        
136
        private static FLayer createWFSLayer(String host,String layerName)throws Exception{
137
                ExtensionPoint extensionPoint = (ExtensionPoint)ExtensionPointsSingleton.getInstance().get("CatalogLayers");
138
                Map args = new HashMap();
139
                args.put("host",host);
140
                args.put("layer",layerName);
141
                args.put("user","");
142
                args.put("pwd","");
143
                return (FLayer)extensionPoint.create("OGC:WFS", args);
144
        }
145
}