# HG changeset patch # User Andre Heinecke # Date 1348156709 -7200 # Node ID b6c0fbae16dc2cc3f3d4be3304edc3429c170352 # Parent 9289b7c1b4ce0da18c4dfece9a3009104d370498 Expand Graphics Layer Support diff -r 9289b7c1b4ce -r b6c0fbae16dc ChangeLog --- a/ChangeLog Thu Sep 20 13:01:33 2012 +0200 +++ b/ChangeLog Thu Sep 20 17:58:29 2012 +0200 @@ -1,3 +1,17 @@ +2012-09-20 Andre Heinecke + + Expand Graphics Layer Support + + * src/java/de/intevation/mxd/reader/CompositeGraphicsLayerReader.java: + Reduce debug output verbosity, add support for GraphicsSubLayer, add + classId for elements + + * src/java/de/intevation/mxd/reader/GraphicsSubLayerReader.java: + New. Class to read Graphics sublayers and their elements + + * src/java/de/intevation/mxd/writer/MapScriptWriter.java: + Write classId for Elements as feature attribute. + 2012-09-20 Andre Heinecke Implement Label Styles and Labels with background diff -r 9289b7c1b4ce -r b6c0fbae16dc src/java/de/intevation/mxd/reader/CompositeGraphicsLayerReader.java --- a/src/java/de/intevation/mxd/reader/CompositeGraphicsLayerReader.java Thu Sep 20 13:01:33 2012 +0200 +++ b/src/java/de/intevation/mxd/reader/CompositeGraphicsLayerReader.java Thu Sep 20 17:58:29 2012 +0200 @@ -23,7 +23,10 @@ import org.apache.log4j.Logger; import com.esri.arcgis.carto.IGraphicsLayer; +import com.esri.arcgis.carto.ILayer; import com.esri.arcgis.carto.CompositeGraphicsLayer; +import com.esri.arcgis.carto.GraphicsSubLayer; + import com.esri.arcgis.carto.AnnotateLayerPropertiesCollection; import com.esri.arcgis.carto.IAnnotateLayerProperties; import com.esri.arcgis.carto.LabelEngineLayerProperties; @@ -194,9 +197,8 @@ IPoint poi = te.getGeometry().getEnvelope().getLowerLeft(); xmlTextElement.setAttribute("X", String.valueOf(poi.getX())); xmlTextElement.setAttribute("Y", String.valueOf(poi.getY())); + xmlTextElement.setAttribute("classId", String.valueOf(count)); - logger.debug("Text: " + te.getText()); - logger.debug(" X,Y: " + poi.getX() + ", " + poi.getY()); try { ITextSymbol sym = te.getSymbol(); if(sym instanceof TextSymbol) { @@ -219,8 +221,8 @@ layer.getName()); } count++; + actElement = layer.next(); } - logger.debug("Read " + count + " Elements"); } catch(Exception e) { logger.warn("Could not read layer elements."); @@ -263,8 +265,20 @@ } // Static values for this layer - layerElement.setAttribute("type", "point"); + layerElement.setAttribute("type", "annotation"); + // Read Sublayers + for (int i = 0; i < layer.getCount(); i++) { + ILayer pLyr = layer.getLayer(i); + GraphicsSubLayer subbie = new GraphicsSubLayer((Object)pLyr); + if (subbie != null) { + GraphicsSubLayerReader lr = new GraphicsSubLayerReader(subbie); + lr.setUtil(util); + lr.read(); + } else { + logger.warn("Could not convert sublayer to GraphicsSubLayer"); + } + } return layerElement; } } diff -r 9289b7c1b4ce -r b6c0fbae16dc src/java/de/intevation/mxd/reader/GraphicsSubLayerReader.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/java/de/intevation/mxd/reader/GraphicsSubLayerReader.java Thu Sep 20 17:58:29 2012 +0200 @@ -0,0 +1,212 @@ +/* + * Copyright (c) 2012 by Intevation GmbH, Germany + * + * This file is part of MXD2map. + * + * This program is free software under the LGPL (>=v2.1) + * Read the file LICENCE.txt coming with the software for details + * or visit http://www.gnu.org/licenses/ if it does not exist. + * + * MXD2map has been developed on behalf of the + * Bundesamt fuer Seeschifffahrt und Hydrographie (BSH) in Hamburg + * by Intevation GmbH. + * + * Authors: + * Raimund Renkert + * Bjoern Schilberg + * Stephan Holl + * Andre Heinecke + */ + +package de.intevation.mxd.reader; + +import org.apache.log4j.Logger; + +import com.esri.arcgis.carto.IGraphicsLayer; +import com.esri.arcgis.carto.ILayer; +import com.esri.arcgis.carto.GraphicsSubLayer; +import com.esri.arcgis.globecore.GlobeGraphicsLayer; +import com.esri.arcgis.analyst3d.GraphicsLayer3D; +import com.esri.arcgis.carto.GraphicsSubLayer; +import com.esri.arcgis.carto.FDOGraphicsLayer; + +import com.esri.arcgis.carto.AnnotateLayerPropertiesCollection; +import com.esri.arcgis.carto.IAnnotateLayerProperties; +import com.esri.arcgis.carto.LabelEngineLayerProperties; +import com.esri.arcgis.carto.IElement; +import com.esri.arcgis.carto.TextElement; +import com.esri.arcgis.system.IName; +import com.esri.arcgis.system.IPropertySet; +import com.esri.arcgis.geometry.Envelope; +import com.esri.arcgis.geometry.ISpatialReference; +import com.esri.arcgis.geometry.ProjectedCoordinateSystem; +import com.esri.arcgis.geometry.GeographicCoordinateSystem; +import com.esri.arcgis.geometry.UnknownCoordinateSystem; +import com.esri.arcgis.geometry.Projection; +import com.esri.arcgis.geometry.IPoint; + +import com.esri.arcgis.display.ITextSymbol; +import com.esri.arcgis.display.TextSymbol; + +import org.w3c.dom.Element; + +import de.intevation.mxd.utils.MapToXMLUtils; +import java.io.IOException; +import com.esri.arcgis.interop.AutomationException; +/** + * Reads Layer information. + * + * @author Andre Heinecke + */ +public class GraphicsSubLayerReader +implements ILayerReader { + + /** + * The logger. + */ + private static final Logger logger = + Logger.getLogger(GraphicsSubLayerReader.class); + + /** + * Privte member. + */ + private GraphicsSubLayer layer; + private MapToXMLUtils util; + + /** + * Constructor with layer. + * + * @param layer The ArcGIS layer object. + */ + public GraphicsSubLayerReader(GraphicsSubLayer layer) { + this.layer = layer; + } + + /** + * Setter for XML document helper. + * + * @param util The helper for storing map information. + */ + public void setUtil(MapToXMLUtils util) { + this.util = util; + } + + /** + * Reads the Layer content. + * + * @return The layer XML element. + */ + public Element read() + throws IOException{ + logger.debug("read()"); + Element layerElement = null; + try { + layerElement = util.addLayer(); + } + catch(Exception e) { + logger.error("Failed to create DOM-Element for Layer."); + return null; + } + + // Name + try { + layerElement.setAttribute("name", layer.getName()); + + } + catch(Exception e) { + logger.warn( + "Could not read layer name." + + " Stopped reading layer."); + throw new IOException("Error reading layer name."); + } + + // Scale + try { + layerElement.setAttribute("min_scale", + String.valueOf(layer.getMinimumScale())); + } + catch(IOException ioe) { + logger.warn("Could not read minimum scale."); + } + + try { + layerElement.setAttribute("max_scale", + String.valueOf(layer.getMaximumScale())); + } + catch(Exception e) { + logger.warn( + "Could not read maximum scale."); + } + + // Status + try { + if(layer.isVisible()) { + layerElement.setAttribute("status", "on"); + } + else { + layerElement.setAttribute("status", "off"); + } + } + catch(Exception e) { + logger.warn( + "Could not read layer status." + + " Setting layer status to \"on\"."); + layerElement.setAttribute("status", "on"); + } + + // Read the elements + try { + int count = 0; + IElement actElement = null; + IElement prevElement = null; + layer.reset(); // Reset the element container + actElement = layer.next(); + while (actElement != prevElement) { + prevElement = actElement; + if (actElement instanceof TextElement) { + TextElement te = (TextElement)actElement; + Element xmlTextElement = util.addFeature(layerElement); + xmlTextElement.setAttribute("text", te.getText()); + + IPoint poi = te.getGeometry().getEnvelope().getLowerLeft(); + xmlTextElement.setAttribute("X", String.valueOf(poi.getX())); + xmlTextElement.setAttribute("Y", String.valueOf(poi.getY())); + xmlTextElement.setAttribute("classId", String.valueOf(count)); + + try { + ITextSymbol sym = te.getSymbol(); + if(sym instanceof TextSymbol) { + TextSymbolReader tsr = new TextSymbolReader(sym); + tsr.setParent(xmlTextElement); + tsr.setUtil(util); + tsr.read(); + } else { + logger.warn("Unknwon Symbol of class: " + + sym.getClass().toString()); + } + } + catch(Exception e) { + logger.warn("Could not read element text symbol."); + } + } else { + logger.warn("Unhandled Element of class: " + + actElement.getClass().toString() + + " in conversion of layer: " + + layer.getName()); + } + count++; + actElement = layer.next(); + } + } + catch(Exception e) { + logger.warn("Could not read layer elements."); + logger.debug(e); + } + + // Static values for this layer + layerElement.setAttribute("type", "annotation"); + + return layerElement; + } +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : diff -r 9289b7c1b4ce -r b6c0fbae16dc src/java/de/intevation/mxd/writer/LabelStyleWriter.java --- a/src/java/de/intevation/mxd/writer/LabelStyleWriter.java Thu Sep 20 13:01:33 2012 +0200 +++ b/src/java/de/intevation/mxd/writer/LabelStyleWriter.java Thu Sep 20 17:58:29 2012 +0200 @@ -72,7 +72,6 @@ public boolean write(Element symbolElement) { logger.debug("write(Element)"); - style.setGeomTransform("labelpoly"); cl.getLabel().insertStyle(style, -1); symbolSetObj symbolSet = map.getSymbolset(); @@ -102,15 +101,7 @@ col.getBlue(), -4); style.setColor(color); - } else if(symbolElement.hasAttribute("color")) { - String c = symbolElement.getAttribute("color"); - Color col = Color.decode(c); - colorObj color = new colorObj( - col.getRed(), - col.getGreen(), - col.getBlue(), - -4); - style.setColor(color); + style.setGeomTransform("labelpoly"); } if (symbolElement.hasAttribute ("size")) { try { diff -r 9289b7c1b4ce -r b6c0fbae16dc src/java/de/intevation/mxd/writer/MapScriptWriter.java --- a/src/java/de/intevation/mxd/writer/MapScriptWriter.java Thu Sep 20 13:01:33 2012 +0200 +++ b/src/java/de/intevation/mxd/writer/MapScriptWriter.java Thu Sep 20 17:58:29 2012 +0200 @@ -551,12 +551,14 @@ layer.setOffsite(new colorObj(255,255,255,-4)); } - // Set scaling properties for layer + // Set scaling properties for layer and add Processing if(type == "annotation") { if (mapNode.hasAttribute("referencescale")) { layer.setSymbolscaledenom(Double.parseDouble( mapNode.getAttribute("referencescale"))); } + layer.addProcessing("ITEMS=classId"); + layer.setClassitem("classId"); } // Create labelitem @@ -616,13 +618,18 @@ shape.add(line); shape.setText(feature.getAttribute("text")); - // Write the Style / Symbol once - if ( i == 0 ) { - classObj co = new classObj(layer); - writeLabel(co, feature, layerElement.getAttribute("type")); - LabelStyleWriter swriter = new LabelStyleWriter (this.map, co); - swriter.write((Element)feature.getFirstChild()); - } + shape.initValues(1); + shape.setValue(0, feature.getAttribute("classId")); + + // Write the Style / Symbol for each element as a single class + // TODO build a hash of the style/symbol and check if classes can be + // grouped + + classObj co = new classObj(layer); + writeLabel(co, feature, layerElement.getAttribute("type")); + co.setExpression("\"" + feature.getAttribute("classId") + "\""); + LabelStyleWriter swriter = new LabelStyleWriter (this.map, co); + swriter.write((Element)feature.getFirstChild()); layer.addFeature(shape); } }