Search in sources :

Example 6 with Coordinate

use of org.openstreetmap.gui.jmapviewer.Coordinate in project Course_Generator by patrovite.

the class JPanelMaps method RefreshTrack.

/**
 * Display track stored in a TrackData class
 *
 * @param tdata
 *            TrackData object to display
 * @param zoom2fit
 *            If true the zoom is set have the complete display of the track
 */
public void RefreshTrack(TrackData tdata, boolean zoom2fit) {
    if (tdata == null)
        return;
    // Enabling the map tools
    btMapAddMarker.setEnabled(true);
    btMapMark.setEnabled(true);
    btMapEat.setEnabled(true);
    btMapDrink.setEnabled(true);
    // -- Remove the previous track
    MapViewer.removeAllMapPolygons();
    MapViewer.removeAllMapMarkers();
    MapMarker = null;
    CurrentPosMarker = null;
    // -- Create the route
    List<Coordinate> route1 = new ArrayList<Coordinate>();
    double last_diff = tdata.data.get(0).getDiff();
    for (CgData r : tdata.data) {
        if (r.getDiff() == last_diff) {
            route1.add(new Coordinate(r.getLatitude(), r.getLongitude()));
        } else {
            route1.add(new Coordinate(r.getLatitude(), r.getLongitude()));
            MapPolyLine polyLine1 = new MapPolyLine(route1);
            // -- Set the line color
            if (last_diff == 100.0)
                polyLine1.setColor(CgConst.CL_MAP_DIFF_VERYEASY);
            else if (last_diff >= 98.0)
                polyLine1.setColor(CgConst.CL_MAP_DIFF_EASY);
            else if (last_diff >= 95.0)
                polyLine1.setColor(CgConst.CL_MAP_DIFF_AVERAGE);
            else if (last_diff >= 88)
                polyLine1.setColor(CgConst.CL_MAP_DIFF_HARD);
            else
                polyLine1.setColor(CgConst.CL_MAP_DIFF_VERYHARD);
            // -- Track width
            polyLine1.setStroke(new BasicStroke(CgConst.TRACK_TICKNESS));
            // -- Upddate the viewer
            MapViewer.addMapPolygon(polyLine1);
            route1 = new ArrayList<Coordinate>();
            route1.add(new Coordinate(r.getLatitude(), r.getLongitude()));
        }
        last_diff = r.getDiff();
    }
    // -- Add the last polyline
    MapPolyLine polyLine1 = new MapPolyLine(route1);
    // -- Set the line color
    if (last_diff >= 98.0)
        polyLine1.setColor(Color.GREEN);
    else if (last_diff >= 95.0)
        polyLine1.setColor(Color.BLUE);
    else if (last_diff >= 88)
        polyLine1.setColor(Color.RED);
    else
        polyLine1.setColor(Color.BLACK);
    // -- Set the stroke
    polyLine1.setStroke(new BasicStroke(3));
    // -- Upddate the viewer
    MapViewer.addMapPolygon(polyLine1);
    // -- Zoom to display the track
    if (zoom2fit)
        MapViewer.setDisplayToFitMapPolygons();
    for (CgData r : tdata.data) {
        int t = r.getTag();
        int v = 0;
        if ((t & CgConst.TAG_MARK) != 0)
            v = v + 1;
        if ((t & CgConst.TAG_EAT_PT) != 0)
            v = v + 2;
        if ((t & CgConst.TAG_WATER_PT) != 0)
            v = v + 4;
        if (v != 0)
            MapViewer.addMapMarker(new MapMarkerImg(new Coordinate(r.getLatitude(), r.getLongitude()), createImageIcon("/course_generator/images/markers_" + v + ".png", "").getImage()));
    }
}
Also used : BasicStroke(java.awt.BasicStroke) Coordinate(org.openstreetmap.gui.jmapviewer.Coordinate) ArrayList(java.util.ArrayList) CgData(course_generator.CgData)

Example 7 with Coordinate

use of org.openstreetmap.gui.jmapviewer.Coordinate in project Course_Generator by patrovite.

the class JPanelMaps method MapViewerMouseClicked.

private void MapViewerMouseClicked(java.awt.event.MouseEvent evt) {
    if (Track == null)
        return;
    if (Track.data == null)
        return;
    if (Track.data.size() <= 0)
        return;
    selectedPosition = MapViewer.getPosition(evt.getX(), evt.getY());
    notifyMouseClicked(evt);
    // Find the nearest point
    Coordinate c = MapViewer.getPosition(evt.getX(), evt.getY());
    // int i = Track.FindNearestPoint(c.getLat(), c.getLon());
    // //Selection the position on the data grid
    // panelTrackData.setSelectedRow(i);
    // 
    // //Refresh profil position
    // panelProfil.RefreshProfilInfo(i);
    // panelProfil.setCrosshairPosition(Track.data.get(i).getTotal(Settings.Unit) / 1000.0, Track.data.get(i).getElevation(Settings.Unit));
    // Refresh position marker on the map
    int i = Track.FindNearestPoint(c.getLat(), c.getLon());
    RefreshCurrentPosMarker(Track.data.get(i).getLatitude(), Track.data.get(i).getLongitude());
}
Also used : Coordinate(org.openstreetmap.gui.jmapviewer.Coordinate)

Aggregations

Coordinate (org.openstreetmap.gui.jmapviewer.Coordinate)7 ArrayList (java.util.ArrayList)2 CgData (course_generator.CgData)1 JPanelAnalysisSpeed (course_generator.analysis.JPanelAnalysisSpeed)1 JPanelAnalysisSpeedSlope (course_generator.analysis.JPanelAnalysisSpeedSlope)1 JPanelAnalysisTimeDist (course_generator.analysis.JPanelAnalysisTimeDist)1 course_generator.dialogs.frmEditPosition (course_generator.dialogs.frmEditPosition)1 course_generator.dialogs.frmSearchPoint (course_generator.dialogs.frmSearchPoint)1 JPanelMaps (course_generator.maps.JPanelMaps)1 JPanelMapsListener (course_generator.maps.JPanelMapsListener)1 JPanelProfil (course_generator.profil.JPanelProfil)1 JPanelProfilListener (course_generator.profil.JPanelProfilListener)1 JPanelResume (course_generator.resume.JPanelResume)1 JPanelResumeListener (course_generator.resume.JPanelResumeListener)1 JPanelStatistics (course_generator.statistics.JPanelStatistics)1 JPanelTrackData (course_generator.trackdata.JPanelTrackData)1 JPanelTrackDataListener (course_generator.trackdata.JPanelTrackDataListener)1 BasicStroke (java.awt.BasicStroke)1 BorderLayout (java.awt.BorderLayout)1 Container (java.awt.Container)1