Issue
I have inserted a map in my android app using osmdroid, over which I lay out ~10K pins. I want each pin to have an icon (same icon for all pins). I know how to do it for a single icon with Marker class.
I am using SimpleFastPointOverlay in order to optimize drawing so many pins on the map. I could not figure out how to set an icon to the theme of the points.
Relevant code:
// wrap points in a theme
SimplePointTheme pointThm = new SimplePointTheme(points, true);
// >>>>>> THIS I WANT TO REPLACE WITH AN ICON
Paint textStyle = new Paint();
textStyle.setStyle(Paint.Style.FILL);
textStyle.setColor(Color.parseColor("#0000ff"));
textStyle.setTextAlign(Paint.Align.CENTER);
textStyle.setTextSize(24);
SimpleFastPointOverlayOptions opts = SimpleFastPointOverlayOptions.getDefaultStyle()
.setAlgorithm(SimpleFastPointOverlayOptions.RenderingAlgorithm.MEDIUM_OPTIMIZATION)
.setRadius(7).setIsClickable(true).setCellSize(15).setTextStyle(textStyle);
// create the overlay with the theme
final SimpleFastPointOverlay fastOverlay = new SimpleFastPointOverlay(pointThm, opts);
mapView.getOverlays().add(fastOverlay);
How can I set the icon?
Solution
That's unfortunately not possible with SimpleFastPointOverlay. It supports only simple shapes: circle or rectangle.
I see following two options, if you really need icons:
- Preferred: Try ItemizedIconOverlay with OverlayItem instances.
OverlayItem
is more lightweight thanMarker
. TheItemizedIconOverlay
class also have a default marker (drawable) parameter in its constructor, so you don't need to set drawable to eachOverlayItem
instance. - Create a custom subclass of the
SimpleFastPointOverlay
class and override itsdrawPointAt
method and implement rendering as you wish. Remember to minimize allocations in order to keep good performance. Keep in mind that this is an attempt to bend the class to have other than intended behavior. It's harder to implement correctly and there will be sideeffects, e.g. broken click handling, as revealed in comments.
Answered By - Josef Adamcik
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.