Announcement

Collapse
No announcement yet.

Adding WW icon based add-ons to WWJ

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Adding WW icon based add-ons to WWJ

    Here is a first shot at a WW icon add-ons loader for WWJ. It creates icon layers from a WW add-on XML config file.



    I tested it with mazop Highest Mountains and the classic Landmark Catalog. It supports 'clickable urls' and descriptions - but the latter is not displayed yet .

    Also, ChildLayerSets are flatten out into one linear list - no layer hierarchy.
    My World Wind Java Blog & WW.net Plugins page

  • #2
    Good job ! I think that a way to display boundaries could be also very useful
    -Nicolas CASTEL- Thales Alenia Space, Toulouse, France-

    Comment


    • #3
      Hi!

      This looks really great and promizing!

      I have a question though (I'm a beginner)... Would it be possible to adapt your code to get it to read a xml featuring this kind of structure ? :
      http://rodolphe.geo6331.googlepages.com/SITES.xml
      (I just want to read the site number and the coordinate out of this messy xml)

      I changed your source to this, it doesn't seem to work (doesn't give any error though):
      http://rodolphe.geo6331.googlepages....SitesLayer.txt

      Any idea would be muuuuch appreciated!
      Last edited by rodolphe; 05-30-2007, 07:54 PM.

      Comment


      • #4
        Rodolphe, yes you can read that xml file, but you have to do more changes to the code.

        For one thing, you have to change (or remove) the findLayerSetByName method call in loadIcons() and pass the document root node (dataroot) to loadLayerSet() instead. Actually it doesnt find any "Layerset" node so doesnt process anything - with no error.

        In loadLayerSet, change "Icon" with "SITES" at the beginning.

        Code:
        else if(child.getNodeName().compareToIgnoreCase("SITES") == 0)
        My World Wind Java Blog & WW.net Plugins page

        Comment


        • #5
          Hi Pat.

          Excellent, I'll try first thing in the morning tomorrow. Thanks so much!

          Comment


          • #6
            Hmm, I must be doing something wrong... How can I pass dataroot to loadLayerSet() instead of going through the method findLayerSetByName() ? I wrote (probably naively) Node node = "dataroot"; ?

            Code:
            public class WWXMLSitesLayer extends IconLayer implements SelectListener {
            	
                public WWXMLSitesLayer(String fileName, String layerName)
                {
                    this.setName(layerName);
                    this.loadIcons(readXML(new File(fileName)), layerName);
                }
                
                // Load icons from XML document named layer
                private void loadIcons(Document doc, String layerName) {
                	// Get LayerSet node
                    // Node node = findLayerSetByName(doc, layerName);
                	Node node = "dataroot";
                    if(node == null)
                    	return; // TODO: throw exception
            
                    loadLayerSet(node);
                }
                
                // Load icons from a LayerSet node (recursive)
                private void loadLayerSet(Node node) {
                    // Process icon child nodes
                    Node child;
                    for(int i = 0; i < node.getChildNodes().getLength(); i++) {
                    	child = node.getChildNodes().item(i);
                    	if(child.getNodeName().compareToIgnoreCase("SITES") == 0) {
                    		loadLayerSet(child);	// recurse
                    	}
                    	else if(child.getNodeName().compareToIgnoreCase("SITES") == 0) {
                    		// Get icon info
                    		Node n;
                          	n = findChildByName(child, "FECD_ID");
                          	String name = n.getTextContent();
                          	n = findChildByName(child, "LATITUDE");
                        	double latitude = Double.parseDouble(findChildByName(n, "LATITUDE").getTextContent());
                          	n = findChildByName(child, "LONGITUDE");
                        	double longitude = Double.parseDouble(findChildByName(n, "LONGITUDE").getTextContent());
                          	n = findChildByName(child, "DistanceAboveSurface");
                          	double distanceAboveSurface = 5;
                          	n = findChildByName(child, "TextureFilePath");
                          	String textureFilePath = "mountains.png";
                          	n = findChildByName(child, "TextureWidthPixels");
                          	int textureWidthPixels = 128;

            Comment


            • #7
              Well... i guess everybody has to start learning Java someday...

              Try this to get to the "dataroot" node :
              Code:
              Node node = doc.getFirstChild()
              Then remove the first "if()... else" part of loadLayerSet() :
              Code:
                          ...
                          child = node.getChildNodes().item(i);
                          if(child.getNodeName().compareToIgnoreCase("SITES") == 0) {
                                // Get icon info
                                Node n;
                                n = findChildByName(child, "FECD_ID");
                                String name = n.getTextContent();
                                n = findChildByName(child, "LATITUDE");
                                ...
              That will avoid 'infinite recursion' which usually ends up in stack overflow or some similar error.
              Last edited by patmurris; 06-01-2007, 01:46 AM.
              My World Wind Java Blog & WW.net Plugins page

              Comment


              • #8
                Hmm... now i'm not sure about how to get to the document root node - named "dataroot"

                This may be more appropriate :
                Code:
                Node node = doc.getDocumentElement();
                I'll try to load your xml when i can. I'm still learning myself
                And BTW there was no infinite recursion risk... but you dont need that anyway.
                Last edited by patmurris; 06-01-2007, 04:29 AM.
                My World Wind Java Blog & WW.net Plugins page

                Comment


                • #9
                  Code:
                  Node rootNode = doc.getElementsByTagName("dataroot").item(0);
                  ?
                  Machine. Unexpectedly, I’d invented a time
                  - Alan Moore

                  Comment


                  • #10
                    Originally posted by Chade View Post
                    Code:
                    Node rootNode = doc.getElementsByTagName("dataroot").item(0);
                    ?
                    Yes that one would centainly work
                    My World Wind Java Blog & WW.net Plugins page

                    Comment


                    • #11
                      Ok, I tried these three methods to get to the dataroot node :

                      *
                      Code:
                      Node node = doc.getFirstChild();
                      *
                      Code:
                      Node node = doc.getDocumentElement();
                      *
                      Code:
                      Node node = doc.getElementsByTagName("dataroot").item(0);
                      None of them seem to work, the "node" variable is NULL everytime.

                      I keep looking around to try and figure it out, but if you guys have an idea...

                      XML Document :
                      Code:
                      <?xml version="1.0" encoding="UTF-8"?>
                      <dataroot xmlns:od="urn:schemas-microsoft-com:officedata" generated="2007-05-25T20:41:06">
                      <SITES>
                      <FECD_ID>18</FECD_ID>
                      <LATITUDE>55.53</LATITUDE>
                      <LONGITUDE>-98.41</LONGITUDE>
                      <SITE_INFORMATION>
                      <FECD_ID>18</FECD_ID>
                      <ORIGINAL_SOURCE>Halliwell &amp; Apps, 1997</ORIGINAL_SOURCE>
                      <ORIGINAL_SOURCE_ID>MAN TE-OA (1)</ORIGINAL_SOURCE_ID>
                      <ESTABLISHMENT_DATE>1994</ESTABLISHMENT_DATE>
                      <PROVINCE>MB</PROVINCE>
                      <TERRESTRIAL_ECOZONE>Boreal Shield</TERRESTRIAL_ECOZONE>
                      <TERRESTRIAL_ECOREGION_TEXT>Churchill River Upland</TERRESTRIAL_ECOREGION_TEXT>
                      <ORDER>Brunisolic</ORDER>
                      <SUB_GROUP_GREAT_GROUP>Gleyed Melanic</SUB_GROUP_GREAT_GROUP>
                      <DRAINAGE_CLASS_ID>Imperfectly</DRAINAGE_CLASS_ID>
                      <FEATURE_DEPTH>33</FEATURE_DEPTH>
                      <SOIL_FEATURE>Carbonates</SOIL_FEATURE>
                      <ROOTING_DEPTH>53</ROOTING_DEPTH>
                      <DOMINANT_TREE_1>POPU TRE</DOMINANT_TREE_1>
                      <CODOMINANT_TREE_1>POPU TRE</CODOMINANT_TREE_1>
                      ...

                      Comment


                      • #12
                        The third one does work here - Node node = doc.getElementsByTagName("dataroot").ite m(0);.
                        Maybe the xml doc is null - not found ?
                        The latitude / longitude tags where not read properly - the WW xml includes a child tag named 'value' that is not in your xml structure.
                        Here is a working version (zip 4k)


                        Nice to see so many mountains in Canada

                        Edit : all three methods above to get the document root do work actually.
                        Last edited by patmurris; 06-01-2007, 09:13 PM.
                        My World Wind Java Blog & WW.net Plugins page

                        Comment


                        • #13
                          Originally posted by patmurris View Post

                          Nice to see so many mountains in Canada
                          The data show a clear anti-american bias.

                          Comment


                          • #14
                            "With US or against US"
                            My World Wind Java Blog & WW.net Plugins page

                            Comment


                            • #15
                              WOW!!! This is so cool, thank you so much for your work, this is very helpful!!! I'm going to analyse the changes now, this is my first steps in Java, this is teaching me a lot...

                              Originally posted by patmurris View Post
                              The third one does work here - Node node = doc.getElementsByTagName("dataroot").ite m(0);.
                              Maybe the xml doc is null - not found ?
                              The latitude / longitude tags where not read properly - the WW xml includes a child tag named 'value' that is not in your xml structure.
                              Here is a working version (zip 4k)


                              Nice to see so many mountains in Canada

                              Edit : all three methods above to get the document root do work actually.

                              Comment

                              Working...
                              X