root / org.gvsig.gpe / library / trunk / org.gvsig.gpe / org.gvsig.gpe.exportto / org.gvsig.gpe.exportto.kml / src / main / java / org / gvsig / gpe / exportto / kml / style / KmlBalloonStyle.java @ 386
History | View | Annotate | Download (2.22 KB)
1 |
package org.gvsig.gpe.exportto.kml.style; |
---|---|
2 |
|
3 |
import java.io.IOException; |
4 |
|
5 |
import org.gvsig.gpe.prov.kml.utils.Kml2_1_Tags; |
6 |
import org.gvsig.xmlpull.lib.api.stream.IXmlStreamWriter; |
7 |
|
8 |
|
9 |
/**
|
10 |
* Balloon style to show when user clicks on marker.
|
11 |
* Currently not used because CDDATA is not written properly
|
12 |
* (writer escapes it)
|
13 |
*
|
14 |
* @author jldominguez
|
15 |
*
|
16 |
*/
|
17 |
public class KmlBalloonStyle extends KmlStyle { |
18 |
|
19 |
private String[] fields = new String[0]; |
20 |
|
21 |
public KmlBalloonStyle(String[] flds, String id) { |
22 |
setId(id); |
23 |
if (flds != null) { |
24 |
fields = flds; |
25 |
} |
26 |
} |
27 |
|
28 |
public void writeXml(IXmlStreamWriter writer) throws IOException { |
29 |
|
30 |
writer.writeStartElement(Kml2_1_Tags.BALLOON_STYLE); |
31 |
writer.writeStartElement(Kml2_1_Tags.TEXT); |
32 |
|
33 |
// ====================================
|
34 |
String cddata = "<![CDATA["; |
35 |
cddata = cddata + htmlTable(); |
36 |
cddata = cddata + "]]>";
|
37 |
// ====================================
|
38 |
writer.writeValue(cddata); |
39 |
writer.writeEndElement(); |
40 |
writer.writeEndElement(); |
41 |
|
42 |
/*
|
43 |
<Style id="golf-balloon-style">
|
44 |
<BalloonStyle>
|
45 |
<text>
|
46 |
<![CDATA[
|
47 |
<table>
|
48 |
<tr><td>This is $[name]</td><td> : </td><td>This is $[name]</td></tr>
|
49 |
<tr><td>This is hole $[holeNumber]</td><td> : </td><td>This is $[name]</td></tr>
|
50 |
<tr><td>The par for this hole is $[holePar]</td><td> : </td><td>This is $[name]</td></tr>
|
51 |
<tr><td>The yardage is $[holeYardage]</td><td> : </td><td><b>This is $[name]</b></td></tr>
|
52 |
</table>
|
53 |
]]>
|
54 |
</text>
|
55 |
</BalloonStyle>
|
56 |
</Style>
|
57 |
*/
|
58 |
|
59 |
|
60 |
|
61 |
} |
62 |
|
63 |
private String htmlTable() { |
64 |
|
65 |
String resp = "<table>\n"; |
66 |
String aux = null; |
67 |
String auxrep = null; |
68 |
for (int i=0; i<fields.length; i++) { |
69 |
aux = fields[i]; |
70 |
auxrep = aux.replace(' ', '_'); |
71 |
auxrep = "$[" + auxrep + "]"; |
72 |
resp = resp + "<tr><td>" + aux + "</td><td> : </td><td><b>" + auxrep + "</b></td></tr>\n"; |
73 |
} |
74 |
resp = resp + "</table>\n";
|
75 |
return resp;
|
76 |
} |
77 |
|
78 |
} |