Statistics
| Revision:

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

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