Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-6459] Android: MapView Annotations - leftButton/rightButton don't appear when included from a commonjs subdirectory

GitHub Issuen/a
TypeBug
PriorityHigh
StatusClosed
ResolutionInvalid
Resolution Date2011-12-05T13:58:13.000+0000
Affected Version/sRelease 1.8.0.1
Fix Version/sn/a
ComponentsAndroid
Labelsbranch-v8, dr-list, regression
ReporterTony Lukasavage
AssigneeMarshall Culpepper
Created2011-12-05T10:48:12.000+0000
Updated2014-06-19T12:43:35.000+0000

Description

Expected bahavior

Given the test case below, the delete.png image should be shown as the leftButton on the MapView Annotation when selected.

Actual Behavior

The leftButton does not appear at all. This occurs only on 1.8.0.1 for both rhino and v8. 1.7.5 and 1.8.0v20111114 perform as expected. The problem occurs only when the annotation/mapview are created in a commonjs module that is in a subdirectory of the Resources directory. So for example, the below test case will show the failing behavior, but if you moved winInclude.js to the main Resources directory, instead of the 'ui' subdirectory, it will work as it should.

test case

app.js

Creating the window from *Resources/winInclude.js* rather than *Resources/ui/winInclude.js* will make everything work fine.
// This will make it work, provided you move winInclude.js to the Resources directory
// var win = require('winInclude').createWin();

var win = require('ui/winInclude').createWin();
win.open();

ui/winInclude.js

exports.createWin = function() {
	var win = Ti.UI.createWindow({
		backgroundColor: '#fff',
		fullscreen: false
	});
	var mapview;
	
	// win gets create in open function otherwise the map won't re-render
	// on pinch, zoom, location change, etc...
	win.addEventListener('open', function(e) {
		mapview = Titanium.Map.createView({
		    mapType: Titanium.Map.STANDARD_TYPE,
		    region: {
				latitude: 37.389569, 
				longitude: -122.050212,
		        latitudeDelta: 0.1, 
		        longitudeDelta: 0.1
		    },
		    animate:true,
		    regionFit:true,
		    userLocation:false
		});
		
		// Add initial annotation
		mapview.addAnnotation(Ti.Map.createAnnotation({
			animate: true,
			pincolor: Titanium.Map.ANNOTATION_RED,
			title: 'Appcelerator',
			latitude: 37.389569,
			longitude: -122.050212,
			leftButton: 'delete.png'
		}));
		
		// Handle all map annotation clicks
		mapview.addEventListener('click', function(e) {
		    if (e.annotation && (e.clicksource === 'leftButton' || e.clicksource === 'leftPane')) {    
		        mapview.removeAnnotation(e.annotation);
		    }         
		});
		win.add(mapview);
	});
	return win;
};

Attachments

FileDateSize
delete.png2011-12-05T13:39:21.000+00002515

Comments

  1. Marshall Culpepper 2011-12-05

    You don't explicitly state this, but I assume that delete.png lives at Resources/ui/delete.png ?
  2. Tony Lukasavage 2011-12-05

    I attached delete.png, which can be placed at Resources/delete.png
  3. Tony Lukasavage 2011-12-05

    Turns out this was a result of a change in behavior in how paths are handled in commonjs modules. In versions prior to 1.8.0.1, all paths were considered relative to the root of the project. With 1.8.0.1, paths are relative to the path of the module. You can make the paths relative to the root simply by appending '/' in front to make it an absolute path.

JSON Source