MATSIM
MatsimKmlStyleFactory.java
Go to the documentation of this file.
1 /* *********************************************************************** *
2  * project: org.matsim.*
3  * MatsimKmlStyleFactory.java
4  * *
5  * *********************************************************************** *
6  * *
7  * copyright : (C) 2007, 2008 by the members listed in the COPYING, *
8  * LICENSE and WARRANTY file. *
9  * email : info at matsim dot org *
10  * *
11  * *********************************************************************** *
12  * *
13  * This program is free software; you can redistribute it and/or modify *
14  * it under the terms of the GNU General Public License as published by *
15  * the Free Software Foundation; either version 2 of the License, or *
16  * (at your option) any later version. *
17  * See also COPYING, LICENSE and WARRANTY file *
18  * *
19  * *********************************************************************** */
20 
21 package org.matsim.vis.kml;
22 
23 import net.opengis.kml.v_2_2_0.DocumentType;
24 import net.opengis.kml.v_2_2_0.IconStyleType;
25 import net.opengis.kml.v_2_2_0.LineStyleType;
26 import net.opengis.kml.v_2_2_0.LinkType;
27 import net.opengis.kml.v_2_2_0.ObjectFactory;
28 import net.opengis.kml.v_2_2_0.StyleType;
30 
31 import java.io.IOException;
32 
37  public static final String DEFAULTLINKICON ="link.png";
38 
39  public static final String DEFAULTNODEICON ="node.png";
43  public static final String DEFAULTNODEICONRESOURCE = "icon18.png";
44 
45  private static final Double ICONSCALE = 0.5;
46 
47  public static final byte[] MATSIMRED = new byte[]{(byte) 255, (byte) 15, (byte) 15, (byte) 190};
48 // public static final Color MATSIMBLUE = new Color(190, 190, 80, 90);
49  private static final byte[] MATSIMGREY = new byte[]{(byte) 210, (byte) 70, (byte) 50, (byte) 50};
50  private static final byte[] MATSIMWHITE = new byte[]{(byte) 230, (byte) 230, (byte) 230, (byte) 230};
51 
52 
53  // these come from CountsSimComparisonKMLWriter:
54 // byte[] red = new byte[]{(byte) 0xFF, (byte) 0x0F, (byte) 0x0F, (byte) 0xBE};
55  public static final byte[] MATSIMGREEN = new byte[]{(byte) 0xFF, (byte) 0x14, (byte) 0xDC, (byte) 0x0A};
56  public static final byte[] MATSIMYELLOW = new byte[]{(byte) 0xFF, (byte) 0x14, (byte) 0xE6, (byte) 0xE6};
57 // byte[] grey = new byte[]{(byte) 0xFF, (byte) 0x42, (byte) 0x42, (byte) 0x42};
58 
62  private KMZWriter writer = null;
63 
64  private ObjectFactory kmlObjectFactory = new ObjectFactory();
65 
66  private DocumentType document;
67 
68  private StyleType defaultnetworknodestyle;
69 
70  private StyleType defaultnetworklinkstyle;
71 
72  public MatsimKmlStyleFactory(KMZWriter writer, DocumentType document) {
73  this.writer = writer;
74  this.document = document;
75  }
76 
77  @Override
78  public StyleType createDefaultNetworkNodeStyle() throws IOException {
79  if (this.defaultnetworknodestyle == null) {
80  this.defaultnetworknodestyle = kmlObjectFactory.createStyleType();
81  this.defaultnetworknodestyle.setId("defaultnetworknodestyle");
82 
83  LinkType iconLink = kmlObjectFactory.createLinkType();
84  iconLink.setHref(DEFAULTNODEICON);
85  this.writer.addNonKMLFile(MatsimResource.getAsInputStream(DEFAULTNODEICONRESOURCE), DEFAULTNODEICON);
86  IconStyleType iStyle = kmlObjectFactory.createIconStyleType();
87  iStyle.setIcon(iconLink);
88  iStyle.setColor(MatsimKmlStyleFactory.MATSIMRED);
89  iStyle.setScale(MatsimKmlStyleFactory.ICONSCALE);
90  this.defaultnetworknodestyle.setIconStyle(iStyle);
91  this.document.getAbstractStyleSelectorGroup().add(kmlObjectFactory.createStyle(this.defaultnetworknodestyle));
92  }
93  return this.defaultnetworknodestyle;
94  }
95 
96  @Override
97  public StyleType createDefaultNetworkLinkStyle() throws IOException {
98  if (this.defaultnetworklinkstyle == null) {
99  this.defaultnetworklinkstyle = kmlObjectFactory.createStyleType();
100  this.defaultnetworklinkstyle.setId("defaultnetworklinkstyle");
101 
102  LinkType iconLink = kmlObjectFactory.createLinkType();
103  iconLink.setHref(DEFAULTLINKICON);
104  this.writer.addNonKMLFile(MatsimResource.getAsInputStream(DEFAULTNODEICONRESOURCE), DEFAULTLINKICON);
105  IconStyleType iStyle = kmlObjectFactory.createIconStyleType();
106  iStyle.setIcon(iconLink);
107  iStyle.setColor(MatsimKmlStyleFactory.MATSIMWHITE);
108  iStyle.setScale(MatsimKmlStyleFactory.ICONSCALE);
109  this.defaultnetworklinkstyle.setIconStyle(iStyle);
110  LineStyleType lineStyle = kmlObjectFactory.createLineStyleType();
111  lineStyle.setColor(MatsimKmlStyleFactory.MATSIMGREY);
112  lineStyle.setWidth(12.0);
113  this.defaultnetworklinkstyle.setLineStyle(lineStyle);
114  this.document.getAbstractStyleSelectorGroup().add(kmlObjectFactory.createStyle(this.defaultnetworklinkstyle));
115  }
116  return this.defaultnetworklinkstyle;
117  }
118 
119 }
static final InputStream getAsInputStream(final String filename)
MatsimKmlStyleFactory(KMZWriter writer, DocumentType document)
void addNonKMLFile(final String filename, final String inZipFilename)
Definition: KMZWriter.java:168