Exemple #1
0
 private static LatLon getProject(Location loc, Location from, Location to) {
   return MapUtils.getProjection(
       loc.getLatitude(),
       loc.getLongitude(),
       from.getLatitude(),
       from.getLongitude(),
       to.getLatitude(),
       to.getLongitude());
 }
Exemple #2
0
 private static double getOrthogonalDistance(Location loc, Location from, Location to) {
   return MapUtils.getOrthogonalDistance(
       loc.getLatitude(),
       loc.getLongitude(),
       from.getLatitude(),
       from.getLongitude(),
       to.getLatitude(),
       to.getLongitude());
 }
Exemple #3
0
 public List<Amenity> searchAmenitiesOnThePath(
     List<Location> locations,
     double radius,
     SearchPoiTypeFilter filter,
     ResultMatcher<Amenity> matcher) {
   searchAmenitiesInProgress = true;
   final List<Amenity> amenities = new ArrayList<Amenity>();
   try {
     if (locations != null && locations.size() > 0) {
       List<AmenityIndexRepository> repos = new ArrayList<AmenityIndexRepository>();
       double topLatitude = locations.get(0).getLatitude();
       double bottomLatitude = locations.get(0).getLatitude();
       double leftLongitude = locations.get(0).getLongitude();
       double rightLongitude = locations.get(0).getLongitude();
       for (Location l : locations) {
         topLatitude = Math.max(topLatitude, l.getLatitude());
         bottomLatitude = Math.min(bottomLatitude, l.getLatitude());
         leftLongitude = Math.min(leftLongitude, l.getLongitude());
         rightLongitude = Math.max(rightLongitude, l.getLongitude());
       }
       if (!filter.isEmpty()) {
         for (AmenityIndexRepository index : amenityRepositories.values()) {
           if (index.checkContains(topLatitude, leftLongitude, bottomLatitude, rightLongitude)) {
             repos.add(index);
           }
         }
         if (!repos.isEmpty()) {
           for (AmenityIndexRepository r : repos) {
             List<Amenity> res = r.searchAmenitiesOnThePath(locations, radius, filter, matcher);
             if (res != null) {
               amenities.addAll(res);
             }
           }
         }
       }
     }
   } finally {
     searchAmenitiesInProgress = false;
   }
   return amenities;
 }
  @Override
  public void onCreate(Bundle savedInstanceState) {
    app = getMyApplication();
    settings = app.getSettings();
    app.applyTheme(this);
    super.onCreate(savedInstanceState);

    mapActions = new MapActivityActions(this);
    mapLayers = new MapActivityLayers(this);
    requestWindowFeature(Window.FEATURE_NO_TITLE);
    // Full screen is not used here
    // getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
    // WindowManager.LayoutParams.FLAG_FULLSCREEN);
    setContentView(R.layout.main);
    startProgressDialog = new ProgressDialog(this);
    startProgressDialog.setCancelable(true);
    app.checkApplicationIsBeingInitialized(this, startProgressDialog);
    parseLaunchIntentLocation();

    mapView = (OsmandMapTileView) findViewById(R.id.MapView);
    mapView.setTrackBallDelegate(
        new OsmandMapTileView.OnTrackBallListener() {
          @Override
          public boolean onTrackBallEvent(MotionEvent e) {
            showAndHideMapPosition();
            return MapActivity.this.onTrackballEvent(e);
          }
        });
    mapView.setAccessibilityActions(new MapAccessibilityActions(this));
    if (mapViewTrackingUtilities == null) {
      mapViewTrackingUtilities = new MapViewTrackingUtilities(app);
    }
    mapViewTrackingUtilities.setMapView(mapView);

    // Do some action on close
    startProgressDialog.setOnDismissListener(
        new DialogInterface.OnDismissListener() {
          @Override
          public void onDismiss(DialogInterface dialog) {
            app.getResourceManager().getRenderer().clearCache();
            mapView.refreshMap(true);
          }
        });

    app.getResourceManager()
        .getMapTileDownloader()
        .addDownloaderCallback(
            new IMapDownloaderCallback() {
              @Override
              public void tileDownloaded(DownloadRequest request) {
                if (request != null && !request.error && request.fileToSave != null) {
                  ResourceManager mgr = app.getResourceManager();
                  mgr.tileDownloaded(request);
                }
                if (request == null || !request.error) {
                  mapView.tileDownloaded(request);
                }
              }
            });
    createProgressBarForRouting();
    // This situtation could be when navigation suddenly crashed and after restarting
    // it tries to continue the last route
    if (settings.FOLLOW_THE_ROUTE.get()
        && !app.getRoutingHelper().isRouteCalculated()
        && !app.getRoutingHelper().isRouteBeingCalculated()) {
      FailSafeFuntions.restoreRoutingMode(this);
    }

    mapLayers.createLayers(mapView);

    if (!settings.isLastKnownMapLocation()) {
      // show first time when application ran
      net.osmand.Location location = app.getLocationProvider().getFirstTimeRunDefaultLocation();
      if (location != null) {
        mapView.setLatLon(location.getLatitude(), location.getLongitude());
        mapView.setZoom(14);
      }
    }
    addDialogProvider(mapActions);
    OsmandPlugin.onMapActivityCreate(this);
    if (lockView != null) {
      ((FrameLayout) mapView.getParent()).addView(lockView);
    }
  }
Exemple #5
0
 public void announceVisibleLocations() {
   Location lastKnownLocation = app.getRoutingHelper().getLastProjection();
   if (lastKnownLocation != null && app.getRoutingHelper().isFollowingMode()) {
     for (int type = 0; type < locationPoints.size(); type++) {
       int currentRoute = route.getCurrentRoute();
       List<LocationPointWrapper> approachPoints = new ArrayList<LocationPointWrapper>();
       List<LocationPointWrapper> announcePoints = new ArrayList<LocationPointWrapper>();
       List<LocationPointWrapper> lp = locationPoints.get(type);
       if (lp != null) {
         int kIterator = pointsProgress.get(type);
         while (kIterator < lp.size() && lp.get(kIterator).routeIndex < currentRoute) {
           kIterator++;
         }
         pointsProgress.set(type, kIterator);
         while (kIterator < lp.size()) {
           LocationPointWrapper lwp = lp.get(kIterator);
           if (route.getDistanceToPoint(lwp.routeIndex) > LONG_ANNOUNCE_RADIUS * 2) {
             break;
           }
           LocationPoint point = lwp.point;
           double d1 =
               Math.max(
                   0.0,
                   MapUtils.getDistance(
                           lastKnownLocation.getLatitude(),
                           lastKnownLocation.getLongitude(),
                           point.getLatitude(),
                           point.getLongitude())
                       - lwp.getDeviationDistance());
           Integer state = locationPointsStates.get(point);
           if (state != null
               && state.intValue() == ANNOUNCED_ONCE
               && getVoiceRouter()
                   .isDistanceLess(lastKnownLocation.getSpeed(), d1, SHORT_ANNOUNCE_RADIUS, 0f)) {
             locationPointsStates.put(point, ANNOUNCED_DONE);
             announcePoints.add(lwp);
           } else if (type != ALARMS
               && (state == null || state == NOT_ANNOUNCED)
               && getVoiceRouter()
                   .isDistanceLess(lastKnownLocation.getSpeed(), d1, LONG_ANNOUNCE_RADIUS, 0f)) {
             locationPointsStates.put(point, ANNOUNCED_ONCE);
             approachPoints.add(lwp);
           } else if (type == ALARMS
               && (state == null || state == NOT_ANNOUNCED)
               && getVoiceRouter()
                   .isDistanceLess(lastKnownLocation.getSpeed(), d1, ALARMS_ANNOUNCE_RADIUS, 0f)) {
             locationPointsStates.put(point, ANNOUNCED_ONCE);
             approachPoints.add(lwp);
           }
           kIterator++;
         }
         if (!announcePoints.isEmpty()) {
           if (announcePoints.size() > ANNOUNCE_POI_LIMIT) {
             announcePoints = announcePoints.subList(0, ANNOUNCE_POI_LIMIT);
           }
           if (type == WAYPOINTS) {
             getVoiceRouter().announceWaypoint(announcePoints);
           } else if (type == POI) {
             getVoiceRouter().announcePoi(announcePoints);
           } else if (type == ALARMS) {
             // nothing to announce
           } else if (type == FAVORITES) {
             getVoiceRouter().announceFavorite(announcePoints);
           }
         }
         if (!approachPoints.isEmpty()) {
           if (approachPoints.size() > APPROACH_POI_LIMIT) {
             approachPoints = approachPoints.subList(0, APPROACH_POI_LIMIT);
           }
           if (type == WAYPOINTS) {
             getVoiceRouter().approachWaypoint(lastKnownLocation, approachPoints);
           } else if (type == POI) {
             getVoiceRouter().approachPoi(lastKnownLocation, approachPoints);
           } else if (type == ALARMS) {
             EnumSet<AlarmInfoType> ait = EnumSet.noneOf(AlarmInfoType.class);
             for (LocationPointWrapper pw : approachPoints) {
               ait.add(((AlarmInfo) pw.point).getType());
             }
             for (AlarmInfoType t : ait) {
               app.getRoutingHelper().getVoiceRouter().announceAlarm(t);
             }
           } else if (type == FAVORITES) {
             getVoiceRouter().approachFavorite(lastKnownLocation, approachPoints);
           }
         }
       }
     }
   }
 }