Background to this query:
I have a need to display small labels on an offline map backed by a tpk, the data for which is generated at runtime. These labels are each associated with their own GPS coordinate, and require the drawing of text and some border or background to provide contrast against the map behind it.
Considered solutions to the overall problem:
- A border directly on the text in TextSymbol - not supported, and without an arrow of some kind provides a poor association between the text and the actual location
- Callouts - only a single callout is supported, which therefore does not meet requirements
- CalloutPopupWindow - deprecated with no alternative offered, and poorly tracks the associated location when the map is panning anyway (very jittery).
- Android View located over MapView - poorly tracks associated locations when map is panning (very jittery)
- Polygon in screen coordinates around a TextSymbol with an arrow (roughly mimicing a callout) - tracks associated locations well, but scales badly when zoom changes as unlike the text in TextSymbol the polygon size must be specified in GPS coordinates and there is no facility to keep geometries agnostic of zoom level.
Of these, the last has seemed the best compromise, but this does mean that zooming in and out has to be handled differently to avoid the outer polygon being at the wrong scale relative to the text. The best approach found so far is to clear all labels at the start of a zoom and re-instate them once zoom completes. This would work fine if not for the following issues.
The current problems with the solution so far:
- OnZoomListener.postAction does not fire reliably at the end of a series of zoom actions, particularly if zoom is triggered during an existing zoom animation.
- This can be somewhat mitigated by overriding the zoomin/out methods on MapView to chain zooms together in sequence, requiring that postAction is fired before triggering the next zoom to commence. However, there is no mechanism to hook into the handling of zoom gestures, and so ultimately it is still possible to trigger a sequence of programmatic zoomin/zoomout events in addition to zooming with gestures which will result in a zoom without an associated postAction firing - giving no opportunity to fix the Polygon geometry. (This approach is still unreliable)
- OnPanListener does not provide any mechanism to tell when panning actually ends, from what I can see this listener instead reports user interaction with the MapView equivalent of a GestureOverlayView. This is not sufficient, as the fling gesture does not finish panning until some time after user interaction completes and the postPointerUp event has already fired.
- As far as I can tell there is no mechanism to hook into the standard gesture handling without having to re-write it from scratch, noting that MapGestureDetector is deprecated. (See update regarding MapOnTouchListener below)
- How should developers display custom metadata on offline maps at runtime for multiple features simultaneously, in a way which is easily readable regardless of the colour of the map beneath it?
- Is there currently a mechanism for hooking into the handling of gestures without requiring custom handling for all gestures?
- Is there intention to add reliable events for zoom/pan which consistently fire when zoom/pan is actioned and completes, no matter whether the action is triggered programatically, by normal user interaction, or by extended handling of gestures?
- Is there intention to support adding geometries to the map which are relative to screen coordinates, as per the zoom behaviour of TextSymbol?
- Is there intention to allow individual gestures to be enabled/disabled? (this is currently possible for the one-finger zoom but nothing else)
- Is there intention to fix repeated zoomIn/zoomOut events changing the map centring?
P.S. these difficulties were found whilst using ArcGIS for Android 10.2.4, the release notes for 10.2.5 do not suggest any relevant changes.
I have since found MapOnTouchListener, which is not deprecated and subclassing provides a lot of the gesture control I was looking for
Message edited by: Robert Bares, updated to include MapOnTouchListener, strikethrough added for details which have been resolved by this