com.mapbox.mapboxsdk.annotations.Marker Java Examples
The following examples show how to use
com.mapbox.mapboxsdk.annotations.Marker.
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
Source File: CarshareInfoWindowAdapter.java From android with MIT License | 6 votes |
@Nullable @Override public View getInfoWindow(@NonNull Marker marker) { if (viewHolder == null) { this.viewHolder = new InfoWindowViewHolder(view); } final JsonSnippet snippet = JsonSnippet.fromJson(marker.getSnippet()); viewHolder.title.setText(marker.getTitle()); viewHolder.snippet.setText(getSubtitle(snippet)); final String figure = getFigure(snippet); viewHolder.figure.setVisibility(TextUtils.isEmpty(figure) ? View.GONE : View.VISIBLE); viewHolder.figure.setText(figure); return view; }
Example #2
Source File: MainMapFragment.java From android with MIT License | 5 votes |
private boolean onNearestMarkerClick(@NonNull LatLng point) { final Annotation annotation = MapUtils.getNearestAnnotation(point, vMap.getAllAnnotations()); if (annotation != null) { final double distance = MapUtils.distanceTo(point, annotation); // threshold ranges between 13-25 metres final double threshold = Const.UiConfig.MIN_CLICK_DISTANCE + 3 * (MapView.MAXIMUM_ZOOM - vMap.getZoom()); if (Double.compare(distance, threshold) < 0) { if (annotation instanceof Marker) { // Nearest is a Marker, trigger onMarkerClick() onMarkerClick((Marker) annotation); return true; } else if (annotation instanceof Polyline) { // Nearest is a Polyline, find its associated Marker for (Map.Entry<String, List<Annotation>> entry : mFeatureAnnotsList.entrySet()) { if (entry.getValue().contains(annotation)) { for (Annotation a : entry.getValue()) { if (a instanceof Marker) { onMarkerClick((Marker) a); return true; } } } } } } } return false; }
Example #3
Source File: MapUtils.java From android with MIT License | 5 votes |
public static Marker addSearchMarker(MapView mapView, LatLng latLng, Icon searchIcon) { final JsonSnippet snippet = new JsonSnippet.Builder() .search() .build(); return mapView.addMarker(new MarkerOptions() .snippet(JsonSnippet.toJson(snippet)) .position(latLng) .icon(searchIcon) ); }
Example #4
Source File: MapUtils.java From android with MIT License | 5 votes |
public static boolean removeCheckinMarker(MapView mapView) { for (Annotation annotation : mapView.getAllAnnotations()) { if (annotation instanceof Marker) { final Marker marker = (Marker) annotation; if (JsonSnippet.fromJson(marker.getSnippet()).isCheckin()) { mapView.removeMarker(marker); return true; } } } return false; }
Example #5
Source File: MapUtils.java From android with MIT License | 5 votes |
public static double distanceTo(@NonNull LatLng point, @NonNull Annotation annotation) { if (annotation instanceof Marker) { return point.distanceTo(((Marker) annotation).getPosition()); } else if (annotation instanceof Polyline) { double minDistance = Double.MAX_VALUE; for (LatLng latLng : ((Polyline) annotation).getPoints()) { minDistance = Math.min(minDistance, latLng.distanceTo(point)); } return minDistance; } return Double.MAX_VALUE; }
Example #6
Source File: MapUtils.java From android with MIT License | 5 votes |
public static MarkerOptions extractMarkerOptions(Marker marker) { final MarkerOptions options = new MarkerOptions(); if (marker != null) { options.position(marker.getPosition()) .icon(marker.getIcon()) .title(marker.getTitle()) .snippet(marker.getSnippet()); } return options; }
Example #7
Source File: MainActivity.java From android with MIT License | 5 votes |
/** * Implements MainMapFragment.OnMapMarkerClickListener * * @param marker */ @Override public void showMarkerInfo(Marker marker, int type) { if (marker == null) { hideMarkerInfo(); } else { //setMarkerInfo(marker.getSnippet(), marker.getTitle(), type) final FragmentManager fm = getSupportFragmentManager(); final FragmentTransaction ft = fm.beginTransaction(); Fragment fragment = fm.findFragmentByTag(Const.FragmentTags.MAP_INFO); if (fragment == null) { Log.v(TAG, "setCustomAnimations"); ft.setCustomAnimations(R.anim.slide_up, R.anim.slide_down); } switch (type) { case Const.MapSections.OFF_STREET: fragment = LotInfoFragment.newInstance( JsonSnippet.parseId(marker.getSnippet()), marker.getTitle(), marker.getPosition()); break; case Const.MapSections.CARSHARE_SPOTS: case Const.MapSections.ON_STREET: fragment = SpotInfoFragment.newInstance( JsonSnippet.parseId(marker.getSnippet()), marker.getTitle()); break; default: return; } ft.replace(R.id.map_info_frame, fragment, Const.FragmentTags.MAP_INFO) .commit(); } }
Example #8
Source File: MainMapFragment.java From android with MIT License | 5 votes |
/** * Implements MapView.OnMarkerClickListener * Called when the user clicks on a marker. * * @param marker * @return True, to consume the event and skip showing the infoWindow */ @Override public boolean onMarkerClick(@NonNull Marker marker) { final JsonSnippet snippet = JsonSnippet.fromJson(marker.getSnippet()); final String featureId = snippet.getId(); final String selectedId = mSelectedFeature == null ? null : mSelectedFeature.getId(); if (featureId != null && featureId.equals(selectedId)) { // Skip if re-clicked the same Feature return true; } if (snippet.isCheckin()) { startActivity(CheckinActivity.newIntent(getActivity())); return true; } else if (snippet.isSearch()) { return true; } switch (mPrkngMapType) { case Const.MapSections.ON_STREET: case Const.MapSections.OFF_STREET: case Const.MapSections.CARSHARE_SPOTS: unselectFeatureIfNecessary(); selectFeature(JsonSnippet.parseId(marker.getSnippet())); if (listener != null && !snippet.isCarshareLot()) { listener.showMarkerInfo(marker, mPrkngMapType); return true; } return false; default: return false; } }
Example #9
Source File: NavigationLauncherActivity.java From graphhopper-navigation-example with Apache License 2.0 | 5 votes |
@Override public void onMapReady(MapboxMap mapboxMap) { this.mapboxMap = mapboxMap; this.mapboxMap.getUiSettings().setAttributionDialogManager(new GHAttributionDialogManager(this.mapView.getContext(), this.mapboxMap)); this.mapboxMap.addOnMapLongClickListener(this); initMapRoute(); this.mapboxMap.setOnInfoWindowClickListener(new MapboxMap.OnInfoWindowClickListener() { @Override public boolean onInfoWindowClick(@NonNull Marker marker) { for (Marker geocodingMarker : markers) { if (geocodingMarker.getId() == marker.getId()) { LatLng position = geocodingMarker.getPosition(); addPointToRoute(position.getLatitude(), position.getLongitude()); updateRouteAfterWaypointChange(); marker.hideInfoWindow(); return true; } } return true; } }); // Check for location permission permissionsManager = new PermissionsManager(this); if (!PermissionsManager.areLocationPermissionsGranted(this)) { permissionsManager.requestLocationPermissions(this); } else { initLocationLayer(); } handleIntent(getIntent()); }
Example #10
Source File: NavigationLauncherActivity.java From graphhopper-navigation-example with Apache License 2.0 | 5 votes |
private void clearGeocodingResults() { if (markers != null) { for (Marker marker : markers) { this.mapboxMap.removeMarker(marker); } markers.clear(); } }
Example #11
Source File: NavigationMapboxMap.java From graphhopper-navigation-android with MIT License | 5 votes |
@NonNull private Marker createMarkerFromIcon(Context context, Point position) { LatLng markerPosition = new LatLng(position.latitude(), position.longitude()); Icon markerIcon = ThemeSwitcher.retrieveThemeMapMarker(context); return mapboxMap.addMarker(new MarkerOptions() .position(markerPosition) .icon(markerIcon)); }
Example #12
Source File: MainMapFragment.java From android with MIT License | 4 votes |
private void selectFeature(String featureId) { if (mFeatureAnnotsList == null) { return; } // Store the selected feature's ID, for restore mSelectedFeature = new SelectedFeature(featureId); final List<Annotation> annotations = mFeatureAnnotsList.get(featureId); if (annotations == null) { return; } // Reset the selection array mSelectedAnnotsList = new ArrayList<>(); Icon icon; switch (mPrkngMapType) { case Const.MapSections.OFF_STREET: icon = mapAssets.getLotMarkerIconSelected(Const.UNKNOWN_VALUE); break; case Const.MapSections.ON_STREET: default: icon = mapAssets.getMarkerIconSelected(); break; } for (Annotation annot : annotations) { if (annot instanceof Marker) { final Marker m = ((Marker) annot); if (!m.getIcon().getId().equals(mapAssets.getMarkerIconTransparent().getId())) { // Store the selected feature's marker Icon, for restore mSelectedFeature.setMarkerIcon(m.getIcon()); // Change the marker's Icon final Marker selectedMarker = vMap.addMarker( MapUtils.extractMarkerOptions(m) .icon(icon) ); // Add to the selection array mSelectedAnnotsList.add(selectedMarker); // Remove old marker from Map vMap.removeAnnotation(m); } else { // Store transparent buttons without any changes mSelectedAnnotsList.add(m); } } else if (annot instanceof Polyline) { final Polyline p = ((Polyline) annot); // Store the selected feature's polyline Color, for restore mSelectedFeature.setPolylineColor(p.getColor()); // Change the polyline's color final Polyline selected = vMap.addPolyline( MapUtils.extractPolylineOptions(p) .color(mapAssets.getLineColorSelected()) ); // Add to the selection array mSelectedAnnotsList.add(selected); // Remove old polyline from Map vMap.removeAnnotation(p); } } // Update the global feature-annotations reference list mFeatureAnnotsList.put(featureId, mSelectedAnnotsList); }
Example #13
Source File: MarkerWrapper.java From android with MIT License | 4 votes |
public void setMarker(Marker marker) { this.marker = marker; }
Example #14
Source File: MarkerWrapper.java From android with MIT License | 4 votes |
public Marker getMarker() { return marker; }
Example #15
Source File: NavigationMapboxMap.java From graphhopper-navigation-android with MIT License | 4 votes |
private void removeAllMarkers() { for (Marker marker : mapMarkers) { mapboxMap.removeMarker(marker); } }
Example #16
Source File: NavigationMapboxMap.java From graphhopper-navigation-android with MIT License | 2 votes |
/** * Adds a marker icon on the map at the given position. * <p> * The icon used for this method can be defined in your theme with * the attribute <tt>navigationViewDestinationMarker</tt>. * * @param context to retrieve the icon drawable from the theme * @param position the point at which the marker will be placed */ public void addMarker(Context context, Point position) { Marker marker = createMarkerFromIcon(context, position); mapMarkers.add(marker); }
Example #17
Source File: MainMapFragment.java From android with MIT License | votes |
void showMarkerInfo(Marker marker, int type);