Titanium JIRA Archive
Appcelerator Modules (MOD)

[MOD-2401] Ti.Map: Inconsistency between iOS and Android click events on Annotations

GitHub Issuen/a
TypeImprovement
PriorityMedium
StatusResolved
ResolutionFixed
Resolution Date2018-08-17T21:52:54.000+0000
Affected Version/sRelease 7.1.0
Fix Version/sTi.Map Android 4.3.1
ComponentsMap
Labelsios, parity, ti.map
ReporterRene Pot
AssigneeYordan Banev
Created2018-03-06T11:30:16.000+0000
Updated2018-08-17T21:52:54.000+0000

Description

In ti.map when selecting an annotation on the map a click event is triggered. When selecting another annotation on iOS 2 events are fired for both annotations (a deselect event, and a select event for the new one). On Android only a click event is triggered for the newly selected annotation. Some sample code
var clickedAnnotation = null;
function handleMapClick(e){
    // check if annotation was clicked
    if (e.hasOwnProperty('annotation')){
        
        // check if the annotation was selected or deselected based on previous state
        if (e.annotation.id == clickedAnnotation){
            log.args('annotation deselected', e.annotation);
            clickedAnnotation = null;
        } else {
            log.args('annotation selected', e.annotation);
            clickedAnnotation = e.annotation.id;
        }
    } else {
        if (e.clicksource == 'circle'){
            log.args('circle clicked', e.latitude, e.longitude);
        }
    }
}
    	<Module method="createView" module="ti.map" id="mapview" onClick="handleMapClick">
    		<Annotation id="amsterdam"></Annotation>
    		<Annotation id="appcHQ"></Annotation>
    	</Module>
"#mapview": {
    region: {
        latitude: 37.359996,
        longitude: -121.950208,
        latitudeDelta: 0.6,
        longitudeDelta: 0.6
    }
}

"#amsterdam": {
    latitude: 52.39,
    longitude: 4.89,
    title: "Amsterdam",
    subtitle: "This is Amsterdam!",
    pincolor: Alloy.Globals.Map.ANNOTATION_RED
}

"#appcHQ": {
    latitude: 37.368122,
    longitude: -121.913653,
    title: "Appcelerator Headquarters",
    subtitle: "San Jose, CA",
    pincolor: Alloy.Globals.Map.ANNOTATION_RED
}
*Result with example code* When selecting an annotation you'll get a this in the console
log.args('annotation selected', e.annotation);
When selecting another one, you'll get both deselected and selected on iOS. But only selected on Android. *Expected behaviour* Consistency across platforms. Either create a click event for both annotations when selecting another, or only trigger a click event for selecting the annotation. The first is preferred in my opinion as that is consistent with other situations (like clicking on the canvas/circle after selecting an annotation).

Comments

  1. Hans Knöchel 2018-03-06

    So to be clear, Android should add support for the deselect-event when reselecting another annotations?
  2. Rene Pot 2018-03-06

    [~hknoechel] yes that should be the most logical flow and most consistent with other events.
  3. Yordan Banev 2018-08-01

    PR: https://github.com/appcelerator-modules/ti.map/pull/240

JSON Source