com.mapbox.mapboxsdk.geometry.LatLng Java Examples

The following examples show how to use com.mapbox.mapboxsdk.geometry.LatLng. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
@Override
public void setEventInfo(Pair<ProgramEventViewModel, LatLng> eventInfo) {
    if (currentMarker != null) {
        markerViewManager.removeMarker(currentMarker);
    }
    InfoWindowEventBinding binding = InfoWindowEventBinding.inflate(LayoutInflater.from(this));
    binding.setEvent(eventInfo.val0());
    binding.setPresenter(presenter);
    View view = binding.getRoot();
    view.setOnClickListener(viewClicked ->
            markerViewManager.removeMarker(currentMarker));
    view.setOnLongClickListener(view1 -> {
        presenter.onEventClick(eventInfo.val0().uid(), eventInfo.val0().orgUnitUid());
        return true;
    });
    view.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT));
    currentMarker = new MarkerView(eventInfo.val1(), view);
    markerViewManager.addMarker(currentMarker);
}
 
Example #2
Source Project: OpenMapKitAndroid   Author: posm   File: MapTileLayerArray.java    License: BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Override
public LatLng getCenterCoordinate() {
    float latitude = 0;
    float longitude = 0;
    int nb = 0;
    synchronized (mTileProviderList) {
        for (final MapTileModuleLayerBase tileProvider : mTileProviderList) {
            LatLng providerCenter = tileProvider.getCenterCoordinate();
            if (providerCenter != null) {
                latitude += providerCenter.getLatitude();
                longitude += providerCenter.getLongitude();
                nb++;
            }
        }
    }
    if (nb > 0) {
        latitude /= nb;
        longitude /= nb;
        return new LatLng(latitude, longitude);
    }
    return null;
}
 
Example #3
Source Project: graphhopper-navigation-android   Author: graphhopper   File: NavigationCamera.java    License: MIT License 6 votes vote down vote up
/**
 * Creates an initial animation with the given {@link RouteInformation#route()}.
 * <p>
 * This is the first animation that fires prior to receiving progress updates.
 * <p>
 * If a user interacts with the {@link MapboxMap} while the animation is in progress,
 * the animation will be cancelled.  So it's important to add the {@link ProgressChangeListener}
 * in both onCancel() and onFinish() scenarios.
 *
 * @param routeInformation with route data
 */
private void animateCameraFromRoute(RouteInformation routeInformation) {

  Camera cameraEngine = navigation.getCameraEngine();

  Point targetPoint = cameraEngine.target(routeInformation);
  LatLng targetLatLng = new LatLng(targetPoint.latitude(), targetPoint.longitude());
  double bearing = cameraEngine.bearing(routeInformation);
  double zoom = cameraEngine.zoom(routeInformation);

  CameraPosition position = new CameraPosition.Builder()
    .target(targetLatLng)
    .bearing(bearing)
    .zoom(zoom)
    .build();

  updateMapCameraPosition(position, new AddProgressListenerCancelableCallback(navigation, progressChangeListener));
}
 
Example #4
Source Project: android   Author: prkng   File: MapUtils.java    License: MIT License 6 votes vote down vote up
public static void setInitialCenterCoordinates(final MapView mapView, Bundle extras) throws UnsupportedAreaException {
    final long startMillis = System.currentTimeMillis();

    final LatLngZoom initialCoords = MapUtils
            .getInitialCenterCoordinates(mapView, extras);

    if (initialCoords != null) {
        mapView.setLatLng((LatLng) initialCoords);
        mapView.setZoom(initialCoords.getZoom(), true);
    } else if (mapView.isMyLocationEnabled()) {
        mapView.setOnMyLocationChangeListener(new MapView.OnMyLocationChangeListener() {
            @Override
            public void onMyLocationChange(Location location) {
                if (System.currentTimeMillis() - startMillis > DateUtils.SECOND_IN_MILLIS) {
                    mapView.setOnMyLocationChangeListener(null);
                } else if (CityBoundsHelper.isValidLocation(mapView.getContext(), location)) {
                    mapView.setOnMyLocationChangeListener(null);

                    mapView.setLatLng(new LatLng(
                            location.getLatitude(), location.getLongitude()));
                    mapView.setZoom(Const.UiConfig.MY_LOCATION_ZOOM, true);
                }
            }
        });
    }
}
 
Example #5
Source Project: AirMapSDK-Android   Author: airmap   File: MyLocationMapActivity.java    License: Apache License 2.0 6 votes vote down vote up
private void zoomTo(Location location, boolean force) {
    // only zoom to user's location once
    if (!hasLoadedMyLocation || force) {

        // move map camera
        int duration = getMapView().getMap().getCameraPosition().zoom < 10 ? 2500 : 1000;
        getMapView().getMap().animateCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(location.getLatitude(), location.getLongitude()), 13), duration);

        // stop location requests
        locationComponent.getLocationEngine().removeLocationUpdates(new LocationEngineCallback<LocationEngineResult>() {
            @Override
            public void onSuccess(LocationEngineResult result) {}

            @Override
            public void onFailure(@NonNull Exception exception) {}
        });
        hasLoadedMyLocation = true;

        // save location to prefs
        PreferenceManager.getDefaultSharedPreferences(this)
                .edit()
                .putFloat(AirMapConstants.LAST_LOCATION_LATITUDE, (float) location.getLatitude())
                .putFloat(AirMapConstants.LAST_LOCATION_LONGITUDE, (float) location.getLongitude())
                .apply();
    }
}
 
Example #6
Source Project: android   Author: prkng   File: PrkngDataDownloadTask.java    License: MIT License 6 votes vote down vote up
protected void drawRadius(LatLng center, LatLng northWest) {
    final LatLng realNW = vMap.fromScreenLocation(new PointF(0, 0));
    final LatLng realCenter = vMap.getLatLng();

    vMap.addMarker(new MarkerOptions().position(northWest));
    vMap.addMarker(new MarkerOptions().position(center));
    vMap.addMarker(new MarkerOptions().position(realNW));
    vMap.addMarker(new MarkerOptions().position(realCenter));

    vMap.addPolyline(new PolylineOptions()
            .add(new LatLng[]{center, northWest})
            .color(Color.GREEN)
            .width(5));

    vMap.addPolyline(new PolylineOptions()
            .add(new LatLng[]{realCenter, realNW})
            .color(Color.YELLOW)
            .width(5));
}
 
Example #7
Source Project: AirMapSDK-Android   Author: airmap   File: PointMath.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Finds the intersection between 2 lines, if it exists
 * @param line1 Line 1 to check
 * @param line2 Line 2 to check
 * @return null if no intersection, otherwise the intersection point
 */
@Nullable
private static LatLng lineIntersect(Line line1, Line line2) {
    double x1 = line1.a.getLatitude();
    double y1 = line1.a.getLongitude();
    double x2 = line1.b.getLatitude();
    double y2 = line1.b.getLongitude();
    double x3 = line2.a.getLatitude();
    double y3 = line2.a.getLongitude();
    double x4 = line2.b.getLatitude();
    double y4 = line2.b.getLongitude();
    double denom = (y4 - y3) * (x2 - x1) - (x4 - x3) * (y2 - y1);
    if (denom == 0.0) { // Lines are parallel.
        return null;
    }
    double ua = ((x4 - x3) * (y1 - y3) - (y4 - y3) * (x1 - x3)) / denom;
    double ub = ((x2 - x1) * (y1 - y3) - (y2 - y1) * (x1 - x3)) / denom;
    if (ua >= 0.0f && ua <= 1.0f && ub >= 0.0f && ub <= 1.0f) {
        // Get the intersection point.
        return new LatLng((x1 + ua * (x2 - x1)), (y1 + ua * (y2 - y1)));
    }
    return null;
}
 
Example #8
Source Project: graphhopper-navigation-example   Author: graphhopper   File: NavigationLauncherActivity.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public void onDialogPositiveClick(DialogFragment dialog) {
    EditText jobId = dialog.getDialog().findViewById(R.id.job_id);
    // Check if it's a solution fetch
    if (jobId != null) {
        EditText vehicleId = dialog.getDialog().findViewById(R.id.vehicle_id);

        fetchVrpSolution(jobId.getText().toString(), vehicleId.getText().toString());
    }
    // Check if it's a geocoding search
    EditText search = dialog.getDialog().findViewById(R.id.geocoding_input_id);
    if (search != null) {
        currentGeocodingInput = search.getText().toString();

        showLoading();
        String point = null;
        LatLng pointLatLng = this.mapboxMap.getCameraPosition().target;
        if (pointLatLng != null)
            point = pointLatLng.getLatitude() + "," + pointLatLng.getLongitude();
        new FetchGeocodingTask(this, getString(R.string.gh_key)).execute(new FetchGeocodingConfig(currentGeocodingInput, getLanguageFromSharedPreferences().getLanguage(), 5, false, point, "default"));
    }

}
 
Example #9
Source Project: mapbox-plugins-android   Author: mapbox   File: LineManagerTest.java    License: BSD 2-Clause "Simplified" License 6 votes vote down vote up
@Test
public void testIgnoreClearedAnnotations() {
  lineManager = new LineManager(mapView, mapboxMap, style, coreElementProvider, null, null, draggableAnnotationController);
  List<LatLng>latLngs = new ArrayList<>();
  latLngs.add(new LatLng());
  latLngs.add(new LatLng(1,1));
  LineOptions options = new LineOptions().withLatLngs(latLngs);
   Line  line = lineManager.create(options);
  assertEquals(1, lineManager.annotations.size());

  lineManager.getAnnotations().clear();
  lineManager.updateSource();
  assertTrue(lineManager.getAnnotations().isEmpty());

  lineManager.update(line);
  assertTrue(lineManager.getAnnotations().isEmpty());
}
 
Example #10
OfflineRegionDefinition createRegion() {
  if (mapboxMap == null) {
    throw new NullPointerException("MapboxMap is null and can't be used to create Offline region"
      + "definition.");
  }
  RectF rectF = getSelectionRegion();
  LatLng northEast = mapboxMap.getProjection().fromScreenLocation(new PointF(rectF.right, rectF.top));
  LatLng southWest = mapboxMap.getProjection().fromScreenLocation(new PointF(rectF.left, rectF.bottom));

  LatLngBounds bounds = new LatLngBounds.Builder().include(northEast).include(southWest).build();
  double cameraZoom = mapboxMap.getCameraPosition().zoom;
  float pixelRatio = getActivity().getResources().getDisplayMetrics().density;

  return new OfflineTilePyramidRegionDefinition(
    mapboxMap.getStyle().getUrl(), bounds, cameraZoom - 2, cameraZoom + 2, pixelRatio
  );
}
 
Example #11
Source Project: mapbox-plugins-android   Author: mapbox   File: LineManagerTest.java    License: BSD 2-Clause "Simplified" License 6 votes vote down vote up
@Test
public void addLines() {
  lineManager = new LineManager(mapView, mapboxMap, style, coreElementProvider, null, null, draggableAnnotationController);
  List<List<LatLng>> latLngList = new ArrayList<>();
  latLngList.add(new ArrayList<LatLng>() {{
    add(new LatLng(2, 2));
    add(new LatLng(2, 3));
  }});
  latLngList.add(new ArrayList<LatLng>() {{
    add(new LatLng(1, 1));
    add(new LatLng(2, 3));
  }});
  List<LineOptions> options = new ArrayList<>();
  for (List<LatLng> latLngs : latLngList) {
    options.add(new LineOptions().withLatLngs(latLngs));
  }
  List<Line> lines = lineManager.create(options);
  assertTrue("Returned value size should match", lines.size() == 2);
  assertTrue("Annotations size should match", lineManager.getAnnotations().size() == 2);
}
 
Example #12
Source Project: AirMapSDK-Android   Author: airmap   File: PolygonContainer.java    License: Apache License 2.0 6 votes vote down vote up
public LatLng[] getNeighborPoints(LatLng point) {
    LatLng closestPoint = getClosestPointOrMidpoint(point);
    int index = path.indexOf(closestPoint);

    // midpoint
    if (index == -1) {
        index = midpoints.indexOf(closestPoint);
        if (index == 0) {
            return new LatLng[]{path.get(0), path.get(1)};
        } else {
            return new LatLng[]{path.get(index), path.get(index + 1)};
        }

    // point
    } else {
        if (index == 0) {
            return new LatLng[]{path.get(path.size() - 2), path.get(index + 1)};
        } else if (index == path.size() - 2) {
            return new LatLng[]{path.get(index - 1), path.get(index + 1)};
        } else {
            return new LatLng[]{path.get(index - 1), path.get(index + 1)};
        }
    }
}
 
Example #13
Source Project: AirMapSDK-Android   Author: airmap   File: PolygonContainer.java    License: Apache License 2.0 6 votes vote down vote up
public boolean checkForIntersections() {
    List<LatLng> points = PointMath.findIntersections(path);
    if (points.isEmpty()) {
        return false;
    }

    List<Point> intersections = latLngsToPositions(points);
    if (map.getStyle().getLayer(INTERSECTION_LAYER) == null) {
        Source intersectionSource = new GeoJsonSource(INTERSECTION_SOURCE, Feature.fromGeometry(MultiPoint.fromLngLats(intersections)));
        map.getStyle().addSource(intersectionSource);
        Layer intersectionLayer = new SymbolLayer(INTERSECTION_LAYER, INTERSECTION_SOURCE)
                .withProperties(PropertyFactory.iconImage(INTERSECTION_IMAGE));
        map.getStyle().addLayer(intersectionLayer);
    } else {
        GeoJsonSource intersectionsSource = map.getStyle().getSourceAs(INTERSECTION_SOURCE);
        intersectionsSource.setGeoJson(Feature.fromGeometry(MultiPoint.fromLngLats(intersections)));
    }

    return true;
}
 
Example #14
Source Project: AirMapSDK-Android   Author: airmap   File: PolygonContainer.java    License: Apache License 2.0 6 votes vote down vote up
private LatLng getClosestPointOrMidpoint(LatLng latLng) {
    double shortestDistance = Double.MAX_VALUE;
    LatLng closestPoint = null;

    List<LatLng> allPoints = new ArrayList<>(path);
    allPoints.addAll(midpoints);
    for (LatLng pathPoint : allPoints) {
        double dist = latLng.distanceTo(pathPoint);
        if (closestPoint == null || dist < shortestDistance) {
            closestPoint = pathPoint;
            shortestDistance = dist;
        }
    }

    return closestPoint;
}
 
Example #15
Source Project: AirMapSDK-Android   Author: airmap   File: CircleContainer.java    License: Apache License 2.0 6 votes vote down vote up
public void move(LatLng center) {
    this.center = center;
    this.points = calculateCirclePoints(center, radius);

    List<Point> positions = latLngsToPositions(points);
    List<List<Point>> coordinates = new ArrayList<>();
    coordinates.add(positions);

    List<Point> lineString = new ArrayList<>(positions);
    lineString.add(positions.get(0));

    GeoJsonSource pointSource = map.getStyle().getSourceAs(POINT_SOURCE);
    pointSource.setGeoJson(Feature.fromGeometry(Point.fromLngLat(center.getLongitude(), center.getLatitude())));

    GeoJsonSource polygonSource = map.getStyle().getSourceAs(POLYGON_SOURCE);
    polygonSource.setGeoJson(Feature.fromGeometry(Polygon.fromLngLats(coordinates)));

    FillLayer polygonFill = map.getStyle().getLayerAs(Container.POLYGON_LAYER);
    polygonFill.setProperties(PropertyFactory.fillColor(ContextCompat.getColor(context, R.color.colorAccent)));

    GeoJsonSource polylineSource = map.getStyle().getSourceAs(POLYLINE_SOURCE);
    polylineSource.setGeoJson(Feature.fromGeometry(LineString.fromLngLats(lineString)));
}
 
Example #16
Source Project: android   Author: prkng   File: CityBoundsHelper.java    License: MIT License 5 votes vote down vote up
public static boolean isValidLocation(Context context, Location location) {
    if (location == null) {
        return false;
    }

    final LatLng latLng = new LatLng(location.getLatitude(),
            location.getLongitude());

    return CityBoundsHelper
            .getNearestCity(context, latLng)
            .containsInRadius(latLng);
}
 
Example #17
Source Project: graphhopper-navigation-android   Author: graphhopper   File: NavigationCamera.java    License: MIT License 5 votes vote down vote up
private LatLngBounds convertRoutePointsToLatLngBounds(List<Point> routePoints) {
  List<LatLng> latLngs = new ArrayList<>();
  for (Point routePoint : routePoints) {
    latLngs.add(new LatLng(routePoint.latitude(), routePoint.longitude()));
  }
  return new LatLngBounds.Builder()
    .includes(latLngs)
    .build();
}
 
Example #18
Source Project: mapbox-plugins-android   Author: mapbox   File: SymbolManagerTest.java    License: BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Test
public void testTextHaloBlurLayerProperty() {
  symbolManager = new SymbolManager(mapView, mapboxMap, style, coreElementProvider, null, null, draggableAnnotationController);
  verify(symbolLayer, times(0)).setProperties(argThat(new PropertyValueMatcher(textHaloBlur(get("text-halo-blur")))));

  SymbolOptions options = new SymbolOptions().withLatLng(new LatLng()).withTextHaloBlur(0.3f);
  symbolManager.create(options);
  verify(symbolLayer, times(1)).setProperties(argThat(new PropertyValueMatcher(textHaloBlur(get("text-halo-blur")))));

  symbolManager.create(options);
  verify(symbolLayer, times(1)).setProperties(argThat(new PropertyValueMatcher(textHaloBlur(get("text-halo-blur")))));
}
 
Example #19
Source Project: graphhopper-navigation-android   Author: graphhopper   File: RerouteActivity.java    License: MIT License 5 votes vote down vote up
@Override
public void onMapClick(@NonNull LatLng point) {
  if (!running || mapboxMap == null) {
    return;
  }

  mapboxMap.addMarker(new MarkerOptions().position(point));
  mapboxMap.setOnMapClickListener(null);

  Point newDestination = Point.fromLngLat(point.getLongitude(), point.getLatitude());
  mockLocationEngine.moveTo(newDestination);
  destination = Point.fromLngLat(point.getLongitude(), point.getLatitude());
  tracking = false;
}
 
Example #20
Source Project: graphhopper-navigation-android   Author: graphhopper   File: RerouteActivity.java    License: MIT License 5 votes vote down vote up
@Override
public void onProgressChange(Location location, RouteProgress routeProgress) {
  if (tracking) {
    locationLayerPlugin.forceLocationUpdate(location);
    CameraPosition cameraPosition = new CameraPosition.Builder()
      .zoom(15)
      .target(new LatLng(location.getLatitude(), location.getLongitude()))
      .bearing(location.getBearing())
      .build();
    mapboxMap.animateCamera(CameraUpdateFactory.newCameraPosition(cameraPosition), 2000);
  }
  instructionView.update(routeProgress);
}
 
Example #21
Source Project: mapbox-plugins-android   Author: mapbox   File: SymbolManagerTest.java    License: BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Test
public void testIconHaloBlurLayerProperty() {
  symbolManager = new SymbolManager(mapView, mapboxMap, style, coreElementProvider, null, null, draggableAnnotationController);
  verify(symbolLayer, times(0)).setProperties(argThat(new PropertyValueMatcher(iconHaloBlur(get("icon-halo-blur")))));

  SymbolOptions options = new SymbolOptions().withLatLng(new LatLng()).withIconHaloBlur(0.3f);
  symbolManager.create(options);
  verify(symbolLayer, times(1)).setProperties(argThat(new PropertyValueMatcher(iconHaloBlur(get("icon-halo-blur")))));

  symbolManager.create(options);
  verify(symbolLayer, times(1)).setProperties(argThat(new PropertyValueMatcher(iconHaloBlur(get("icon-halo-blur")))));
}
 
Example #22
Source Project: mapbox-plugins-android   Author: mapbox   File: LineManagerTest.java    License: BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Test
public void testLineDraggableFlag() {
  lineManager = new LineManager(mapView, mapboxMap, style, coreElementProvider, null, null, draggableAnnotationController);
  List<LatLng>latLngs = new ArrayList<>();
  latLngs.add(new LatLng());
  latLngs.add(new LatLng(1,1));
  Line lineZero = lineManager.create(new LineOptions().withLatLngs(latLngs));

  assertFalse(lineZero.isDraggable());
  lineZero.setDraggable(true);
  assertTrue(lineZero.isDraggable());
  lineZero.setDraggable(false);
  assertFalse(lineZero.isDraggable());
}
 
Example #23
Source Project: mapbox-plugins-android   Author: mapbox   File: CircleManagerTest.java    License: BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Test
public void testClearAll() {
  circleManager = new CircleManager(mapView, mapboxMap, style, coreElementProvider, null, null, draggableAnnotationController);
  CircleOptions options = new CircleOptions().withLatLng(new LatLng());
  circleManager.create(options);
  assertEquals(1, circleManager.getAnnotations().size());
  circleManager.deleteAll();
  assertEquals(0, circleManager.getAnnotations().size());
}
 
Example #24
Source Project: mapbox-plugins-android   Author: mapbox   File: SymbolManagerTest.java    License: BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Test
public void testIconOpacityLayerProperty() {
  symbolManager = new SymbolManager(mapView, mapboxMap, style, coreElementProvider, null, null, draggableAnnotationController);
  verify(symbolLayer, times(0)).setProperties(argThat(new PropertyValueMatcher(iconOpacity(get("icon-opacity")))));

  SymbolOptions options = new SymbolOptions().withLatLng(new LatLng()).withIconOpacity(0.3f);
  symbolManager.create(options);
  verify(symbolLayer, times(1)).setProperties(argThat(new PropertyValueMatcher(iconOpacity(get("icon-opacity")))));

  symbolManager.create(options);
  verify(symbolLayer, times(1)).setProperties(argThat(new PropertyValueMatcher(iconOpacity(get("icon-opacity")))));
}
 
Example #25
Source Project: mapbox-plugins-android   Author: mapbox   File: FillManagerTest.java    License: BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Test
public void testAddFill() {
  fillManager = new FillManager(mapView, mapboxMap, style, coreElementProvider, null, null, draggableAnnotationController);
  List<LatLng>innerLatLngs = new ArrayList<>();
  innerLatLngs.add(new LatLng());
  innerLatLngs.add(new LatLng(1,1));
  innerLatLngs.add(new LatLng(-1,-1));
  innerLatLngs.add(new LatLng());
  List<List<LatLng>>latLngs = new ArrayList<>();
  latLngs.add(innerLatLngs);
  Fill fill = fillManager.create(new FillOptions().withLatLngs(latLngs));
  assertEquals(fillManager.getAnnotations().get(0), fill);
}
 
Example #26
Source Project: graphhopper-navigation-android   Author: graphhopper   File: NavigationLauncherActivity.java    License: MIT License 5 votes vote down vote up
private void onLocationFound(Location location) {
  if (!locationFound) {
    animateCamera(new LatLng(location.getLatitude(), location.getLongitude()));
    Snackbar.make(mapView, R.string.explanation_long_press_waypoint, Snackbar.LENGTH_LONG).show();
    locationFound = true;
    hideLoading();
  }
}
 
Example #27
Source Project: mapbox-plugins-android   Author: mapbox   File: SymbolManagerTest.java    License: BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Test
public void testGeometrySymbol() {
  symbolManager = new SymbolManager(mapView, mapboxMap, style, coreElementProvider, null, null, draggableAnnotationController);
  LatLng latLng = new LatLng(12, 34);
  SymbolOptions options = new SymbolOptions().withLatLng(latLng);
  Symbol symbol = symbolManager.create(options);
  assertEquals(options.getLatLng(), latLng);
  assertEquals(symbol.getLatLng(), latLng);
  assertEquals(options.getGeometry(), Point.fromLngLat(34, 12));
  assertEquals(symbol.getGeometry(), Point.fromLngLat(34, 12));
}
 
Example #28
Source Project: mapbox-plugins-android   Author: mapbox   File: SymbolManagerTest.java    License: BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Test
public void testDeleteSymbol() {
  symbolManager = new SymbolManager(mapView, mapboxMap, style, coreElementProvider, null, null, draggableAnnotationController);
  Symbol symbol = symbolManager.create(new SymbolOptions().withLatLng(new LatLng()));
  symbolManager.delete(symbol);
  assertTrue(symbolManager.getAnnotations().size() == 0);
}
 
Example #29
Source Project: graphhopper-navigation-android   Author: graphhopper   File: NavigationLauncherActivity.java    License: MIT License 5 votes vote down vote up
private void setCurrentMarkerPosition(LatLng position) {
  if (position != null) {
    if (currentMarker == null) {
      MarkerViewOptions markerViewOptions = new MarkerViewOptions()
        .position(position);
      currentMarker = mapboxMap.addMarker(markerViewOptions);
    } else {
      currentMarker.setPosition(position);
    }
  }
}
 
Example #30
Source Project: WhereAreTheEyes   Author: DaylightingSociety   File: DownloadPinsTask.java    License: BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private void renderPins(final PinData p) {
    // Note: Use a LinkedList here so we don't need contiguous memory
    // We were having some interesting memory problems with an ArrayList.
    final LinkedList<MarkerOptions> markers = new LinkedList<MarkerOptions>();

    Iterator it = p.pins.entrySet().iterator();
    while( it.hasNext() ) {
        Map.Entry pair = (Map.Entry)it.next();
        final MarkerOptions marker = new MarkerOptions().position((LatLng)pair.getKey());
        marker.title(p.map.getContext().getString(R.string.confirmations) + ": " + Integer.valueOf((int)pair.getValue()).toString());
        marker.icon(Images.getCameraIcon());
        marker.snippet("This is a camera.");
        markers.add(marker);
    }
    if( markers.size() != 0 ) {
        Log.d("GPS", "Trying to render pins: " + Integer.toString(markers.size()));

        Runnable clearPins = new Runnable() {
            public void run() {
                p.map.getMapAsync(new OnMapReadyCallback() {
                    @Override
                    public void onMapReady(MapboxMap mapboxMap) {
                        // We don't want to layer cameras on top
                        mapboxMap.removeAnnotations();
                        mapboxMap.addMarkers(markers);
                        Log.d("GPS", "Pins now on map: " + Integer.toString(mapboxMap.getAnnotations().size()));
                    }
                });
            }
        };

        // Note: Pins *must* be cleared on the main thread.
        // This is because if a UI window (like the pin detail screen) is currently open
        // then only the thread that created it can destroy it. If we delete the pins from
        // the background while a UI window for the pin is open it crashes the app.
        Handler mainThread = new Handler(Looper.getMainLooper());
        mainThread.post(clearPins);
    }
}