How to keep the callout sticky when users move map?

522
2
01-19-2023 10:56 PM
LeoDeng
Occasional Contributor II

Hi All,

   The SDK version is  100.15.0

   I create a point graphic with callout on the mapview. When panning the map, the callout always has a gap between the arrow and the graphic. Is there any way to solve this issue in Android SDK ?

  Here is the code for create a callout with a point graphic.

Callout callout = _mapView.getCallout();
callout.setPassTouchEventsToMapView(false);

TextView calloutContent = new TextView(_context);
calloutContent.setTextColor(Color.BLACK);
calloutContent.setSingleLine();
// format coordinates to 4 decimal places
calloutContent.setText("Lat: " + String.format("%.4f", location.getY()) + ", Lon: " + String.format("%.4f", location.getX()));
callout.show(calloutContent, location);

  Please see the attached video for details.


Bests,
Leo

Tags (1)
0 Kudos
2 Replies
Shubham_Sharma
Esri Contributor

Hey @LeoDeng 

Using a callout probably wouldn't best choice for "perfect stickiness". I would recommend using a `TextSymbol`

graphicsOverlay?.graphics?.add(
    Graphic(
        Point(40.0, -90.0, SpatialReferences.getWgs84()),
        getTextSymbol("Lat: 40.0, Lon: -90.0")
    )
)
        
private fun getTextSymbol(text: String): TextSymbol {
    val textSymbol = TextSymbol(
        10F,
        text,
        Color.BLACK,
        TextSymbol.HorizontalAlignment.CENTER,
        TextSymbol.VerticalAlignment.MIDDLE
    )
    // give the text symbol a white background
    textSymbol.backgroundColor = Color.WHITE
    return textSymbol
}

 Check out the Render multilayer symbols Android Runtime sample, which shows different kinds of multilayer symbols on a map including rendering TextSymbols

0 Kudos
LeoDeng
Occasional Contributor II

Thank you @Shubham_Sharma .

Actually, I tried "TextSymbol" solution too. However, in this solution, I met another problem. I'm not sure if there is a solution which can solve both of the problems.

Bests,
Leo

0 Kudos