Statistics
| Revision:

root / trunk / extensions / extPublish / src / com / iver / cit / gvsig / publish / layers / LayerLoader.java @ 7804

History | View | Annotate | Download (4.31 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.MapServer.ConfigFile;
7
import org.gvsig.remoteservices.conf.mapserver.MapServer.MapLayer;
8

    
9
import com.iver.andami.PluginServices;
10
import com.iver.cit.gvsig.fmap.layers.FLayer;
11
import com.iver.cit.gvsig.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 7804 2006-10-03 10:30:14Z dagilgon $
60
 * $Log$
61
 * Revision 1.5  2006-10-03 10:30:14  dagilgon
62
 * adaptation to branch v10
63
 *
64
 * Revision 1.4  2006/09/28 15:04:02  fjp
65
 * Usar siempre que se pueda ISymbol en lugar de FSymbol
66
 *
67
 * Revision 1.3  2006/09/19 00:30:31  luisw2
68
 * Soporte para WCS en mapserver. Pendiente de verificar que va
69
 *
70
 * Revision 1.2  2006/09/08 12:50:20  jorpiell
71
 * Se tiene en cuanta el par?metro TIME
72
 *
73
 * Revision 1.1  2006/09/07 19:13:39  jorpiell
74
 * Ya se pueden cargar im?genes
75
 *
76
 *
77
 */
78
/**
79
 * @author Jorge Piera Llodr? (piera_jor@gva.es)
80
 */
81
public class LayerLoader {
82
        public static final String GROUP_LAYER_TIME = "TIME";
83
        public static final String GROUP_LAYER_MOSAIC = "MOSAIC";
84
        
85
        public static void loadLayers(ServerData serverData,ConfigFile map){
86
                for (int i=0 ; i<map.layersCnt() ; i++){
87
                        try{
88
                                loadLayer(serverData,(MapLayer)map.getLayer(i));
89
                        }catch(Exception e){
90
                                e.printStackTrace();
91
                        }
92
                }
93
        }
94
        
95
        public static void loadLayer(ServerData serverData,MapLayer mapLayer)throws Exception{
96
                FLayer layer = null;
97
                if (serverData.getServiceType().compareTo(Servers.SERVER_TYPE_WMS) == 0){
98
                        layer = createWMSLayer(serverData.getServerAddress(),mapLayer.name,mapLayer.crs.getCrs());
99
                }else if(serverData.getServiceType().compareTo(Servers.SERVER_TYPE_WFS) == 0){
100
                        layer = createWFSLayer(serverData.getServerAddress(),mapLayer.name);
101
                }        
102
                if (layer != null){
103
                        loadLayer(layer);
104
                }
105
        }
106
        
107
        private static void loadLayer(FLayer layer){
108
                View theView = 
109
                        (View) PluginServices.getMDIManager().getActiveWindow();
110
                        
111
                theView.getMapControl().getMapContext().beginAtomicEvent();
112
                theView.getMapControl().getMapContext().getLayers().addLayer(layer);
113
                theView.getMapControl().getMapContext().endAtomicEvent();
114
                layer.setActive(true);
115
                PluginServices.getMainFrame().enableControls();        
116
        }
117
        
118
        private static FLayer createWMSLayer(String host,String layerName,String srs) throws Exception{
119
                ExtensionPoint extensionPoint = (ExtensionPoint)ExtensionPointsSingleton.getInstance().get("CatalogLayers");
120
                Map args = new HashMap();
121
                args.put("host",host + "&service=WMS");
122
                args.put("layer",layerName);
123
                args.put("SRS",srs);
124
                return (FLayer)extensionPoint.create("OGC:WMS",args);                
125
        }
126
        
127
        private static FLayer createWFSLayer(String host,String layerName)throws Exception{
128
                ExtensionPoint extensionPoint = (ExtensionPoint)ExtensionPointsSingleton.getInstance().get("CatalogLayers");
129
                Map args = new HashMap();
130
                args.put("host",host);
131
                args.put("layer",layerName);
132
                args.put("user","");
133
                args.put("pwd","");
134
                return (FLayer)extensionPoint.create("OGC:WFS", args);
135
        }
136
}