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;
};
You don't explicitly state this, but I assume that
delete.png
lives atResources/ui/delete.png
?I attached delete.png, which can be placed at Resources/delete.png
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.