Search in sources :

Example 96 with XMLElement

use of com.dexels.navajo.document.nanoimpl.XMLElement in project navajo by Dexels.

the class AbstractKMLMap method createPointKmlFile.

public File createPointKmlFile(Navajo n, String messagePath) throws XMLParseException, IOException {
    Message m = n.getMessage(messagePath);
    List<Message> ll = (m != null ? m.getAllMessages() : null);
    XMLElement kml = new CaseSensitiveXMLElement("kml");
    XMLElement document = new CaseSensitiveXMLElement("Document");
    kml.addChild(document);
    Message c = n.getMessage("Styles");
    if (c != null) {
        List<Message> colors = c.getAllMessages();
        for (Message message : colors) {
            XMLElement style = new CaseSensitiveXMLElement("Style");
            XMLElement iconStyle = new CaseSensitiveXMLElement("IconStyle");
            style.setAttribute("id", message.getProperty("StyleRef").getTypedValue());
            style.addChild(iconStyle);
            if (message.getProperty("IconColor") != null) {
                iconStyle.addTagKeyValue("color", "ff" + message.getProperty("IconColor").getTypedValue() + "");
            } else {
                iconStyle.addTagKeyValue("colorMode", "random");
            }
            XMLElement icon = new CaseSensitiveXMLElement("Icon");
            iconStyle.addChild(icon);
            String iconShape = "http://maps.google.com/mapfiles/kml/shapes/play.png";
            if (message.getProperty("IconURL") != null) {
                iconShape = message.getProperty("IconURL").getValue();
                // Make sure to replace &amp; with &
                iconShape = iconShape.replaceAll("&amp;", "&");
                logger.debug("Using url: {}", iconShape);
            } else if (message.getProperty("Icon") != null) {
                iconShape = "http://maps.google.com/mapfiles/kml/" + message.getProperty("Icon").getTypedValue();
            }
            icon.addTagKeyValue("href", iconShape);
            document.addChild(style);
        }
    }
    Message hasFolders = n.getMessage("Folders");
    if (hasFolders != null) {
        List<Message> folders = hasFolders.getAllMessages();
        for (Message folder : folders) {
            String name = folder.getProperty("Name").getValue();
            XMLElement folderElt = createFolder(name);
            m = folder.getMessage(messagePath);
            if (m != null) {
                ll = m.getAllMessages();
                for (Message message : ll) {
                    XMLElement placemark = createPointPlaceMark(message);
                    if (placemark != null) {
                        folderElt.addChild(placemark);
                    }
                }
            }
            if (folderElt != null) {
                document.addChild(folderElt);
            }
        }
    } else {
        if (ll != null) {
            for (Message message : ll) {
                XMLElement placemark = createPointPlaceMark(message);
                // XMLElement placemark = createCirclePlacemark(message);
                if (placemark != null) {
                    document.addChild(placemark);
                }
            }
        }
    }
    File res = File.createTempFile("pointData", ".kml");
    FileWriter fw = new FileWriter(res);
    kml.write(fw);
    fw.flush();
    fw.close();
    return res;
}
Also used : CaseSensitiveXMLElement(com.dexels.navajo.document.nanoimpl.CaseSensitiveXMLElement) Message(com.dexels.navajo.document.Message) FileWriter(java.io.FileWriter) CaseSensitiveXMLElement(com.dexels.navajo.document.nanoimpl.CaseSensitiveXMLElement) XMLElement(com.dexels.navajo.document.nanoimpl.XMLElement) File(java.io.File)

Example 97 with XMLElement

use of com.dexels.navajo.document.nanoimpl.XMLElement in project navajo by Dexels.

the class AbstractKMLMap method createPointPlaceMark.

private XMLElement createPointPlaceMark(Message message) {
    XMLElement placemark = new CaseSensitiveXMLElement("Placemark");
    placemark.setAttribute("id", message.getProperty("Id").getTypedValue());
    placemark.addTagKeyValue("name", message.getProperty("Name").getValue());
    XMLElement point = new CaseSensitiveXMLElement("Point");
    placemark.addChild(point);
    String lon = message.getProperty("Longitude").getValue();
    String lat = message.getProperty("Latitude").getValue();
    if (lon.equals("-1.0") || lat.equals("-1.0")) {
        return null;
    }
    point.addTagKeyValue("coordinates", lon + "," + lat);
    // Introspect other properties.
    StringBuffer descr = new StringBuffer();
    List<Property> properties = message.getAllProperties();
    for (Iterator<Property> iterator = properties.iterator(); iterator.hasNext(); ) {
        Property property = iterator.next();
        if (!(property.getName().equals("Longitude") || property.getName().equals("Latitude") || property.getName().equals("Id") || property.getName().equals("Name"))) {
            descr.append(property.getDescription() + ": " + property.getValue() + "<br/>");
        }
    }
    placemark.addTagKeyValue("description", descr.toString());
    logger.debug("Description: {}", descr);
    XMLElement region = new CaseSensitiveXMLElement("Region");
    if (useLOD) {
        placemark.addChild(region);
    }
    XMLElement latLonAltBox = new CaseSensitiveXMLElement("LatLonAltBox");
    region.addChild(latLonAltBox);
    latLonAltBox.addTagKeyValue("north", lat);
    latLonAltBox.addTagKeyValue("south", "" + (Double.parseDouble(lat) - 0.1));
    latLonAltBox.addTagKeyValue("east", lon);
    latLonAltBox.addTagKeyValue("west", "" + (Double.parseDouble(lon) - 0.1));
    XMLElement lod = new CaseSensitiveXMLElement("Lod");
    lod.addTagKeyValue("minLodPixels", "64");
    // lod.addTagKeyValue("maxLodPixels", "5024");
    lod.addTagKeyValue("minFadeExtent", "828");
    lod.addTagKeyValue("maxFadeExtent", "428");
    region.addChild(lod);
    if (message.getProperty("StyleRef") != null) {
        placemark.addTagKeyValue("styleUrl", "#" + message.getProperty("StyleRef").getTypedValue());
    }
    return placemark;
}
Also used : CaseSensitiveXMLElement(com.dexels.navajo.document.nanoimpl.CaseSensitiveXMLElement) CaseSensitiveXMLElement(com.dexels.navajo.document.nanoimpl.CaseSensitiveXMLElement) XMLElement(com.dexels.navajo.document.nanoimpl.XMLElement) Property(com.dexels.navajo.document.Property)

Example 98 with XMLElement

use of com.dexels.navajo.document.nanoimpl.XMLElement in project navajo by Dexels.

the class AbstractKMLMap method createFolder.

private XMLElement createFolder(String name) {
    XMLElement folder = new CaseSensitiveXMLElement("Folder");
    XMLElement nameElt = new CaseSensitiveXMLElement("name");
    nameElt.setContent(name);
    folder.addChild(nameElt);
    return folder;
}
Also used : CaseSensitiveXMLElement(com.dexels.navajo.document.nanoimpl.CaseSensitiveXMLElement) CaseSensitiveXMLElement(com.dexels.navajo.document.nanoimpl.CaseSensitiveXMLElement) XMLElement(com.dexels.navajo.document.nanoimpl.XMLElement)

Example 99 with XMLElement

use of com.dexels.navajo.document.nanoimpl.XMLElement in project navajo by Dexels.

the class AbstractKMLMap method mapData.

public XMLElement mapData(Message m) throws XMLParseException, IOException {
    Map<String, Message> messageMap = new HashMap<String, Message>();
    XMLElement xe = new CaseSensitiveXMLElement();
    xe.parseFromReader(new InputStreamReader(getClass().getClassLoader().getResourceAsStream(mapPath), "UTF-8"));
    if (m != null) {
        List<Message> msgElements = m.getAllMessages();
        for (Message message : msgElements) {
            Property key = message.getProperty("Key");
            String keyVal = "" + key.getTypedValue();
            messageMap.put(keyVal, message);
        }
    }
    // Create a map of all marker placemarks, for reference
    Map<String, XMLElement> markerMap = new HashMap<String, XMLElement>();
    List<XMLElement> markers = xe.getElementsByTagName("Placemark");
    for (XMLElement element : markers) {
        String id = element.getStringAttribute("id", "");
        if (id.startsWith("marker_")) {
            markerMap.put(id, element);
        }
    }
    List<XMLElement> l = xe.getElementsByTagName("Style");
    for (XMLElement element : l) {
        String stringAttribute = element.getStringAttribute("id");
        String id = stringAttribute.substring(8, stringAttribute.length() - 4);
        Message message = messageMap.get(id);
        renderStyle(element, message, markerMap);
    }
    return xe;
}
Also used : CaseSensitiveXMLElement(com.dexels.navajo.document.nanoimpl.CaseSensitiveXMLElement) Message(com.dexels.navajo.document.Message) InputStreamReader(java.io.InputStreamReader) HashMap(java.util.HashMap) CaseSensitiveXMLElement(com.dexels.navajo.document.nanoimpl.CaseSensitiveXMLElement) XMLElement(com.dexels.navajo.document.nanoimpl.XMLElement) Property(com.dexels.navajo.document.Property)

Example 100 with XMLElement

use of com.dexels.navajo.document.nanoimpl.XMLElement in project navajo by Dexels.

the class AbstractKMLMap method renderStyle.

private void renderStyle(XMLElement style, Message message, Map<String, XMLElement> markerMap) {
    XMLElement polyStyle = style.getElementByTagName("PolyStyle");
    if (polyStyle == null) {
        return;
    }
    String styleId = style.getStringAttribute("id");
    if (styleId == null) {
        logger.debug("Null styleid? Using style {}", polyStyle);
        return;
    }
    String markerId = null;
    if (styleId.startsWith("style")) {
        markerId = "marker_" + styleId.substring(5);
    }
    XMLElement markerPlacemark = markerMap.get(markerId);
    Object value = null;
    Property descriptionProperty;
    String descriptionString = null;
    // double dValue;
    if (message != null) {
        value = message.getProperty("Value").getTypedValue();
        descriptionProperty = message.getProperty("Description");
        descriptionString = (String) descriptionProperty.getTypedValue();
    // dValue = Double.parseDouble((String) value);
    } else {
        value = "0";
        // dValue = Double.parseDouble((String) value);
        descriptionString = "Geen data.";
    }
    XMLElement description = markerPlacemark.getElementByTagName("description");
    description.setContent(descriptionString);
    XMLElement lineStyle = style.getElementByTagName("LineStyle");
    lineStyle.addTagKeyValue("color", "55ffffff");
    lineStyle.addTagKeyValue("width", "1");
    double d = Double.parseDouble((String) value);
    String createColor = getSelectedColorizer().createGeoColorString(d, 0, 1);
    polyStyle.addTagKeyValue("color", createColor);
    polyStyle.addTagKeyValue("color", createColor);
}
Also used : CaseSensitiveXMLElement(com.dexels.navajo.document.nanoimpl.CaseSensitiveXMLElement) XMLElement(com.dexels.navajo.document.nanoimpl.XMLElement) Property(com.dexels.navajo.document.Property)

Aggregations

XMLElement (com.dexels.navajo.document.nanoimpl.XMLElement)120 CaseSensitiveXMLElement (com.dexels.navajo.document.nanoimpl.CaseSensitiveXMLElement)109 MapTag (com.dexels.navajo.document.navascript.tags.MapTag)12 IOException (java.io.IOException)12 NS3Compatible (com.dexels.navajo.document.navascript.tags.NS3Compatible)10 ArrayList (java.util.ArrayList)8 ParamTag (com.dexels.navajo.document.navascript.tags.ParamTag)7 InputStreamReader (java.io.InputStreamReader)7 HashMap (java.util.HashMap)7 APIException (com.dexels.navajo.article.APIException)6 ExpressionTag (com.dexels.navajo.document.navascript.tags.ExpressionTag)5 FieldTag (com.dexels.navajo.document.navascript.tags.FieldTag)5 FileInputStream (java.io.FileInputStream)5 FileReader (java.io.FileReader)5 Property (com.dexels.navajo.document.Property)4 IncludeTag (com.dexels.navajo.document.navascript.tags.IncludeTag)4 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)4 File (java.io.File)4 Message (com.dexels.navajo.document.Message)3 BlockTag (com.dexels.navajo.document.navascript.tags.BlockTag)3