app/src/main/java/com/find/wifitool/NavigateFragment.java
private MapGraph createGraph(Document document, int level) {
        Element multiLayeredGraph = (Element) document.getElementsByTagName("MultiLayeredGraph").item(0);
        Element spaceLayers = (Element) multiLayeredGraph.getElementsByTagName("spaceLayers").item(0);
        NodeList spaceLayersMembers = spaceLayers.getElementsByTagName("spaceLayerMember");

        Element roomSpaceLayerMember = (Element) spaceLayersMembers.item(level);
        Element roomSpaceLayer = (Element) roomSpaceLayerMember.getElementsByTagName("SpaceLayer").item(0);
        // get nodes
        Element roomNodes = (Element) roomSpaceLayer.getElementsByTagName("nodes").item(0);
        Log.e("rooms"," "+roomNodes.toString());
        // get edges
        Element roomEdges = (Element) roomSpaceLayer.getElementsByTagName("edges").item(0);

        Log.d("edges", " a "+roomEdges);
        // get stateMember and get informations
        NodeList roomStateMembers = roomNodes.getElementsByTagName("stateMember");
        // define temp vars and get state's informations
        Element stateMemb, state, gmlGeom, gmlPoint;
        String id, label, tempStr;
        float coords[] = new float[2];
        for (int i = 0; i < roomStateMembers.getLength(); i++) {
            stateMemb = (Element) roomStateMembers.item(i);
            state = (Element) stateMemb.getElementsByTagName("State").item(0);
            // get id
            id = state.getAttribute("gml:id");
            // get label
            label = state.getElementsByTagName("gml:name").item(0).getFirstChild().getTextContent();
            // get coordinates
            Log.d("teststart","asd");
            gmlGeom = (Element) state.getElementsByTagName("geometry").item(0);
            gmlPoint = (Element) gmlGeom.getElementsByTagName("gml:Point").item(0);
            tempStr = gmlPoint.getElementsByTagName("gml:pos").item(0).getTextContent();
            coords[0] = Float.parseFloat(tempStr.split(" ")[0]);
            coords[1] = (Float.parseFloat(tempStr.split(" ")[1])-2339-50)*(-1);

            Log.d("testend","asd");
            // add state to the list
            stateMap.put(id, (new MapGraph.State(id, label, coords[0], coords[1])));
            System.out.println(id + "\t" + label + "\t" + coords[0] + "\t" + coords[1]);
        }
        // get TransitionMember and get start and end states
        NodeList roomTransitionMembers = roomEdges.getElementsByTagName("transitionMember");
        List<MapGraph.Transition> transList = new ArrayList<>();
        // define temp vars and get transition's informations
        Element transMember, trans, start, end;
        MapGraph.State startState, endState;
        for (int i = 0; i < roomTransitionMembers.getLength(); i++) {
            transMember = (Element) roomTransitionMembers.item(i);
            trans = (Element) transMember.getElementsByTagName("Transition").item(0);
            // get start State
            start = (Element) trans.getElementsByTagName("connects").item(0);
            tempStr = start.getAttribute("xlink:href");
            startState = stateMap.get(tempStr.split("#")[1]);
            // get end State
            end = (Element) trans.getElementsByTagName("connects").item(1);
            tempStr = end.getAttribute("xlink:href");
            endState = stateMap.get(tempStr.split("#")[1]);
            // add transition to list
            System.out.println(startState.label+"\t"+endState.label);

            transList.add(new MapGraph.Transition(startState, endState));
            transList.add(new MapGraph.Transition(endState, startState));

        }
        // construct the Graph
        return new MapGraph(stateMap, transList);
    }
// For the information about the document format see the indoorGML standard
For the information about the document format see the indoorGML standard
For the information about the document format see the indoorGML standard
private MapGraph createGraph(Document document, int level) {
        Element multiLayeredGraph = (Element) document.getElementsByTagName("MultiLayeredGraph").item(0);
        Element spaceLayers = (Element) multiLayeredGraph.getElementsByTagName("spaceLayers").item(0);
        NodeList spaceLayersMembers = spaceLayers.getElementsByTagName("spaceLayerMember");
        Element roomSpaceLayerMember = (Element) spaceLayersMembers.item(level);
        Element roomSpaceLayer = (Element) roomSpaceLayerMember.getElementsByTagName("SpaceLayer").item(0);
        Element roomNodes = (Element) roomSpaceLayer.getElementsByTagName("nodes").item(0);
        Log.e("rooms"," "+roomNodes.toString());
        Element roomEdges = (Element) roomSpaceLayer.getElementsByTagName("edges").item(0);
        Log.d("edges", " a "+roomEdges);
        NodeList roomStateMembers = roomNodes.getElementsByTagName("stateMember");
        Element stateMemb, state, gmlGeom, gmlPoint;
        String id, label, tempStr;
        float coords[] = new float[2];
        for (int i = 0; i < roomStateMembers.getLength(); i++) {
            stateMemb = (Element) roomStateMembers.item(i);
            state = (Element) stateMemb.getElementsByTagName("State").item(0);
            id = state.getAttribute("gml:id");
            label = state.getElementsByTagName("gml:name").item(0).getFirstChild().getTextContent();
            Log.d("teststart","asd");
            gmlGeom = (Element) state.getElementsByTagName("geometry").item(0);
            gmlPoint = (Element) gmlGeom.getElementsByTagName("gml:Point").item(0);
            tempStr = gmlPoint.getElementsByTagName("gml:pos").item(0).getTextContent();
            coords[0] = Float.parseFloat(tempStr.split(" ")[0]);
            coords[1] = (Float.parseFloat(tempStr.split(" ")[1])-2339-50)*(-1);
            Log.d("testend","asd");
            stateMap.put(id, (new MapGraph.State(id, label, coords[0], coords[1])));
            System.out.println(id + "\t" + label + "\t" + coords[0] + "\t" + coords[1]);
        }
        NodeList roomTransitionMembers = roomEdges.getElementsByTagName("transitionMember");
        List<MapGraph.Transition> transList = new ArrayList<>();
        Element transMember, trans, start, end;
        MapGraph.State startState, endState;
        for (int i = 0; i < roomTransitionMembers.getLength(); i++) {
            transMember = (Element) roomTransitionMembers.item(i);
            trans = (Element) transMember.getElementsByTagName("Transition").item(0);
            start = (Element) trans.getElementsByTagName("connects").item(0);
            tempStr = start.getAttribute("xlink:href");
            startState = stateMap.get(tempStr.split("#")[1]);
            end = (Element) trans.getElementsByTagName("connects").item(1);
            tempStr = end.getAttribute("xlink:href");
            endState = stateMap.get(tempStr.split("#")[1]);
            System.out.println(startState.label+"\t"+endState.label);
            transList.add(new MapGraph.Transition(startState, endState));
            transList.add(new MapGraph.Transition(endState, startState));
        }
        return new MapGraph(stateMap, transList);
    }
private MapGraph createGraph ( Document document , int level ) { Element multiLayeredGraph = ( Element ) document . getElementsByTagName ( "MultiLayeredGraph" ) . item ( 0 ) ; Element spaceLayers = ( Element ) multiLayeredGraph . getElementsByTagName ( "spaceLayers" ) . item ( 0 ) ; NodeList spaceLayersMembers = spaceLayers . getElementsByTagName ( "spaceLayerMember" ) ; Element roomSpaceLayerMember = ( Element ) spaceLayersMembers . item ( level ) ; Element roomSpaceLayer = ( Element ) roomSpaceLayerMember . getElementsByTagName ( "SpaceLayer" ) . item ( 0 ) ; Element roomNodes = ( Element ) roomSpaceLayer . getElementsByTagName ( "nodes" ) . item ( 0 ) ; Log . e ( "rooms" , " " + roomNodes . toString ( ) ) ; Element roomEdges = ( Element ) roomSpaceLayer . getElementsByTagName ( "edges" ) . item ( 0 ) ; Log . d ( "edges" , " a " + roomEdges ) ; NodeList roomStateMembers = roomNodes . getElementsByTagName ( "stateMember" ) ; Element stateMemb , state , gmlGeom , gmlPoint ; String id , label , tempStr ; float coords [ ] = new float [ 2 ] ; for ( int i = 0 ; i < roomStateMembers . getLength ( ) ; i ++ ) { stateMemb = ( Element ) roomStateMembers . item ( i ) ; state = ( Element ) stateMemb . getElementsByTagName ( "State" ) . item ( 0 ) ; id = state . getAttribute ( "gml:id" ) ; label = state . getElementsByTagName ( "gml:name" ) . item ( 0 ) . getFirstChild ( ) . getTextContent ( ) ; Log . d ( "teststart" , "asd" ) ; gmlGeom = ( Element ) state . getElementsByTagName ( "geometry" ) . item ( 0 ) ; gmlPoint = ( Element ) gmlGeom . getElementsByTagName ( "gml:Point" ) . item ( 0 ) ; tempStr = gmlPoint . getElementsByTagName ( "gml:pos" ) . item ( 0 ) . getTextContent ( ) ; coords [ 0 ] = Float . parseFloat ( tempStr . split ( " " ) [ 0 ] ) ; coords [ 1 ] = ( Float . parseFloat ( tempStr . split ( " " ) [ 1 ] ) - 2339 - 50 ) * ( - 1 ) ; Log . d ( "testend" , "asd" ) ; stateMap . put ( id , ( new MapGraph . State ( id , label , coords [ 0 ] , coords [ 1 ] ) ) ) ; System . out . println ( id + "\t" + label + "\t" + coords [ 0 ] + "\t" + coords [ 1 ] ) ; } NodeList roomTransitionMembers = roomEdges . getElementsByTagName ( "transitionMember" ) ; List < MapGraph . Transition > transList = new ArrayList < > ( ) ; Element transMember , trans , start , end ; MapGraph . State startState , endState ; for ( int i = 0 ; i < roomTransitionMembers . getLength ( ) ; i ++ ) { transMember = ( Element ) roomTransitionMembers . item ( i ) ; trans = ( Element ) transMember . getElementsByTagName ( "Transition" ) . item ( 0 ) ; start = ( Element ) trans . getElementsByTagName ( "connects" ) . item ( 0 ) ; tempStr = start . getAttribute ( "xlink:href" ) ; startState = stateMap . get ( tempStr . split ( "#" ) [ 1 ] ) ; end = ( Element ) trans . getElementsByTagName ( "connects" ) . item ( 1 ) ; tempStr = end . getAttribute ( "xlink:href" ) ; endState = stateMap . get ( tempStr . split ( "#" ) [ 1 ] ) ; System . out . println ( startState . label + "\t" + endState . label ) ; transList . add ( new MapGraph . Transition ( startState , endState ) ) ; transList . add ( new MapGraph . Transition ( endState , startState ) ) ; } return new MapGraph ( stateMap , transList ) ; }
For the information about the document format see the indoorGML standard
For the information about the document format see the indoorGML standard
// get nodes // get edges // get stateMember and get informations // define temp vars and get state's informations // get id // get label // get coordinates // add state to the list // get TransitionMember and get start and end states // define temp vars and get transition's informations // get start State // get end State // add transition to list // construct the Graph