001/* *********************************************************************** * 002 * project: org.matsim.* 003 * MatsimKmlStyleFactory.java 004 * * 005 * *********************************************************************** * 006 * * 007 * copyright : (C) 2007, 2008 by the members listed in the COPYING, * 008 * LICENSE and WARRANTY file. * 009 * email : info at matsim dot org * 010 * * 011 * *********************************************************************** * 012 * * 013 * This program is free software; you can redistribute it and/or modify * 014 * it under the terms of the GNU General Public License as published by * 015 * the Free Software Foundation; either version 2 of the License, or * 016 * (at your option) any later version. * 017 * See also COPYING, LICENSE and WARRANTY file * 018 * * 019 * *********************************************************************** */ 020 021package org.matsim.vis.kml; 022 023import net.opengis.kml.v_2_2_0.DocumentType; 024import net.opengis.kml.v_2_2_0.IconStyleType; 025import net.opengis.kml.v_2_2_0.LineStyleType; 026import net.opengis.kml.v_2_2_0.LinkType; 027import net.opengis.kml.v_2_2_0.ObjectFactory; 028import net.opengis.kml.v_2_2_0.StyleType; 029import org.matsim.core.gbl.MatsimResource; 030 031import java.io.IOException; 032 033/** 034 * @author dgrether 035 */ 036public class MatsimKmlStyleFactory implements NetworkKmlStyleFactory { 037 public static final String DEFAULTLINKICON ="link.png"; 038 039 public static final String DEFAULTNODEICON ="node.png"; 040 /** 041 * the resource to be used as icon 042 */ 043 public static final String DEFAULTNODEICONRESOURCE = "icon18.png"; 044 045 private static final Double ICONSCALE = 0.5; 046 047 public static final byte[] MATSIMRED = new byte[]{(byte) 255, (byte) 15, (byte) 15, (byte) 190}; 048// public static final Color MATSIMBLUE = new Color(190, 190, 80, 90); 049 private static final byte[] MATSIMGREY = new byte[]{(byte) 210, (byte) 70, (byte) 50, (byte) 50}; 050 private static final byte[] MATSIMWHITE = new byte[]{(byte) 230, (byte) 230, (byte) 230, (byte) 230}; 051 052 053 // these come from CountsSimComparisonKMLWriter: 054// byte[] red = new byte[]{(byte) 0xFF, (byte) 0x0F, (byte) 0x0F, (byte) 0xBE}; 055 public static final byte[] MATSIMGREEN = new byte[]{(byte) 0xFF, (byte) 0x14, (byte) 0xDC, (byte) 0x0A}; 056 public static final byte[] MATSIMYELLOW = new byte[]{(byte) 0xFF, (byte) 0x14, (byte) 0xE6, (byte) 0xE6}; 057// byte[] grey = new byte[]{(byte) 0xFF, (byte) 0x42, (byte) 0x42, (byte) 0x42}; 058 059 /** 060 * the kmz writer 061 */ 062 private KMZWriter writer = null; 063 064 private ObjectFactory kmlObjectFactory = new ObjectFactory(); 065 066 private DocumentType document; 067 068 private StyleType defaultnetworknodestyle; 069 070 private StyleType defaultnetworklinkstyle; 071 072 public MatsimKmlStyleFactory(KMZWriter writer, DocumentType document) { 073 this.writer = writer; 074 this.document = document; 075 } 076 077 @Override 078 public StyleType createDefaultNetworkNodeStyle() throws IOException { 079 if (this.defaultnetworknodestyle == null) { 080 this.defaultnetworknodestyle = kmlObjectFactory.createStyleType(); 081 this.defaultnetworknodestyle.setId("defaultnetworknodestyle"); 082 083 LinkType iconLink = kmlObjectFactory.createLinkType(); 084 iconLink.setHref(DEFAULTNODEICON); 085 this.writer.addNonKMLFile(MatsimResource.getAsInputStream(DEFAULTNODEICONRESOURCE), DEFAULTNODEICON); 086 IconStyleType iStyle = kmlObjectFactory.createIconStyleType(); 087 iStyle.setIcon(iconLink); 088 iStyle.setColor(MatsimKmlStyleFactory.MATSIMRED); 089 iStyle.setScale(MatsimKmlStyleFactory.ICONSCALE); 090 this.defaultnetworknodestyle.setIconStyle(iStyle); 091 this.document.getAbstractStyleSelectorGroup().add(kmlObjectFactory.createStyle(this.defaultnetworknodestyle)); 092 } 093 return this.defaultnetworknodestyle; 094 } 095 096 @Override 097 public StyleType createDefaultNetworkLinkStyle() throws IOException { 098 if (this.defaultnetworklinkstyle == null) { 099 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}