I have balloon popups showing in Android MapView when a user tap:s on specific points on the map. Depending on where the user taps the balloon does not always fit insize the MapView. I solve this now by using MapController.animateTo to always have the tapped point in center. However, this is not the way I prefer it to be. I would like to animate the MapView only so much that the balloon layout fits inside MapView.
Any tips on how this can be solved?
One way to fit the balloon overlay is to override the dispatchDraw method, check the bounds of the display using getMeasuredWidth and getMeasuredHeight, and, draw the balloon such that it fits within the display area.
I am not sure if you have seen the Android MapView Balloons project on github. I have been using this code for a while and it is excellent, may be you can find some pointers to your problem from there.
Hope this helps.
Related
Building custom overlay specifically circle with radius(colored) in Android MapBox GL. It allows to change radius dynamically using seekbar.
I'm trying to build some custom markers and I used SimpleCircleView but Im having problem trying to display it in MapBox GL android, and it created lots of bugs.
The map touch event is unresponsive once my CircleOverlay is displayed in map
The marker doesnt stay in its coordinates once i zoom-in , zoom-out.
Updating markers doesnt work, So I have to remove then add again the marker.
The color does not match the color that I set in marker.
I'll limit my posting on code, because this repo is mine and to keep the problem understandable.
In building custom overlay I have to make these classes:
CircleMarkerView.java - The Custom Marker View
[CircleMarkerViewOptions.java] (https://github.com/spurdow/SimpleCircleView/blob/master/app/src/main/java/com/spurdow/circleviewtest/CircleMarkerViewOptions.java) - This is to be used with CircleMarkerView
SimpleCircleView.java - This is my custom view for dynamic circle changing its radius etc.
MainActivityMapBox - This is where to put it all
This is an example of the code in the repo.
Does anybody have any idea how to do this simply?
Or
Is there another way of building an overlay dynamically?
Or
Is it possible to create a circle bitmap dynamically and convert it to icon when seekbar's progress is changing?
1. The map touch event is unresponsive once my CircleOverlay is displayed in map
This is an issue we plan to address by next release, you can follow progress on this here.
2. The marker doesnt stay in its coordinates once i zoom-in , zoom-out.
The could be because you aren't anchoring the marker icon correctly using .setAnchor() or your icon has padding around it. For a circle, you'll want to anchor centered (using 0.5f). A bug was introduced right before the previous stable release that causes anchoring not to work correctly. If this is an issue, use the 4.2.0-SNAPSHOT.
3. Updating markers doesnt work, So I have to remove then add again the marker.
Could you elaborate on this issue? You might be using
Marker marker = mapboxMap.addMarker(new MarkerViewOptions()...
When you should be using:
MarkerView marker = mapboxMap.addMarker(new MarkerViewOptions()...
Which will give you more options to update markers.
4. The color does not match the color that I set in marker.
Could you clarify what you mean by this?
It sounds like you are wanting to do what this example does in the testapp? I would follow along with the code found there.
I have a particular need with a mapView and i can't find any good solution.
I have a Mapview with some markers displayed on it, and it works perfectly.
My need is that i want to put a kind of layer/background on the screen, in order to "mask" the map, but i always want to see the markers, and keep all the mapview functionnalities (zoom, move, etc.)
Is there any solution available to do it?
I hope you understand my need.
Many thanks in advance.
Create an overlay that mask (cover) the part of the map that you want to cover. In the onDraw() of this oevrlay just draw something that achive your mask requirements (areas, colors and opacity).
To ensure that markers are always visible, you need to add the overlay with markers after you add the overlay that mask map to the mapView.getOverlays.add().
Enjoy it.
Android: I am using a mapview and ItemizedOverlay. I am ploting a drawable on that, it does not shows correct place. It shows correct position on map when full zoom in but when it is zoom out the marker is moving from correct position.
Can any one know the solution. Should I need to do something in draw of ItemizedOverlay.?
Does anyone knows the solution. Please help me.
regards,
dharma
I'm developing an application in which i have to show a map with the aim on it. just like it is on the picture. When a user drags map with a finger, map is moving and the aim isn't. I can make a translucent layout over the map, but can't understand how to draw a transparent circle. Please give me some ideas. Thanks!
I suppose it depends how you're drawing the translucent overlay, but if you were using Canvas methods, you can try with the clip methods to intersect with a path. http://developer.android.com/reference/android/graphics/Canvas.html#clipPath(android.graphics.Path)
I have faced some problems with the Android MapView API. I get OverlayItems from a database which I want to display in a MapView. If I'm displaying 100 Icons, I have no issues, but if it gets more - like 500 Items in one City - it first looks really bad, while second it slows down a lot. Unfortunately my goal is to display 10000 of them. I think one solution can be to register a listener to ZoomLevels to make them appear/dissapear, but I couldn't find that functionality. Second, I couldn't find a function to scale my Overlays with the Zoom of the Map.
Any Ideas are very welcome
There is a very strange behavior in ItemizedOverlay draw method. When you say: Draw line from (x,y) to (x1,y1) the draw method is called about 20-30-40 times - i don't know why. It is acceptable when you draw one line, but when you draw a thousands of lines,icons and so on...it is very very bad! To solve this problem you should create a cached overlay. This is overlay that catches the first draw, creates the object and then prevents the future draws that do the same draw.
A cluster is a dozen of icons behind one icon. For example if you have 1000 markers on the map, in a specific minimal zoom level you can not see each marker separately - it becomes a mess of icons and colors and so on. And instead of 100 markers that are very very close one by one you place a cluster marker. And on zoom in remove this cluster and create another clusters...do this until the markers became far enough away and you can seen them divided.
Check this: Cluster markers
Take the following approaches:
Create a cached overlay to prevent multiple drawing of same clusters;
Draw in thread;
Cluster your markers depending on zoom level and marker proximity.
Each time you draw in the overlay, check for sure is the current marker inside of the visible part of the screen. If it is not, do no draw it!
I had a similar problem with the icon size and zoom level in my application. What I ended up doing was having 2 sets of overlays containing the markers, one with a "zoomed in" icon and one with a "zoomed out" icon. Then just changed the overlay at a certain zoom level (using a zoom poller - On zoom event for google maps on android)