Statistics
| Revision:

root / trunk / libraries / libGPE-KML / src / org / gvsig / gpe / kml / parser / v21 / features / LookAtBinding.java @ 21966

History | View | Annotate | Download (4.78 KB)

1
package org.gvsig.gpe.kml.parser.v21.features;
2

    
3
import java.io.IOException;
4

    
5
import javax.xml.namespace.QName;
6

    
7
import org.gvsig.gpe.kml.parser.GPEDeafultKmlParser;
8
import org.gvsig.gpe.kml.utils.Kml2_1_Tags;
9
import org.gvsig.gpe.xml.stream.IXmlStreamReader;
10
import org.gvsig.gpe.xml.stream.XmlStreamException;
11
import org.gvsig.gpe.xml.utils.CompareUtils;
12

    
13
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
14
 *
15
 * Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
16
 *
17
 * This program is free software; you can redistribute it and/or
18
 * modify it under the terms of the GNU General Public License
19
 * as published by the Free Software Foundation; either version 2
20
 * of the License, or (at your option) any later version.
21
 *
22
 * This program is distributed in the hope that it will be useful,
23
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
24
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
25
 * GNU General Public License for more details.
26
 *
27
 * You should have received a copy of the GNU General Public License
28
 * along with this program; if not, write to the Free Software
29
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
30
 *
31
 * For more information, contact:
32
 *
33
 *  Generalitat Valenciana
34
 *   Conselleria d'Infraestructures i Transport
35
 *   Av. Blasco Ib??ez, 50
36
 *   46010 VALENCIA
37
 *   SPAIN
38
 *
39
 *      +34 963862235
40
 *   gvsig@gva.es
41
 *      www.gvsig.gva.es
42
 *
43
 *    or
44
 *
45
 *   IVER T.I. S.A
46
 *   Salamanca 50
47
 *   46005 Valencia
48
 *   Spain
49
 *
50
 *   +34 963163400
51
 *   dac@iver.es
52
 */
53
/* CVS MESSAGES:
54
 *
55
 * $Id: LookAtBinding.java 357 2008-01-09 17:50:08Z jpiera $
56
 * $Log$
57
 * Revision 1.2  2007/06/07 14:53:59  jorpiell
58
 * Add the schema support
59
 *
60
 * Revision 1.1  2007/05/11 07:06:29  jorpiell
61
 * Refactoring of some package names
62
 *
63
 * Revision 1.4  2007/05/08 08:22:37  jorpiell
64
 * Add comments to create javadocs
65
 *
66
 * Revision 1.3  2007/04/14 16:08:07  jorpiell
67
 * Kml writing support added
68
 *
69
 * Revision 1.2  2007/04/13 13:16:21  jorpiell
70
 * Add KML reading support
71
 *
72
 * Revision 1.1  2007/03/07 08:19:10  jorpiell
73
 * Pasadas las clases de KML de libGPE-GML a libGPE-KML
74
 *
75
 * Revision 1.1  2007/02/28 11:48:31  csanchez
76
 * *** empty log message ***
77
 *
78
 * Revision 1.1  2007/02/20 10:53:20  jorpiell
79
 * A?adidos los proyectos de kml y gml antiguos
80
 *
81
 * Revision 1.1  2007/02/12 13:49:18  jorpiell
82
 * A?adido el driver de KML
83
 *
84
 *
85
 */
86
/**
87
 * This class parses a LookAt tag. Example:
88
 * <p>
89
 * <pre>
90
 * <code>
91
 * &lt;LookAt&gt;
92
 * &lt;longitude&gt;-2.935547902482675&lt;/longitude&gt;
93
 * &lt;latitude&gt;43.41884927185296&lt;/latitude&gt;
94
 * &lt;range&gt;406.2340631356369&lt;/range&gt;
95
 * &lt;tilt&gt;5.122096682951607e-010&lt;/tilt&gt;
96
 * &lt;heading&gt;-0.005135845406706679&lt;/heading&gt;
97
 * &lt;/LookAt&gt;
98
 * </code>
99
 * </pre>
100
 * </p>
101
 * @author Jorge Piera LLodr? (jorge.piera@iver.es)
102
 * @see http://code.google.com/apis/kml/documentation/kml_tags_21.html#lookat
103
 */
104
public class LookAtBinding{
105

    
106
        /**
107
         * It parses the LookAt tag
108
         * @param parser
109
         * The XML parser
110
         * @param handler
111
         * The GPE parser that contains the content handler and
112
         * the error handler
113
         * @throws XmlStreamException 
114
         * @throws IOException 
115
         */
116
        public void parse(IXmlStreamReader parser,GPEDeafultKmlParser handler) throws XmlStreamException, IOException {
117
                boolean endFeature = false;
118
                int currentTag;                
119
                double longitude;
120
                double latitude;
121
                double altitude;
122
                double range;
123
                float tilt;
124
                float heading;
125

    
126

    
127
                QName tag = parser.getName();
128
                currentTag = parser.getEventType();
129

    
130
                while (!endFeature){
131
                        switch(currentTag){
132
                        case IXmlStreamReader.START_ELEMENT:
133
                                if (tag.getLocalPart().compareTo(Kml2_1_Tags.LONGITUDE) == 0){
134
                                        parser.next();
135
                                        longitude = new Double(parser.getText()).doubleValue();
136
                                }else if (tag.getLocalPart().compareTo(Kml2_1_Tags.LATITUDE) == 0){
137
                                        parser.next();
138
                                        latitude = new Double(parser.getText()).doubleValue();                                                
139
                                }else if (tag.getLocalPart().compareTo(Kml2_1_Tags.ALTITUDE) == 0){
140
                                        parser.next();
141
                                        altitude = new Double(parser.getText()).doubleValue();
142
                                }else if (tag.getLocalPart().compareTo(Kml2_1_Tags.RANGE) == 0){
143
                                        parser.next();
144
                                        altitude = new Double(parser.getText()).doubleValue();
145
                                }else if (tag.getLocalPart().compareTo(Kml2_1_Tags.TILT) == 0){
146
                                        parser.next();
147
                                        tilt = new Float(parser.getText()).floatValue();
148
                                }else if (tag.getLocalPart().compareTo(Kml2_1_Tags.HEADING) == 0){
149
                                        parser.next();
150
                                        longitude = new Float(parser.getText()).floatValue();
151
                                }
152
                                break;
153
                        case IXmlStreamReader.END_ELEMENT:
154
                                if (CompareUtils.compareWithNamespace(tag,Kml2_1_Tags.LOOKAT)){                                                
155
                                        endFeature = true;
156
                                }
157
                                break;
158
                        case IXmlStreamReader.CHARACTERS:                                        
159

    
160
                                break;
161
                        }
162
                        if (!endFeature){                                        
163
                                currentTag = parser.next();
164
                                tag = parser.getName();
165
                        }
166
                }                        
167

    
168
        }
169
}