⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 garmingmldoc.java

📁 基于Java的地图数据管理软件。使用MySQL数据库管理系统。
💻 JAVA
📖 第 1 页 / 共 5 页
字号:

    return c;
  }

  public static String printDoc() {
    String n = "";

    n = walk(d);

    return n;
  }

  public static String printStucture(Document doc) {
    return walkStructure(doc, 0);
  }

  private static Element newGMLPoint(double lon, double lat, String n) {
    if (lon < 0) {
      lon = 0 - lon;
    }
    if (lat < 0) {
      lat = 0 - lat;
    }

    Element e = d.createElement("gml_Point");

    Element ename = d.createElement("gml_name");
    Text t = d.createTextNode(n);
    ename.appendChild(t);

    e.appendChild(ename);

    Element epos = d.createElement("gml_coord");

    Element ex = d.createElement("X");
    t = d.createTextNode(Double.toString(lon));
    ex.appendChild(t);

    Element ey = d.createElement("Y");
    t = d.createTextNode(Double.toString(lat));
    ey.appendChild(t);

    epos.appendChild(ex);
    epos.appendChild(ey);

    e.appendChild(epos);

    return e;
  }

  private static Element newXmlGMLPoint(double lon, double lat, String n,
                                        double alt, String dateTime) {
    Element e = d.createElement("gml_Point");

    Element ename = d.createElement("gml_name");
    Text t = d.createTextNode(n);
    ename.appendChild(t);

    e.appendChild(ename);

    Element epos = d.createElement("gml_coord");

    Element ex = d.createElement("X");
    t = d.createTextNode(Double.toString(lon));
    ex.appendChild(t);

    Element ey = d.createElement("Y");
    t = d.createTextNode(Double.toString(lat));
    ey.appendChild(t);

    Element ez = d.createElement("Z");
    t = d.createTextNode(Double.toString(alt));
    ez.appendChild(t);

    Element et = d.createElement("Time");
    t = d.createTextNode(dateTime);
    et.appendChild(t);

    epos.appendChild(ex);
    epos.appendChild(ey);
    epos.appendChild(ez);
    epos.appendChild(et);

    e.appendChild(epos);

    return e;
  }

  private static Element newXmlGMLPoint(double lon, double lat, String n,
                                        double alt, String dateTime, String RWa,
                                        String RWb,
                                        String RS, String KP, String TracksID,
                                        String[] xzcArray,
                                        String[] qlArray, String[] sdArray,
                                        String[] dkArray) {
    if (lon < 0) {
      lon = 0 - lon;
    }
    if (lat < 0) {
      lat = 0 - lat;
    }

    Element e = d.createElement("gml_Point");

    Element ename = d.createElement("gml_name");
    Text t = d.createTextNode(n);
    ename.appendChild(t);

    e.appendChild(ename);

    Element epos = d.createElement("gml_coord");

    Element ex = d.createElement("X");
    t = d.createTextNode(Double.toString(lon));
    ex.appendChild(t);

    Element ey = d.createElement("Y");
    t = d.createTextNode(Double.toString(lat));
    ey.appendChild(t);

    Element ez = d.createElement("Z");
    t = d.createTextNode(Double.toString(alt));
    ez.appendChild(t);

    Element et = d.createElement("Time");
    t = d.createTextNode(dateTime);
    et.appendChild(t);

    Element rs = d.createElement("RS"); //路面变化
    t = d.createTextNode(RS);
    rs.appendChild(t);

    Element rwa = d.createElement("RWa"); //宽度变化
    t = d.createTextNode(RWa);
    rwa.appendChild(t);

    Element rwb = d.createElement("RWb"); //宽度变化
    t = d.createTextNode(RWb);
    rwb.appendChild(t);

    Element kp = d.createElement("KP"); //关键点
    t = d.createTextNode(KP);
    kp.appendChild(t);

    Element tracksid = d.createElement("TracksID"); //航迹的ID
    t = d.createTextNode("new" + TracksID);
    tracksid.appendChild(t);

    epos.appendChild(ex);
    epos.appendChild(ey);
    epos.appendChild(ez);
    epos.appendChild(et);
    epos.appendChild(rs);
    epos.appendChild(rwa);
    epos.appendChild(rwb);
    epos.appendChild(kp);
    epos.appendChild(tracksid);
//    epos.appendChild(addElement(t,"gml_xzc",xzc));
//    epos.appendChild(addElement(t,"gml_renkou",renkou));
//    epos.appendChild(addElement(t,"gml_shouru",shouru));
//    epos.appendChild(addElement(t,"gml_jingji",jingji));
//    xzcArray = new String[11];
//    for (int i = 0; i < xzcArray.length; i++) {
//      xzcArray[i] = "子节点" + i;
//    }
    //行政村
    Element exzc = addElement(t, "gml_jtb_after_xzc", "");
    if (xzcArray != null) {
      exzc.appendChild(addXZC(exzc, xzcArray));
    }
    //桥梁
    Element eQiaoliang = addElement(t, "gml_jtb_after_qiaoliang", "");
    if (qlArray != null) {
      eQiaoliang.appendChild(addQiaoliang(eQiaoliang, qlArray));
    }
    //隧道
    Element eSuidao = addElement(t, "gml_jtb_after_suidao", "");
    if (sdArray != null) {
      eSuidao.appendChild(addSuidao(eSuidao, sdArray));
    }
    //渡口
    Element eDukou = addElement(t, "gml_jtb_after_dukou", "");
    if (dkArray != null) {
      eDukou.appendChild(addDukou(eDukou, dkArray));
    }
    epos.appendChild(exzc);
    epos.appendChild(eQiaoliang);
    epos.appendChild(eSuidao);
    epos.appendChild(eDukou);
    e.appendChild(epos);

    return e;
  }

  public static String walk(Node node) {
    String n = "";

    if (node == null) {
      System.out.println("walk node is null.");
      return n;
    }

    int type = node.getNodeType();

    switch (type) {
      case Node.DOCUMENT_NODE: {
        n = n + "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\r\n";

        break;
      }

      case Node.ELEMENT_NODE: {
        n = n + "<" + node.getNodeName();

        NamedNodeMap nnm = node.getAttributes();

        if (nnm != null) {
          int len = nnm.getLength();
          Attr attr;

          for (int i = 0; i < len; i++) {
            attr = (Attr) nnm.item(i);
            n = n + " " + attr.getNodeName() + "=\"" + attr.getNodeValue() +
                "\"";
          }
        }

        n = n + ">";

        break;
      }

      case Node.ENTITY_REFERENCE_NODE: {
        n = n + "&" + node.getNodeName() + ";";

        break;
      }

      case Node.CDATA_SECTION_NODE: {
        n = n + "<![CDATA[" + node.getNodeValue() + "]]>";

        break;

      }

      case Node.TEXT_NODE: {
        n = n + node.getNodeValue();

        break;
      }

      case Node.PROCESSING_INSTRUCTION_NODE: {
        n = n + "<?" + node.getNodeName();

        String data = node.getNodeValue();

        if (data != null && data.length() > 0) {
          n = n + " " + data;
        }

        n = n + "?>";

        break;
      }

    }

    for (Node child = node.getFirstChild(); child != null;
         child = child.getNextSibling()) {
      n = n + walk(child);
    }

    if (type == Node.ELEMENT_NODE) {
      n = n + "</" + node.getNodeName() + ">\r\n";
    }

    return n;
  }

  public static String walkStructure(Node node, int depth) {
    String n = "";
    n = "|" + n;
    for (int i = 0; i < depth; i++) {
      n = n + "--";
    }
    n = n + node.getNodeName() + ":" + node.getNodeValue() + "\r\n";
    for (Node child = node.getFirstChild(); child != null;
         child = child.getNextSibling()) {
      n = n + walkStructure(child, depth + 1);
    }
    return n;
  }

  private void addWaypointToSVG(float x, float y, String n) {
    if (svgDoc == null) {
      svgDoc = GarminConfiguration.getSVGDoc();

    }
    Element r = svgDoc.getRootElement();

    Element e = svgDoc.createElement("circle");

    e.setAttribute("style", "fill:blue;stroke:red;");
    e.setAttribute("cx", Float.toString(x));
    e.setAttribute("cy", Float.toString(y));
    e.setAttribute("r", "10");

    r.appendChild(e);
  }

  public static String updateSVGFile(String fname) {
    try {
      String tmp = GarminConfiguration.getTmpFile();

      if (tmp == null) {
        tmp = fname;

      }
      File f = new File(tmp);

      if (f.exists() && ! (fname.startsWith("jar"))) {
        f.delete();

      }
      Date d = new Date();

      int hc = d.hashCode();

      if (hc < 0) {
        hc = 0 - hc;

      }
      fname = System.getProperty("user.dir") +
          System.getProperty("file.separator") + Integer.toString(hc) + ".svg";

      File ftmp = new File(fname);

      ftmp.createNewFile();

      GarminConfiguration.setTmpFile(fname);

      PrintWriter fout = new PrintWriter(new FileOutputStream(ftmp));

      URL url = new URL(
          "jar:file:net.aetherial.gis.garmin.jar!/net/aetherial/gis/garmin/defaultMap.svg");
      JarURLConnection jarConnection = (JarURLConnection) url.openConnection();

      BufferedReader bin = new BufferedReader(new InputStreamReader(
          jarConnection.getInputStream()));

      String line = null;

      for (line = bin.readLine(); ! (line.startsWith("</svg>")) && line != null;
           line = bin.readLine()) {
        fout.println(line);
      }

      NodeList nl = root.getElementsByTagName("waypoint");

      for (int i = 0; i < nl.getLength(); i++) {
        Element e = (Element) nl.item(i);

        String name = "no name";
        String x = "0";
        String y = "0";

        NodeList nln = e.getElementsByTagName("gml_name");

        for (int j = 0; nln != null && j < nln.getLength(); j++) {
          if (nln.item(j) != null) {
            NodeList nlc = nln.item(j).getChildNodes();

            name = nlc.item(0).getNodeValue();
          }
        }

        nln = e.getElementsByTagName("X");

        for (int j = 0; nln != null && j < nln.getLength(); j++) {
          if (nln.item(j) != null) {
            NodeList nlc = nln.item(j).getChildNodes();

            x = nlc.item(0).getNodeValue();
          }
        }

        nln = e.getElementsByTagName("Y");

        for (int j = 0; nln != null && j < nln.getLength(); j++) {
          if (nln.item(j) != null) {
            NodeList nlc = nln.item(j).getChildNodes();

            y = nlc.item(0).getNodeValue();
          }
        }

        fout.println(
            "<circle style=\"fill:gray;stroke:none;opacity:0.25\" cx=\"" + x +
            "\" cy=\"" + y + "\" r=\"1\"/>");
        fout.println(
   

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -