Search code examples
javaandroidosmdroidosmbonuspack

Add Custom Control as Marker OSMDROID BONUS PACK


Can I add Custom Control as Marker to OSMBONUSPACK?

I create some Buttons and image in Android xml file Named MyMarkerItem.xml

I would like something like MyMarker.setDesign(R.layout.MyMarkerItem);

Thanks


Solution

  • OK, I understand that you want the marker icon itself to be not a simple bitmap, but a layout.

    What you can do is to use the marker infowindow "instead" of the marker icon.

    First of all, create a new class CustomInfoWindow which inherits from MarkerInfoWindow - the default InfoWindow for Markers, and uses your own layout:

    public class CustomInfoWindow extends MarkerInfoWindow {
        public CustomInfoWindow(MapView mapView) {
            super(my_own_layout, mapView);
        }
    }
    
    CustomInfoWindow myCustomInfoWindow = new CustomInfoWindow(mapView);
    

    Then, just after creating your Marker, do that:

    • Set a marker icon as a 1x1 pixel size bitmap, fully transparent: setIcon(mySmall_InvisibleIcon)
    • Set the marker infowindow to your own: setInfoWindow(myCustomInfoWindow)
    • Set the infowindow "anchor" to the most appropriate and natural position, depending on the "look" of your layout: setInfoWindowAnchor(ANCHOR_CENTER, ANCHOR_CENTER) maybe?
    • Force the opening of the infowindow: showInfoWindow()

    All these steps are fairly simple.

    But then, I guess you expect some behaviour to happen when the user will click on your layout buttons. So, inside your CustomInfoWindow code, you will certainly have to do some work => follow this tutorial.