0

I'm totally new to this and taking a Java course. There're airport markers displayed on a map then there're routes from every airport to all possible destinations.

I want to make a method that when a specific airport marker gets clicked, only this marker and the routes that belong to it with the other markers the destinations of the routes would appear.

I just want to know the conditional to use to say if this route starts from this clicked marker, and then one to say if the destination of the route is this marker so i can unhide them.

here's the starting code i'm supposed to work on, I've already implemented everything, I just don't know how to say the routes of a specific marker or the route that start or end at a certain marker to complete.

    package module6;

    import java.util.ArrayList;
    import java.util.HashMap;
    import java.util.List;

    import de.fhpotsdam.unfolding.UnfoldingMap;
    import de.fhpotsdam.unfolding.data.PointFeature;
    import de.fhpotsdam.unfolding.data.ShapeFeature;
    import de.fhpotsdam.unfolding.marker.Marker;
    import de.fhpotsdam.unfolding.marker.SimpleLinesMarker;
    import de.fhpotsdam.unfolding.marker.SimplePointMarker;
    import de.fhpotsdam.unfolding.utils.MapUtils;
    import de.fhpotsdam.unfolding.geo.Location;
    import parsing.ParseFeed;
    import processing.core.PApplet;

    /** An applet that shows airports (and routes)
     * on a world map.  
     * @author Adam Setters and the UC San Diego Intermediate Software     Development
     * MOOC team
     *
     */
     public class AirportMap extends PApplet {
    
    UnfoldingMap map;
    private List<Marker> airportList;
    List<Marker> routeList;
    
    public void setup() {
        // setting up PAppler
        size(800,600, OPENGL);
        
        // setting up map and default events
        map = new UnfoldingMap(this, 50, 50, 750, 550);
        MapUtils.createDefaultEventDispatcher(this, map);
        
        // get features from airport data
        List<PointFeature> features = ParseFeed.parseAirports(this, "airports.dat");
        
        // list for markers, hashmap for quicker access when matching with routes
        airportList = new ArrayList<Marker>();
        HashMap<Integer, Location> airports = new HashMap<Integer, Location>();
        
        // create markers from features
        for(PointFeature feature : features) {
            AirportMarker m = new AirportMarker(feature);
    
            m.setRadius(5);
            airportList.add(m);
            
            // put airport in hashmap with OpenFlights unique id for key
            airports.put(Integer.parseInt(feature.getId()), feature.getLocation());
        
        }
        
        
        // parse route data
        List<ShapeFeature> routes = ParseFeed.parseRoutes(this, "routes.dat");
        routeList = new ArrayList<Marker>();
        for(ShapeFeature route : routes) {
            
            // get source and destination airportIds
            int source = Integer.parseInt((String)route.getProperty("source"));
            int dest = Integer.parseInt((String)route.getProperty("destination"));
            
            // get locations for airports on route
            if(airports.containsKey(source) && airports.containsKey(dest)) {
                route.addLocation(airports.get(source));
                route.addLocation(airports.get(dest));
            }
            
            SimpleLinesMarker sl = new SimpleLinesMarker(route.getLocations(), route.getProperties());
        
            System.out.println(sl.getProperties());
            
            //UNCOMMENT IF YOU WANT TO SEE ALL ROUTES
            //routeList.add(sl);
        }
        
        
        
        //UNCOMMENT IF YOU WANT TO SEE ALL ROUTES
        //map.addMarkers(routeList);
        
        map.addMarkers(airportList);
        
    }
    
    public void draw() {
        background(0);
        map.draw();
        
    }
    

    }

Thanks all so much :)

0

I suppose you know how to listen for clicks on a particular AirportMarker as well as how to access it when clicked, so I'm just gonna skip to the point. but feel free to comment with further questions, if you're not sure!

per the source code for AirportMarker, it has a public method, addRoute that takes a SimpleLinesMarker and adds it to the list of routes associated with that marker.

I don't see it done for you in the distribution code, but probably inside the if statement that checks whether airports contains source and destination you should find those AirportMarkers, whose IDs are source and destination, in airportList and after declaring and initializing sl, you should probably add it as a route to the source and destination airports (if found).

that way, all you have to do when an airport markers gets clicked is to hide all the routes that are currently shown on the map and show the routes in the public list of routes accessible through the clicked marker.

1
  • :D I was just going to tell you to check my question if you can! Thanks a lot Kareem. now I have the routes of a certain marker show when I click on this marker. I still have left the step that I want the destination Airport markers to show as well. I just haven't gone through anything related to this at all and not even throughout this course. That's why I have no idea about it. Thank you :) like always :) @Kareem
    – Riham Nour
    May 20 '16 at 15:53

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .