How to enable clustering feature using custom view annotation on mapbox android? - android

i have a trouble about enable clustering feature on mapbox v10 android.
I have tried to reseach on homepage but didn't find any helpful way to resolve this.
I used to create point annotation manager from AnnotationPlugin before then i can add annotationConfig into them but now i must create custom view instead.
So i don't know how to add clustering for that
Here is way to add custom annotation view into mapview.
val point = fromLngLat(
longitude,
latitude
)
val view = mMapView.viewAnnotationManager.addViewAnnotation(
R.layout.custom_layout,
viewAnnotationOptions {
geometry(point)
allowOverlap(true)
}
)
Anyone help me please? Thanks

Related

Mapbox: How to correct Line overlapping over a Symbol

I'm using the SymbolManager to display two symbols on the map. Here is an example:
The dark symbol is because of the fact that I'm testing the project on the Emulator, but the Line goes under the symbol, as it should be. The problem comes with the other symbol (finish flag). After I'm ready with the drawing of the line, the following code block is called:
symbolManager = new SymbolManager(mapView,mMapboxMap,style);
symbolManager.setIconAllowOverlap(true);
symbolManager.setIconIgnorePlacement(true);
SymbolOptions symbolOptionsFinishFlag = new SymbolOptions()
.withIconImage(IMAGE_FINISH_FLAG)
.withIconSize(2.0f)
.withLatLng(newLatLngs.get(newLatLngs.size()-1));
symbolManager.create(symbolOptionsFinishFlag);
LatLngBounds.Builder builder = new LatLngBounds.Builder();
builder.includes(newLatLngs);
LatLngBounds bounds = builder.build();
final CameraUpdate cu = new CameraUpdateFactory().newLatLngBounds(bounds,300);
mMapboxMap.easeCamera(cu,5000);
I checked some examples in the Mapbox site and it seems to be correct. However, the Symbol is under the Line, how can I bring on top of it?
If you are using a LineLayer, when adding it to the map use style.addLayerBelow(lineLayer, symbolManager.layerId)
This answer is about how to do this in Mapbox SDK v9. All AnnotationManager subclasses have a constructor which allows you to mention which layerId this should be below.
For example, in LineManager, we have this constructor
LineManager(MapView mapView, MapboxMap mapboxMap, Style style, java.lang.String belowLayerId)
Another method which will be needed here is the getLayerId method in the AnnotationManager class which returns the id used by a certain layer.
getLayerId
public java.lang.String getLayerId()
Returns a layer ID that annotations created by this manager are laid out on. This reference can be used together with Style#addLayerAbove(Layer, String) or Style#addLayerBelow(Layer, String) to improve other layers positioning in relation to this manager.
Returns:
underlying layer's ID
So say there are 3 elements on the map, a circle, a line and a symbol and we need to show the circle at the bottom, then the line above and finally the symbol at the top most.
So we will create our AnnotationManagers in this way -
val symbolManager = SymbolManager(mapView, map, map.style!!)
val lineManager = LineManager(mapView, map, map.style!!, symbolManager.layerId)
val fillManager = FillManager(mapView, map, map.style!!, lineManager.layerId)
What we're doing here is that while creating the lineManager object, we pass the layerId of the symbolManager which ensures that the Lines created using LineManager are always below the Symbols created using the SymbolManager. And the same for FillManager being below the lineManager object.
Although SymbolManagers can be useful means for providing an abstraction over the methods needed to add symbols to a map, you may get some more flexibility by working with native SymbolLayers directly. This example shows how to add symbol layer icons to a map, and this example shows how to specify layer ordering when new layers are added. So, by adding two symbol layers for your start and finish icons, and a line layer for the line between them, you could use style.addLayerBelow(finishFlagLayer, "name_of_line_layer").

Get Google Maps Navigation Instructions

I'm looking for a way to get the instructions from Maps Navigation.
Currently I think the only possible way is to read the notification data that is placed at the top by Maps Navigation. My reason for beleving that this is the only way comes from this post.
I tried getting the data with the OnNotificationPosted method, but i cant find directions data in the StatusBarNotification object...
Does anyone have a solution or better idea on how to achieve this
You can implement a NotificationListenerService in order to retrieve the content of google maps route direction. Unfortunately Maps is not using the common attributes within the StatusBarNotification. However maps uses RemoteViews to display content.
You can send this data via Broadcast to the activity and eventually add the content to an existing view:
RemoteViews remoteView = intent.getParcelableExtra(id);
if (remoteView != null) {
ViewGroup frame = (ViewGroup) findViewById(R.id.layout_navi);
frame.removeAllViews();
View newView = remoteView.apply(getApplicationContext(), frame);
newView.setBackgroundColor(Color.TRANSPARENT);
frame.addView(newView);
}

How to implement first person view in android google map?

In my android application i want to implement first person view. Please check following URL for first person View -
Google First Person View
I found one link which redirects to first person view please check -
Google Maps Navigation - Using Google Navigation in Android Application
But in it we don't have control over navigation view or first person view. It redirects to google's default first person view. I want to implement it manually. Means in which we can pass latitude and longitude dynamically(from Server)
Is there any way to implement first person view Pro-grammatically, in which we have command over view ?
Thanks in advance!
Don't know exactly, how to achieve that view, but you can do one thing, that is whatever orientation's value you are getting from your server or any gps device , pass it into bearing() method of CameraPosition and set tilt also, like following -
CameraPosition cameraPos = new CameraPosition.Builder().target(latlng)
.zoom(zoomvalue).bearing(orientation).tilt(tiltvalue).build();
googleMap.animateCamera(CameraUpdateFactory.newCameraPosition(cameraPos), null);
by doing this your map will be rotate according to value of orientation. and if you pass value of orientation into rotation(orientation) method of marker then your marker will rotate according to value.
Hope it'll help you.

How to set my own icon for markers in clusterer in Google Maps

I'm using GoogleMaps clustering. I have 4 different types of markers, each extends from one abstract class, each has its owm icon and it defined in MarkerOptions field. I use ClusterManager for this abstract class.
When I just use
//marker is instance of one of extended classes and has abstract class type
clusterManager.addItem(marker);
After clustering it sets icon to default. How I can fix this? I was trying to use something like this:
//marker is abstract marker, getMarker returns the MarkerOptions of this marker
clusterManager.getMarkerCollection().addMarker(marker.getMarker());
but it doesn't work too, marker is printed with needed icon on map, but without clustering.
Should I create create some method in my abstract class or there are some way to do this extending from DefaultClusterRenderer? I haven't found some information about it using Google or learning google maps lib.
Thanks for helping!
So, it was my foolish. Again, it shows, that I should pay more attention, studying library. If somebody is interested in answer, here it is:
I was right supposing, that I need to override some method in DefaultClusterRenderer. So, the full way:
Create own class and extend it from DefaultClusterRenderer:
public class OwnIconRendered extends DefaultClusterRenderer<AbstractMarker>
Then override method onBeforeClusterItemRendered:
#Override
protected void onBeforeClusterItemRendered(AbstractMarker item,
MarkerOptions markerOptions) {
markerOptions.icon(item.getMarker().getIcon());
}
The way is rather simple, but it seems to me, that clustering started to work slower. So, that's enough.

Implementing a chart with AFreeChart into a View

Here is my problem: I am using AFreeChart to display a chart in my activity. The reason why I used AFreeChart was because I first finished this chart with JFreeChart, and, realized after that, it wasn't compatible with Android.
So, with AFreeChart, I could create the same chart with exactly the same code, but I don't know how to display it on a View.
Here I am creating the chart:
private void creerGraphique(){
//Here I have the creation of the DateSet
AFreeChart chart = ChartFactory.createXYLineChart(
"Mois", // Title
"Jours", // x-axis Label
"Repetitions", // y-axis Label
graph, // Dataset
PlotOrientation.VERTICAL, // Plot Orientation
true, // Show Legend
true, // Use tooltips
false // Configure chart to generate URLs?
);
}
Here I want to use it:
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.graphique);
this.stockTableau();
this.creerGraphique();
//HERE: How can I display it since it's already created
}
I downloaded the AFreeChart demo code, but a function which wasn't on the package was used, and so, I couldn't use it too.
I thank you for your help.
PS: I'm not an english, so I hope my problem is clear, do not hesitate to ask me more details.
Have you looked at the sample in AFreeChart? It's quite straight forward, look at what they did for this chart for instance :
http://code.google.com/p/afreechart/source/browse/trunk/afreechart_sample/src/org/afree/chart/demo/view/PieChartDemo01View.java
They extend a DemoView which is basically an Android View with a setChart method, and pass the chart to the View.
So either extend DemoView or create you own equivalent if you don't need everything that's in it and follow the sample !
Good luck.
It is also worth noting that using the code you've pasted above, it would be helpful to call the chart's draw() method when you want it to draw.
As a simple example, if you were using a SurfaceView, you could create a method something like the following:
private void drawChart(AFreeChart chart, ChartRenderingInfo info) {
getHolder.lockCanvas();
chart.draw(canvas, area, info);
getHolder().unlockCanvasAndPost(canvas);
}
Where 'canvas' and 'area' have been set.
This is useful if you are looking to do a very simple implementation where you don't want to use the DemoView discussed above.

Categories

Resources