Last active
December 12, 2015 08:08
-
-
Save alanleard/4741416 to your computer and use it in GitHub Desktop.
Map annotation selected image
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var win = Ti.UI.createWindow(); | |
var pinImage = 'map-pin.png'; | |
var selectedPinImage = 'map-pin-selected.png'; | |
var pin1 = Titanium.Map.createAnnotation({ | |
latitude:37.390749, | |
longitude:-122.081651, | |
title:"Appcelerator Headquarters", | |
subtitle:'Mountain View, CA', | |
pincolor:Titanium.Map.ANNOTATION_RED, | |
animate:true, | |
image: pinImage, | |
pinImage:pinImage, | |
selectPinImage:selectedPinImage | |
}); | |
var pin2 = Titanium.Map.createAnnotation({ | |
latitude: 31.390749, | |
longitude:-121.081651, | |
title:"Other one", | |
subtitle:'Mountain View, CA', | |
pincolor: Titanium.Map.ANNOTATION_RED, | |
animate:true, | |
image: pinImage, | |
pinImage:pinImage, | |
selectPinImage:selectedPinImage | |
}); | |
var pin3 = Titanium.Map.createAnnotation({ | |
latitude: 30.390749, | |
longitude:-122.081651, | |
title:"Other one", | |
subtitle:'Mountain View, CA', | |
pincolor: Titanium.Map.ANNOTATION_RED, | |
animate:true, | |
image: pinImage, | |
pinImage:pinImage, | |
selectPinImage:selectedPinImage | |
}); | |
var mapView = Titanium.Map.createView({ | |
mapType: Titanium.Map.STANDARD_TYPE, | |
animate:true, | |
regionFit:true, | |
userLocation: false, | |
annotations: [pin1, pin2, pin3] | |
}); | |
win.add(mapView); | |
win.open(); | |
var selectedPin = null; | |
mapView.addEventListener('click', function(e) { | |
if(e.clicksource === 'pin' && e.annotation !=selectedPin){ | |
e.annotation.setImage(e.annotation.selectPinImage); | |
if(selectedPin){ | |
selectedPin.setImage(selectedPin.pinImage); | |
selectedPin = e.annotation; | |
} else { | |
selectedPin = e.annotation; | |
} | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment