aheinecke@321: /* aheinecke@321: * Copyright (c) 2012 by Intevation GmbH, Germany aheinecke@321: * aheinecke@321: * This file is part of MXD2map. aheinecke@321: * aheinecke@321: * This program is free software under the LGPL (>=v2.1) aheinecke@321: * Read the file LICENCE.txt coming with the software for details aheinecke@321: * or visit http://www.gnu.org/licenses/ if it does not exist. aheinecke@321: * aheinecke@321: * MXD2map has been developed on behalf of the aheinecke@321: * Bundesamt fuer Seeschifffahrt und Hydrographie (BSH) in Hamburg aheinecke@321: * by Intevation GmbH. aheinecke@321: * aheinecke@321: * Authors: aheinecke@321: * Raimund Renkert aheinecke@321: * Bjoern Schilberg aheinecke@321: * Stephan Holl aheinecke@321: * Andre Heinecke aheinecke@321: */ aheinecke@321: aheinecke@321: package de.intevation.mxd.reader; aheinecke@321: aheinecke@321: import org.apache.log4j.Logger; aheinecke@321: aheinecke@321: import com.esri.arcgis.carto.IGraphicsLayer; aheinecke@321: import com.esri.arcgis.carto.ILayer; aheinecke@321: import com.esri.arcgis.carto.GraphicsSubLayer; aheinecke@321: import com.esri.arcgis.globecore.GlobeGraphicsLayer; aheinecke@321: import com.esri.arcgis.analyst3d.GraphicsLayer3D; aheinecke@321: import com.esri.arcgis.carto.GraphicsSubLayer; aheinecke@321: import com.esri.arcgis.carto.FDOGraphicsLayer; aheinecke@321: aheinecke@321: import com.esri.arcgis.carto.AnnotateLayerPropertiesCollection; aheinecke@321: import com.esri.arcgis.carto.IAnnotateLayerProperties; aheinecke@321: import com.esri.arcgis.carto.LabelEngineLayerProperties; aheinecke@321: import com.esri.arcgis.carto.IElement; aheinecke@321: import com.esri.arcgis.carto.TextElement; aheinecke@321: import com.esri.arcgis.system.IName; aheinecke@321: import com.esri.arcgis.system.IPropertySet; aheinecke@321: import com.esri.arcgis.geometry.Envelope; aheinecke@321: import com.esri.arcgis.geometry.ISpatialReference; aheinecke@321: import com.esri.arcgis.geometry.ProjectedCoordinateSystem; aheinecke@321: import com.esri.arcgis.geometry.GeographicCoordinateSystem; aheinecke@321: import com.esri.arcgis.geometry.UnknownCoordinateSystem; aheinecke@321: import com.esri.arcgis.geometry.Projection; aheinecke@321: import com.esri.arcgis.geometry.IPoint; aheinecke@321: aheinecke@321: import com.esri.arcgis.display.ITextSymbol; aheinecke@321: import com.esri.arcgis.display.TextSymbol; aheinecke@321: aheinecke@321: import org.w3c.dom.Element; aheinecke@321: aheinecke@321: import de.intevation.mxd.utils.MapToXMLUtils; aheinecke@321: import java.io.IOException; aheinecke@321: import com.esri.arcgis.interop.AutomationException; aheinecke@321: /** aheinecke@321: * Reads Layer information. aheinecke@321: * aheinecke@321: * @author Andre Heinecke aheinecke@321: */ aheinecke@321: public class GraphicsSubLayerReader aheinecke@321: implements ILayerReader { aheinecke@321: aheinecke@321: /** aheinecke@321: * The logger. aheinecke@321: */ aheinecke@321: private static final Logger logger = aheinecke@321: Logger.getLogger(GraphicsSubLayerReader.class); aheinecke@321: aheinecke@321: /** aheinecke@321: * Privte member. aheinecke@321: */ aheinecke@321: private GraphicsSubLayer layer; aheinecke@321: private MapToXMLUtils util; aheinecke@321: aheinecke@321: /** aheinecke@321: * Constructor with layer. aheinecke@321: * aheinecke@321: * @param layer The ArcGIS layer object. aheinecke@321: */ aheinecke@321: public GraphicsSubLayerReader(GraphicsSubLayer layer) { aheinecke@321: this.layer = layer; aheinecke@321: } aheinecke@321: aheinecke@321: /** aheinecke@321: * Setter for XML document helper. aheinecke@321: * aheinecke@321: * @param util The helper for storing map information. aheinecke@321: */ aheinecke@321: public void setUtil(MapToXMLUtils util) { aheinecke@321: this.util = util; aheinecke@321: } aheinecke@321: aheinecke@321: /** aheinecke@321: * Reads the Layer content. aheinecke@321: * aheinecke@321: * @return The layer XML element. aheinecke@321: */ aheinecke@321: public Element read() aheinecke@321: throws IOException{ aheinecke@321: logger.debug("read()"); aheinecke@321: Element layerElement = null; aheinecke@321: try { aheinecke@321: layerElement = util.addLayer(); aheinecke@321: } aheinecke@321: catch(Exception e) { aheinecke@321: logger.error("Failed to create DOM-Element for Layer."); aheinecke@321: return null; aheinecke@321: } aheinecke@321: aheinecke@321: // Name aheinecke@321: try { aheinecke@321: layerElement.setAttribute("name", layer.getName()); aheinecke@321: aheinecke@321: } aheinecke@321: catch(Exception e) { aheinecke@321: logger.warn( aheinecke@321: "Could not read layer name." + aheinecke@321: " Stopped reading layer."); aheinecke@321: throw new IOException("Error reading layer name."); aheinecke@321: } aheinecke@321: aheinecke@321: // Scale aheinecke@321: try { aheinecke@321: layerElement.setAttribute("min_scale", aheinecke@321: String.valueOf(layer.getMinimumScale())); aheinecke@321: } aheinecke@321: catch(IOException ioe) { aheinecke@321: logger.warn("Could not read minimum scale."); aheinecke@321: } aheinecke@321: aheinecke@321: try { aheinecke@321: layerElement.setAttribute("max_scale", aheinecke@321: String.valueOf(layer.getMaximumScale())); aheinecke@321: } aheinecke@321: catch(Exception e) { aheinecke@321: logger.warn( aheinecke@321: "Could not read maximum scale."); aheinecke@321: } aheinecke@321: aheinecke@321: // Status aheinecke@321: try { aheinecke@321: if(layer.isVisible()) { aheinecke@321: layerElement.setAttribute("status", "on"); aheinecke@321: } aheinecke@321: else { aheinecke@321: layerElement.setAttribute("status", "off"); aheinecke@321: } aheinecke@321: } aheinecke@321: catch(Exception e) { aheinecke@321: logger.warn( aheinecke@321: "Could not read layer status." + aheinecke@321: " Setting layer status to \"on\"."); aheinecke@321: layerElement.setAttribute("status", "on"); aheinecke@321: } aheinecke@321: aheinecke@321: // Read the elements aheinecke@321: try { aheinecke@321: int count = 0; aheinecke@321: IElement actElement = null; aheinecke@321: IElement prevElement = null; aheinecke@321: layer.reset(); // Reset the element container aheinecke@321: actElement = layer.next(); aheinecke@321: while (actElement != prevElement) { aheinecke@321: prevElement = actElement; aheinecke@321: if (actElement instanceof TextElement) { aheinecke@321: TextElement te = (TextElement)actElement; aheinecke@321: Element xmlTextElement = util.addFeature(layerElement); aheinecke@321: xmlTextElement.setAttribute("text", te.getText()); aheinecke@321: aheinecke@321: IPoint poi = te.getGeometry().getEnvelope().getLowerLeft(); aheinecke@321: xmlTextElement.setAttribute("X", String.valueOf(poi.getX())); aheinecke@321: xmlTextElement.setAttribute("Y", String.valueOf(poi.getY())); aheinecke@321: xmlTextElement.setAttribute("classId", String.valueOf(count)); aheinecke@321: aheinecke@321: try { aheinecke@321: ITextSymbol sym = te.getSymbol(); aheinecke@321: if(sym instanceof TextSymbol) { aheinecke@321: TextSymbolReader tsr = new TextSymbolReader(sym); aheinecke@321: tsr.setParent(xmlTextElement); aheinecke@321: tsr.setUtil(util); aheinecke@321: tsr.read(); aheinecke@321: } else { aheinecke@321: logger.warn("Unknwon Symbol of class: " + aheinecke@321: sym.getClass().toString()); aheinecke@321: } aheinecke@321: } aheinecke@321: catch(Exception e) { aheinecke@321: logger.warn("Could not read element text symbol."); aheinecke@321: } aheinecke@321: } else { aheinecke@321: logger.warn("Unhandled Element of class: " + aheinecke@321: actElement.getClass().toString() + aheinecke@321: " in conversion of layer: " + aheinecke@321: layer.getName()); aheinecke@321: } aheinecke@321: count++; aheinecke@321: actElement = layer.next(); aheinecke@321: } aheinecke@321: } aheinecke@321: catch(Exception e) { aheinecke@321: logger.warn("Could not read layer elements."); aheinecke@321: logger.debug(e); aheinecke@321: } aheinecke@321: aheinecke@321: // Static values for this layer aheinecke@321: layerElement.setAttribute("type", "annotation"); aheinecke@321: aheinecke@321: return layerElement; aheinecke@321: } aheinecke@321: } aheinecke@321: // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :